using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Runtime.CompilerServices; using System.Xml.Schema; using Newtonsoft.Json; using Amazon.DynamoDBv2; using Amazon.DynamoDBv2.Model; using Amazon.DynamoDBv2.DocumentModel; using Google.Protobuf.WellKnownTypes; using ServerCore; using ServerBase; using MetaAssets; using SESSION_ID = System.Int32; using META_ID = System.UInt32; using ENTITY_GUID = System.String; using ACCOUNT_ID = System.String; using OWNER_GUID = System.String; using USER_GUID = System.String; using CHARACTER_GUID = System.String; using ITEM_GUID = System.String; namespace ServerCommon; public class AccountBaseAttrib : AttribBase { // Account Id 값 (사용자 입력 Id or 통합인증 Id) [JsonProperty("account_id")] public ACCOUNT_ID AccountId { get; set; } = string.Empty; [JsonProperty("user_guid")] public USER_GUID UserGuid { get; set; } = string.Empty; [JsonProperty("password")] public string Password { get; set; } = string.Empty; [JsonProperty("account_type")] public AccountType AccountType { get; set; } = AccountType.None; [JsonProperty("language_type")] public LanguageType LanguageType { get; set; } = LanguageType.None; [JsonProperty("auth_amdin_level_type")] public AuthAdminLevelType AuthAdminLevelType { get; set; } = AuthAdminLevelType.None; [JsonProperty("account_creation_type")] public AccountCreationType AccountCreationType { get; set; } = AccountCreationType.None; [JsonProperty("account_creation_meta_id")] public META_ID AccountCreationMetaId { get; set; } = 0; [JsonProperty("login_datetime")] public DateTime LoginDateTime = DateTime.MinValue; [JsonProperty("logout_datetime")] public DateTime LogoutDateTime = DateTime.MinValue; [JsonProperty("created_datetime")] public DateTime CreatedDateTime = DateTime.MinValue; [JsonProperty("block_start_datetime")] public DateTime BlockStartDateTime { get; set; } = DateTime.MaxValue; [JsonProperty("block_end_datetime")] public DateTime BlockEndDateTime { get; set; } = DateTime.MaxValue; [JsonProperty("block_policy")] public List BlockPolicy { get; set; } = new(); [JsonProperty("block_reason")] public string BlockReason { get; set; } = string.Empty; [JsonProperty("access_token")] public UInt64 AccessToken { get; set; } = 0; [JsonProperty("sso_account_auth_jwt")] public string SsoAccountAuthJWT { get; set; } = string.Empty; public AccountBaseAttrib() : base(typeof(AccountBaseAttrib).Name) {} } //============================================================================================= // Primary Key // PK(Partition Key) : "account_base#login_account_id" // SK(Sort Key) : "" // DocType : AccountBaseDoc // Attrib : AccountBaseAttrib // ... //============================================================================================= public class AccountBaseDoc : DynamoDbDocBase, ICopyDocFromMeta { private static string getPrefixOfPK() { return "account_base#"; } private static string getPrefixOfSK() { return ""; } public AccountBaseDoc() : base(typeof(AccountBaseDoc).Name) { appendAttribWrapperAll(); } public AccountBaseDoc(string loginAccountId) : base(typeof(AccountBaseDoc).Name) { setCombinationKeyForPK(loginAccountId); appendAttribWrapperAll(); fillUpPrimaryKey(onMakePK(), onMakeSK()); } private void appendAttribWrapperAll() { appendAttribWrapper(new AttribWrapper()); } protected override string onGetPrefixOfPK() { return getPrefixOfPK(); } public bool copyDocFromMeta(MetaAssets.IMetaData customMeta) { var err_msg = string.Empty; bool is_success = false; if( null != customMeta as TestUserCreateMetaData && true == copyDocFromTestUserCreateMetaData(customMeta as TestUserCreateMetaData) ) { is_success = true; } if( null != customMeta as UserCreateMetaData && true == copyDocFromUserCreateMetaData(customMeta as UserCreateMetaData)) { is_success = true; } if (false == is_success) { err_msg = $"Failed to copyDocFromMeta() !!!, no successful data copies !!! : {customMeta.getTypeName()}"; Log.getLogger().error(err_msg); return false; } return true; } private bool copyDocFromTestUserCreateMetaData(TestUserCreateMetaData? customMeta) { var err_msg = string.Empty; var to_cast_string = typeof(TestUserCreateMetaData).Name; if (null == customMeta) { err_msg = $"Failed to copyDocFromTestUserCreateMetaData() !!!, customMeta is null : {to_cast_string}"; Log.getLogger().warn(err_msg); return false; } var attrib = getAttrib(); NullReferenceCheckHelper.throwIfNull(attrib, () => $"attrib is null !!!"); attrib.Password = customMeta.Password; attrib.LanguageType = customMeta.Language; attrib.AccountCreationType = AccountCreationType.Test; attrib.AccountCreationMetaId = (UInt32)customMeta.MetaId; return true; } private bool copyDocFromUserCreateMetaData(UserCreateMetaData? customMeta) { var err_msg = string.Empty; var to_cast_string = typeof(UserCreateMetaData).Name; if (null == customMeta) { err_msg = $"Failed to copyDocFromUserCreateMetaData() !!!, customMeta is null : {to_cast_string}"; Log.getLogger().warn(err_msg); return false; } var attrib = getAttrib(); NullReferenceCheckHelper.throwIfNull(attrib, () => $"attrib is null !!!"); attrib.LanguageType = LanguageType.Ko; attrib.AccountCreationType = AccountCreationType.Normal; attrib.AccountCreationMetaId = (UInt32)customMeta.MetaId; return true; } public static async Task<(Result, AccountBaseDoc?)> findUserGuidFromAccountId(string accountId) { var result = new Result(); var err_msg = string.Empty; var server_logic = ServerLogicApp.getServerLogicApp(); NullReferenceCheckHelper.throwIfNull(server_logic, () => $"server_logic is null !!!"); var dynamo_db_client = server_logic.getDynamoDbClient(); NullReferenceCheckHelper.throwIfNull(dynamo_db_client, () => $"dynamo_db_client is null !!!"); return await findUserGuidFromAccountId(dynamo_db_client, accountId); } public static async Task<(Result, AccountBaseDoc?)> findUserGuidFromAccountId(DynamoDbClient dynamoDbClient, string accountId) { var result = new Result(); var err_msg = string.Empty; (result, var make_primary_key) = await DynamoDBDocBaseHelper.makePrimaryKey(accountId); NullReferenceCheckHelper.throwIfNull(make_primary_key, () => $"make_primary_key is null !!! -"); if (result.isFail()) { return (result, null); } var query_config = dynamoDbClient.makeQueryConfigForReadByPKOnly(make_primary_key.PK); (result, var found_account_base_doc) = await dynamoDbClient.simpleQueryDocTypeWithQueryOperationConfig(query_config); if (result.isFail()) { err_msg = $"Failed to simpleQueryDocTypeWithQueryOperationConfig() !!! : {result.toBasicString()}, {make_primary_key.toBasicString()}"; Log.getLogger().error(err_msg); return (result, null); } return (result, found_account_base_doc); } }