//using System.Collections.Concurrent; //using System.Runtime.CompilerServices; //using System.Text; //using Newtonsoft.Json; //using Google.Protobuf.WellKnownTypes; //using Amazon.DynamoDBv2; //using Amazon.DynamoDBv2.DocumentModel; //using Amazon.DynamoDBv2.Model; //using ServerCore; using ServerBase; //using static Grpc.Core.Metadata; //namespace ServerCommon //{ // public enum EDBExecuteType // { // Insert, // Update, // Delete, // ExistsDelete, // } // public enum EEntityType // { // Account, // AccountId, // Building, // BuildingList, // Character, // CharList, // Land, // LandList, // MyHome, // MyHomeList, // SocialActionCollection, // SocialActionSlot, // EmotionCollection, // EmotionSlot, // BlackList, // WhiteList, // NickName, // GameOption, // ReceivedMail, // SendedMail, // CharMetaData, // Room, // RoomList, // Item, // Inventory, // ToolSlot, // Cart, // FriendList, // FriendFolderList, // FriendRequestList, // QuestList, // QuestMail, // ClaimRewardNormal, // ClaimRewardMembership, // TattooSlot, // BlockList, // UserReport, // SystemMail, // NoticeChat, // MinimapMarker, // CharProfile, // MyShop, // InstanceLastRoom, // EscapePosition, // } // public class DBDocumentInfo // { // public DBDocumentInfo(Document document, EDBExecuteType type) // { // this.document = document; // executeType = type; // } // public Document? document; // public EDBExecuteType executeType; // public override string ToString() => $"document: {document?.ToJsonPretty()}, executeType: {executeType}"; // } // public class MainDB // { // AmazonDynamoDBClient? Client = null; // string TableName = string.Empty; // public AmazonDynamoDBClient? getDbClient() => Client; // Table? _mainTable; // public MainDB() { } // GetItemOperationConfig operationDefaultConfig = new GetItemOperationConfig{ ConsistentRead = true }; // TransactWriteItemOperationConfig? existsTranConfig; // TransactWriteItemOperationConfig? notExistsTranConfig; // public async Task DeleteBotClient() // { // try // { // if(_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return false; // } // ScanFilter filter = new(); // filter.AddCondition("PK", ScanOperator.BeginsWith, "accountid#BotClient"); // ScanOperationConfig operationConfig = new ScanOperationConfig // { // Filter = filter, // ConsistentRead = true // }; // Search search = _mainTable.Scan(operationConfig); // List list = new List(1000); // while (search.IsDone == false) // { // List documents = await search.GetNextSetAsync(); // list.AddRange(documents.AsEnumerable()); // } // list.ForEach(doc => // { // _mainTable.DeleteItemAsync(doc); // }); // } // catch(Exception ex) // { // Log.getLogger().error(ex.ToString()); // } // return true; // } // static string GetPrefix(EEntityType type, bool isPK) // { // string prefixPK = string.Empty; // string prefixSK = string.Empty; // switch (type) // { // case EEntityType.Account: // prefixPK = "account#"; // prefixSK = "account#"; // break; // case EEntityType.AccountId: // prefixPK = "accountid#"; // prefixSK = "account#"; // break; // case EEntityType.Building: // prefixPK = "building#"; // prefixSK = "building#"; // break; // case EEntityType.BuildingList: // prefixPK = "char#"; // prefixSK = "buildinglist#"; /// break; // case EEntityType.Character: // prefixPK = "char#"; // prefixSK = "char#"; // break; // case EEntityType.CharList: // prefixPK = "charlist#"; // prefixSK = "char#"; // break; // case EEntityType.Land: // prefixPK = "land#"; // prefixSK = "land#"; // break; // case EEntityType.LandList: // prefixPK = "char#"; // prefixSK = "landlist#"; // break; // case EEntityType.MyHome: // prefixPK = "char#"; // prefixSK = "myhome#"; // break; // case EEntityType.MyHomeList: // prefixPK = "char#"; // prefixSK = "myhomelist#"; // break; // case EEntityType.SocialActionCollection: // prefixPK = "char#"; // prefixSK = "socialactioncollection#"; // break; // case EEntityType.SocialActionSlot: // prefixPK = "char#"; // prefixSK = "socialactionslot#"; // break; // case EEntityType.EmotionCollection: // prefixPK = "char#"; // prefixSK = "emotioncollection#"; // break; // case EEntityType.EmotionSlot: // prefixPK = "char#"; // prefixSK = "emotionslot#"; // break; // case EEntityType.BlackList: // prefixPK = "blacklist#"; // prefixSK = "blacklist#"; // break; // case EEntityType.WhiteList: // prefixPK = "whitelist#"; // prefixSK = "whitelist#"; // break; // case EEntityType.NickName: // prefixPK = "nickname#"; // prefixSK = "nickname#"; // break; // case EEntityType.GameOption: // prefixPK = "game_option#"; // prefixSK = ""; // break; // case EEntityType.ReceivedMail: // prefixPK = "char#"; // prefixSK = "receivedmailid#"; // break; // case EEntityType.SendedMail: // prefixPK = "char#"; // prefixSK = "sendedmailid#"; // break; // case EEntityType.CharMetaData: // prefixPK = "char#"; // prefixSK = "charmetadata#"; // break; // case EEntityType.Room: // prefixPK = "room#"; // prefixSK = ""; // break; // case EEntityType.RoomList: // prefixPK = "char#"; // prefixSK = "roomlist#"; // break; // case EEntityType.Item: // prefixPK = "item#"; // prefixSK = "item#"; // break; // case EEntityType.Inventory: // prefixPK = "char#"; // prefixSK = "inventory#"; // break; // case EEntityType.ToolSlot: // prefixPK = "char#"; // prefixSK = "toolslot#"; // break; // case EEntityType.Cart: // prefixPK = "account#"; // prefixSK = "cart#"; // break; // case EEntityType.FriendList: // prefixPK = "friendList#"; // prefixSK = "friend#"; // break; // case EEntityType.FriendFolderList: // prefixPK = "friendFolderList#"; // prefixSK = "friendFolder#"; // break; // case EEntityType.FriendRequestList: // prefixPK = "friendRequestList#"; // prefixSK = "friendRequest#"; // break; // case EEntityType.QuestList: // prefixPK = "char#"; // prefixSK = "questlist#"; // break; // case EEntityType.QuestMail: // prefixPK = "questmail#"; // prefixSK = "questmail#"; // break; // case EEntityType.ClaimRewardNormal: // prefixPK = "claimreward#"; // prefixSK = "normal#"; // break; // case EEntityType.ClaimRewardMembership: // prefixPK = "claimreward#"; // prefixSK = "membership#"; // break; // case EEntityType.TattooSlot: // prefixPK = "char#"; // prefixSK = "tattooslot#"; // break; // case EEntityType.BlockList: // prefixPK = "blockList#"; // prefixSK = "block#"; // break; // case EEntityType.UserReport: // prefixPK = "user_report#"; // prefixSK = "report#"; // break; // case EEntityType.SystemMail: // prefixPK = "system_mail#"; // prefixSK = ""; // break; // case EEntityType.NoticeChat: // prefixPK = "notice_chat#"; // prefixSK = ""; // break; // case EEntityType.MinimapMarker: // prefixPK = "mini_map_marker#"; // prefixSK = ""; // break; // case EEntityType.CharProfile: // prefixPK = "user_profile#"; // prefixSK = ""; // break; // case EEntityType.MyShop: // prefixPK = "char#"; // prefixSK = "myShop#"; // break; // case EEntityType.InstanceLastRoom: // prefixPK = "instance_last_room#"; // prefixSK = ""; // break; // case EEntityType.EscapePosition: // prefixPK = "escape_position#"; // prefixSK = ""; // break; // default: // Log.getLogger().error($"Wrong EEntityType : {type.ToString()}"); // break; // } // if (isPK) // return prefixPK; // else // return prefixSK; // } // public static string GetPKPrefix(EEntityType type) // { // return GetPrefix(type, true); // } // public static string GetSKPrefix(EEntityType type) // { // return GetPrefix(type, false); // } // static string MakeKey(EEntityType type, string id, bool isPK) // { // string PK = string.Empty; // string SK = string.Empty; // switch (type) // { // case EEntityType.Account: // case EEntityType.AccountId: // case EEntityType.Building: // case EEntityType.BuildingList: // case EEntityType.Character: // case EEntityType.CharList: // case EEntityType.Land: // case EEntityType.LandList: // case EEntityType.MyHome: // case EEntityType.MyHomeList: // case EEntityType.SocialActionCollection: // case EEntityType.SocialActionSlot: // case EEntityType.EmotionCollection: // case EEntityType.EmotionSlot: // case EEntityType.BlackList: // case EEntityType.WhiteList: // case EEntityType.NickName: // case EEntityType.GameOption: // case EEntityType.ReceivedMail: // case EEntityType.SendedMail: // case EEntityType.CharMetaData: // case EEntityType.Room: // case EEntityType.RoomList: // case EEntityType.Item: // case EEntityType.Inventory: // case EEntityType.ToolSlot: // case EEntityType.Cart: // case EEntityType.FriendList: // case EEntityType.FriendFolderList: // case EEntityType.FriendRequestList: // case EEntityType.QuestList: // case EEntityType.QuestMail: // case EEntityType.ClaimRewardNormal: // case EEntityType.ClaimRewardMembership: // case EEntityType.BlockList: // case EEntityType.TattooSlot: // case EEntityType.UserReport: // case EEntityType.SystemMail: // case EEntityType.NoticeChat: // case EEntityType.MinimapMarker: // case EEntityType.CharProfile: // case EEntityType.MyShop: // case EEntityType.InstanceLastRoom: // case EEntityType.EscapePosition: // PK = GetPKPrefix(type) + id; // SK = GetSKPrefix(type) + id; // break; // default: // Log.getLogger().error($"Wrong EEntityType : {type.ToString()}"); // break; // } // if (isPK) // return PK; // else // return SK; // } // public static string MakePK(EEntityType type, string pk_id) // { // return MakeKey(type, pk_id, true); // } // public static string MakeSK(EEntityType type, string sk_id) // { // return MakeKey(type, sk_id, false); // } // public static Document DocumentForInsert(EEntityType type, string pk_id, string sk_id, Object? attr = null) // { // Document document = new Document(); // try // { // document["PK"] = MakePK(type, pk_id); // document["SK"] = MakeSK(type, sk_id); // document["Type"] = type.ToString(); // if (attr == null) // return document; // if (type != EEntityType.Character) // { // document["Attr"] = JsonConvert.SerializeObject(attr); // } // else // { // CharEntity enity = (CharEntity)attr; // document = enity.DocumentForUpdate(); // } // } // catch (Exception ex) // { // Log.getLogger().error($"{ex}"); // } // return document; // } // public static Document DocumentForInsertWithTTL(EEntityType type, string pk_id, string sk_id, DateTime expireDate, Object? attr = null) // { // Document document = new Document(); // document["PK"] = MakePK(type, pk_id); // document["SK"] = MakeSK(type, sk_id); // document["TTL"] = expireDate.ToTimestamp().Seconds; // document["Type"] = type.ToString(); // if (attr == null) // return document; // if (type != EEntityType.Character) // { // document["Attr"] = JsonConvert.SerializeObject(attr); // } // else // { // CharEntity enity = (CharEntity)attr; // document = enity.DocumentForUpdate(); // } // return document; // } // public static Document DocumentForGet(EEntityType type, string pk_id, string sk_id) // { // Document document = new Document(); // document["PK"] = MakePK(type, pk_id); // document["SK"] = MakeSK(type, sk_id); // return document; // } // public async Task> DocumentForGetFromPK(EEntityType type, string pk_id) // { // List documnetList = new(); // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return documnetList; // } // string PK = MakePK(type, pk_id); // QueryFilter filter = new QueryFilter(); // filter.AddCondition("PK", QueryOperator.Equal, PK); // filter.AddCondition("SK", QueryOperator.BeginsWith, GetSKPrefix(type)); // QueryOperationConfig operationConfig = new QueryOperationConfig // { // Filter = filter, // ConsistentRead = true // }; // Search search = _mainTable.Query(operationConfig); // while (search.IsDone == false) // { // List documents = await search.GetNextSetAsync(); // foreach (Document document in documents) // { // documnetList.Add(document); // } // } // return documnetList; // } // public static Document DocumentForDelete(EEntityType type, string pk_id, string sk_id) // { // Document document = new Document(); // document["PK"] = MakePK(type, pk_id); // document["SK"] = MakeSK(type, sk_id); // return document; // } // public async Task ClearMatchPK(EEntityType entityType, string pk) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return; // } // List deleteList = new(); // string PK = MakePK(entityType, pk); // QueryFilter filter = new QueryFilter(); // filter.AddCondition("PK", QueryOperator.Equal, PK); // filter.AddCondition("SK", QueryOperator.BeginsWith, GetSKPrefix(entityType)); // QueryOperationConfig operationConfig = new QueryOperationConfig // { // Filter = filter, // ConsistentRead = true // }; // Search search = _mainTable.Query(operationConfig); // while (search.IsDone == false) // { // List documents = await search.GetNextSetAsync(); // foreach (Document document in documents) // { // deleteList.Add(document); // } // } // foreach (Document document in deleteList) // { // await _mainTable.DeleteItemAsync(document); // } // } // public bool CreateClient(ServerConfig config) // { // var error_code = config.fillupDbTableNameWithServiceType(out TableName); // if (error_code.isFail()) // { // Log.getLogger().error($"Fail to fill up DB TableName !!! error_code:{error_code}"); // return false; // } //#if (SERVER_REFECTORING) //#else//SERVER_REFECTORING // Client = DynamoDBHelper.CreateClient(config); //#endif//SERVER_REFECTORING // return (Client != null); // } // public async Task CreateDBIfNotExists(bool resetTable) // { // await Task.CompletedTask; // if (Client == null) // { // Log.getLogger().error($"Client is null"); // return false; // } // if (resetTable == true) // { //#if (SERVER_REFECTORING) //#else//SERVER_REFECTORING // await DynamoDBHelper.DeleteTable(Client, TableName); //#endif//SERVER_REFECTORING // } // bool ret = true; //#if (SERVER_REFECTORING) //#else//SERVER_REFECTORING // if (await DynamoDBHelper.CheckingTableExistence(Client, TableName) == false) //#endif//SERVER_REFECTORING // { // List tableAttributes = new List(); // tableAttributes.Add(new AttributeDefinition("PK", ScalarAttributeType.S)); // tableAttributes.Add(new AttributeDefinition("SK", ScalarAttributeType.S)); // List tableKeySchema = new List(); // tableKeySchema.Add(new KeySchemaElement("PK", KeyType.HASH)); // tableKeySchema.Add(new KeySchemaElement("SK", KeyType.RANGE)); //#if (SERVER_REFECTORING) //#else//SERVER_REFECTORING // ret = await DynamoDBHelper.CreateTable( Client, TableName // , tableAttributes, tableKeySchema ); //#endif//SERVER_REFECTORING // } // var pkExistsExpression = new Amazon.DynamoDBv2.DocumentModel.Expression(); // pkExistsExpression.ExpressionStatement = "attribute_exists(#PK)"; // pkExistsExpression.ExpressionAttributeNames["#PK"] = "PK"; // var pkNotExistsExpression = new Amazon.DynamoDBv2.DocumentModel.Expression(); // pkNotExistsExpression.ExpressionStatement = "attribute_not_exists(#PK)"; // pkNotExistsExpression.ExpressionAttributeNames["#PK"] = "PK"; // existsTranConfig = new TransactWriteItemOperationConfig() { ConditionalExpression = pkExistsExpression, ReturnValuesOnConditionCheckFailure = Amazon.DynamoDBv2.DocumentModel.ReturnValuesOnConditionCheckFailure.AllOldAttributes }; // notExistsTranConfig = new TransactWriteItemOperationConfig() { ConditionalExpression = pkNotExistsExpression, ReturnValuesOnConditionCheckFailure = Amazon.DynamoDBv2.DocumentModel.ReturnValuesOnConditionCheckFailure.AllOldAttributes }; // _mainTable = Table.LoadTable(Client, TableName); // return ret; // } // public async Task UpdateDocument(Document document) // { // try // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return false; // } // await _mainTable.UpdateItemAsync(document); // } // catch (Exception e) // { // Log.getLogger().error($"{e}"); // return false; // } // return true; // } // public async Task UpdateDocuments(List documents) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return false; // } // if (documents.Count > 0 ) // { // DocumentBatchWrite batch = _mainTable.CreateBatchWrite(); // foreach (var document in documents) // { // batch.AddDocumentToPut(document); // } // await batch.ExecuteAsync(); // } // return true; // } // public async Task DeleteDocuments(List documents) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return false; // } // if (documents.Count > 0) // { // DocumentBatchWrite batch = _mainTable.CreateBatchWrite(); // foreach (var document in documents) // { // batch.AddItemToDelete(document); // } // await batch.ExecuteAsync(); // } // return true; // } // public async Task InsertAccount(string accountId, AccountAttr? attr) // { // if(attr== null || attr.Aid == null) // { // Log.getLogger().error("entity is null"); // return null; // } // try // { // if(_mainTable== null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // Log.getLogger().debug($"{accountId} {JsonConvert.SerializeObject(attr)}"); // Document document1 = DocumentForInsert(EEntityType.Account, attr.Aid, attr.Aid, attr); // Document document2 = DocumentForInsert(EEntityType.AccountId, accountId, attr.Aid); // DocumentBatchWrite batch = _mainTable.CreateBatchWrite(); // batch.AddDocumentToPut(document1); // batch.AddDocumentToPut(document2); // await batch.ExecuteAsync(); // AccountEntity entity = new AccountEntity(document1); // return entity; // } // catch (Exception ex) // { // Log.getLogger().error(ex.ToString()); // return null; // } // } // public async IAsyncEnumerable DelAllDataExceptTableData() // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // yield break; // } // ScanFilter filter = new ScanFilter(); // filter.AddCondition("PK", ScanOperator.BeginsWith, GetPKPrefix(EEntityType.AccountId)); // ScanOperationConfig operationConfig = new ScanOperationConfig // { // Filter = filter, // ConsistentRead = true // }; // Search search = _mainTable.Scan(operationConfig); // while (!search.IsDone) // { // List documents = await search.GetNextSetAsync(); // foreach (Document document in documents) // { // AccountIDEntity entity = new AccountIDEntity(document); // if(TableData.Instance.m_test_user_initial_meta_datas.TryGetValue(entity.PK_Name, out _) == true) // { // continue; // } // await DelAllDataByGuid(entity.PK_Name, entity.SK_Guid); // yield return entity.PK_Name; // } // } // } // public async IAsyncEnumerable DelAllDataFromId(string beginId) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // yield break; // } // ScanFilter filter = new ScanFilter(); // filter.AddCondition("PK", ScanOperator.BeginsWith, GetPKPrefix(EEntityType.AccountId)+beginId); // ScanOperationConfig operationConfig = new ScanOperationConfig // { // Filter = filter, // ConsistentRead = true // }; // Search search = _mainTable.Scan(operationConfig); // while (!search.IsDone) // { // List documents = await search.GetNextSetAsync(); // foreach (Document document in documents) // { // AccountIDEntity entity = new AccountIDEntity(document); // await DelAllDataByGuid(entity.PK_Name, entity.SK_Guid); // yield return entity.PK_Name; // } // } // } // private async Task DelAllDataByGuid(string id, string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return; // } // //Land, pk = landid // //BuildingList, unknown // //Building, pk = buildingguid // DelDataByGuid(accountGuid, EEntityType.EmotionSlot); // DelDataByGuid(accountGuid, EEntityType.EmotionCollection); // DelDataByGuid(accountGuid, EEntityType.SocialActionSlot); // DelDataByGuid(accountGuid, EEntityType.SocialActionCollection); // DelDataByGuid(accountGuid, EEntityType.MyHome); // DelDataByGuid(accountGuid, EEntityType.LandList); // DocumentBatchWrite batch; // Document documentForDelete; // batch = _mainTable.CreateBatchWrite(); // //CharList, // documentForDelete = DocumentForDelete(EEntityType.CharList, accountGuid, accountGuid); // batch.AddItemToDelete(documentForDelete); // //charData // documentForDelete = DocumentForDelete(EEntityType.Character, accountGuid, accountGuid); // batch.AddItemToDelete(documentForDelete); // //AccountId, // documentForDelete = DocumentForDelete(EEntityType.AccountId, id, accountGuid); // batch.AddItemToDelete(documentForDelete); // //Account, // documentForDelete = DocumentForDelete(EEntityType.Account, accountGuid, accountGuid); // batch.AddItemToDelete(documentForDelete); // await batch.ExecuteAsync(); // return; // } // private async void DelDataByGuid(string accountGuid, EEntityType entityType) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return; // } // DocumentBatchWrite batch; // batch = _mainTable.CreateBatchWrite(); // await foreach (var document in GetAllDocument(accountGuid, entityType)) // { // batch.AddItemToDelete(document); // } // await batch.ExecuteAsync(); // } // public async IAsyncEnumerable GetAllDocument(string pkey, EEntityType entityType) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // yield break; // } // string pk = MakePK(entityType, pkey); // QueryFilter filter = new QueryFilter(); // filter.AddCondition("PK", QueryOperator.Equal, pk); // filter.AddCondition("SK", QueryOperator.BeginsWith, GetSKPrefix(entityType)); // QueryOperationConfig operationConfig = new QueryOperationConfig // { // Filter = filter, // ConsistentRead = true // }; // Search? search = _mainTable.Query(operationConfig); // while (search.IsDone == false) // { // List documents = await search.GetNextSetAsync(); // foreach (Document document in documents) // { // yield return document; // } // } // } // public async Task GetAccountGuid(string id) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // string pk = MakePK(EEntityType.AccountId, id); // Log.getLogger().debug($"Table:{_mainTable.TableName} accountID:{pk}"); // QueryFilter filter = new QueryFilter(); // filter.AddCondition("PK", QueryOperator.Equal, pk); // filter.AddCondition("SK", QueryOperator.BeginsWith, GetSKPrefix(EEntityType.AccountId)); // QueryOperationConfig operationConfig = new QueryOperationConfig // { // Filter = filter, // ConsistentRead = true // }; // Search? search = _mainTable.Query(operationConfig); // if (search == null) // { // Log.getLogger().info($"Not found Table:{_mainTable} accountID:{id} Search is null"); // return null; // } // List documents = await search.GetNextSetAsync(); // if (documents.Count != 1) // { // Log.getLogger().info($"Not found Table:{_mainTable} accountID:{id} count:{documents.Count}"); // return null; // } // AccountIDEntity entity = new AccountIDEntity(documents[0]); // Log.getLogger().debug($"Table:{_mainTable.TableName} accountID:{pk} {JsonConvert.SerializeObject(entity)}"); // return entity.SK_Guid; // } // public async Task GetAccountByID(string id) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // string pk = MakePK(EEntityType.AccountId, id); // Log.getLogger().debug($"Table:{_mainTable.TableName} accountID:{pk}"); // QueryFilter filter = new QueryFilter(); // filter.AddCondition("PK", QueryOperator.Equal, pk); // filter.AddCondition("SK", QueryOperator.BeginsWith, GetSKPrefix(EEntityType.AccountId)); // QueryOperationConfig operationConfig = new QueryOperationConfig // { // Filter = filter, // ConsistentRead = true // }; // Search? search = _mainTable.Query(operationConfig); // if (search == null) // { // Log.getLogger().info($"Not found Table:{_mainTable} accountID:{id} Search is null"); // return null; // } // List documents = await search.GetNextSetAsync(); // if (documents.Count != 1) // { // Log.getLogger().info($"Not found Table:{_mainTable} accountID:{id} count:{documents.Count}"); // return null; // } // AccountIDEntity entity = new AccountIDEntity(documents[0]); // Log.getLogger().debug($"Table:{_mainTable.TableName} accountID:{pk} {JsonConvert.SerializeObject(entity)}"); // return await GetAccountByGuid(entity.SK_Guid); // } // public async Task GetAccountByGuid(string guid) // { // Log.getLogger().debug($"GetAccountByGuid:{guid}"); // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.Account, guid, guid); // Document document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document == null) // { // Log.getLogger().error($"Not found Table:{_mainTable} accountGuid:{guid}"); // return null; // } // AccountEntity entity = new AccountEntity(document); // return entity; // } // public async Task UpdateAccount(AccountEntity entity) // { // Log.getLogger().debug($"UpdateAccount {entity.Attr.Id}"); // try // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return; // } // var document = entity.DocumentForUpdate(); // await _mainTable.UpdateItemAsync(document); // } // catch (Exception ex) // { // Log.getLogger().error(ex.ToString()); // } // } // public async Task InsertChar(string accountGuid, string id) // { // // 기본적인 정보 구성만 한다. GUID 생성 & 저장되는 처리는 하지 말자 // var result = new Result(); // var err_msg = string.Empty; // Log.getLogger().debug($"InsertChar {accountGuid} {id}"); // //string guid = Guid.NewGuid().ToString("N"); // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var user_attrib = new CharEntity(); // Log.getLogger().debug(JsonConvert.SerializeObject(user_attrib)); // user_attrib.PK_Guid = accountGuid; // try // { // user_attrib.PK_Guid = accountGuid; // user_attrib.Id = id; // Document document1 = DocumentForInsert(EEntityType.Character, accountGuid, accountGuid, user_attrib); // Document document2 = DocumentForInsert(EEntityType.CharList, accountGuid, accountGuid); // DocumentBatchWrite batch = _mainTable.CreateBatchWrite(); // batch.AddDocumentToPut(document1); // batch.AddDocumentToPut(document2); // await batch.ExecuteAsync(); // } // catch (Exception ex) // { // Log.getLogger().error(ex.ToString()); // } // return user_attrib; // } // public async Task?> ListChar(string accountGuid) // { // //await DeleteChar(accountGuid, accountGuid); // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // string pk = MakePK(EEntityType.CharList, accountGuid); // QueryFilter filter = new QueryFilter(); // filter.AddCondition("PK", QueryOperator.Equal, pk); // filter.AddCondition("SK", QueryOperator.BeginsWith, GetSKPrefix(EEntityType.CharList)); // QueryOperationConfig operationConfig = new QueryOperationConfig // { // Filter = filter, // ConsistentRead = true // }; // List charListEntities = new List(); // Search search = _mainTable.Query(operationConfig); // while (search.IsDone == false) // { // List documents = await search.GetNextSetAsync(); // foreach (Document document in documents) // { // CharListEntity entity = new CharListEntity(document); // charListEntities.Add(entity); // } // } // List charList = new List(); // if (charListEntities.Count > 0) // { // DocumentBatchGet batchGet = _mainTable.CreateBatchGet(); // batchGet.ConsistentRead = true; // foreach (var charListEntity in charListEntities) // { // Document document = DocumentForGet(EEntityType.Character, charListEntity.SK_CharGuid, charListEntity.SK_CharGuid); // batchGet.AddKey(document); // } // await batchGet.ExecuteAsync(); // foreach (Document document in batchGet.Results) // { // CharEntity entiry = new CharEntity(document); // charList.Add(entiry); // } // } // return charList; // } // public async Task DeleteChar(string guid, string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return; // } // Document documentForDelete1 = DocumentForDelete(EEntityType.Character, guid, guid); // Document documentForDelete2 = DocumentForDelete(EEntityType.CharList, guid, accountGuid); // DocumentBatchWrite batch = _mainTable.CreateBatchWrite(); // batch.AddItemToDelete(documentForDelete1); // batch.AddItemToDelete(documentForDelete2); // await batch.ExecuteAsync(); // } // public async Task GetChar(string guid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.Character, guid, guid); // Document document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document == null) // { // Log.getLogger().error($"Not found Table:{_mainTable} charGuid:{guid}"); // return null; // } // CharEntity entity = new CharEntity(document); // return entity; // } // public async Task SaveChar(CharEntity entity) // { // try // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return; // } // var document = entity.DocumentForUpdate(); // await _mainTable.UpdateItemAsync(document); // } // catch(Exception ex) // { // Log.getLogger().error($"{ex}, {entity.Id}"); // } // } // public async Task LoadInven(string charGuild, InventoryEntity entity) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // _ = await entity.LoadAsync(_mainTable, charGuild); // return entity; // } // public async Task DelInven(string charGuild, InventoryEntity entity) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // _ = await entity.DelInven(_mainTable, charGuild); // return entity; // } // public async Task SaveInven(string charGuild, InventoryEntity entity) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return; // } // await entity.InsertAsync(charGuild, _mainTable); // } // public async Task GetMyHomeList(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.MyHomeList, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document is null) // { // document = DocumentForInsert(EEntityType.MyHomeList, accountGuid, "", new MyHomeListAttr()); // } // return document; // } // public async Task GetMyHomeData(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.MyHome, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document is null) // { // document = DocumentForInsert(EEntityType.MyHome, accountGuid, "", new MyHomeAttr()); // } // return document; // } // public async Task UpdateMyHome(MyHomeEntity entity) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return; // } // var document = entity.DocumentForUpdate(); // await _mainTable.UpdateItemAsync(document); // } // public async Task DeleteMyHome(string accountGuid, int slotNum) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return; // } // var document = DocumentForDelete(EEntityType.MyHome, accountGuid, slotNum.ToString()); // await _mainTable.DeleteItemAsync(document); // return; // } // public async Task GetLandList(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.LandList, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document is null) // { // document = DocumentForInsert(EEntityType.LandList, accountGuid, "", new LandListEntity()); // } // return document; // } // public async Task?> GetLandEntityList(List landIds) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // List returnLIst = new(); // if (landIds.Count > 0) // { // var batchGet = _mainTable.CreateBatchGet(); // batchGet.ConsistentRead = true; // foreach (var roomId in landIds) // { // Document document = DocumentForGet(EEntityType.Land, roomId.ToString(), roomId.ToString()); // batchGet.AddKey(document); // } // await batchGet.ExecuteAsync(); // foreach (var document in batchGet.Results) // { // var entity = new LandEntity(document); // returnLIst.Add(entity); // } // } // return returnLIst; // } // /// // /// 업데이트 // /// // /// // /// // public async Task UpdateLand(LandEntity entity) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return; // } // Document document = entity.DocumentForUpdate(); // await _mainTable.UpdateItemAsync(document); // } // /// // /// 목록 업데이트 // /// // /// // /// // public async Task UpdateLands(List entites) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return; // } // if (entites.Count > 0) // { // var batchWrite = _mainTable.CreateBatchWrite(); // foreach (var entity in entites) // { // Document document = entity.DocumentForUpdate(); // batchWrite.AddDocumentToPut(document); // } // await batchWrite.ExecuteAsync(); // } // } // public async Task GetBuildingList(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.BuildingList, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document is null) // { // document = DocumentForInsert(EEntityType.BuildingList, accountGuid, "", new BuildingListEntity()); // } // return document; // } // public async Task?> GetBuildingEntityList(List buildingIds) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // List returnLIst = new List(); // if (buildingIds.Count > 0) // { // var batchGet = _mainTable.CreateBatchGet(); // batchGet.ConsistentRead = true; // foreach (var buildingId in buildingIds) // { // Document document = DocumentForGet(EEntityType.Building, buildingId.ToString(), buildingId.ToString()); // batchGet.AddKey(document); // } // await batchGet.ExecuteAsync(); // foreach (var document in batchGet.Results) // { // var entity = new BuildingEntity(document); // returnLIst.Add(entity); // } // } // return returnLIst; // } // public async Task GetBuildingData(string id) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.Building, id, id); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document == null) // { // Log.getLogger().error($"Building GetItemAsync Error id : {id}"); // return null; // } // var entity = new BuildingEntity(document); // return entity; // } // public async Task UpdateBuilding(BuildingEntity entity) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return; // } // Document document = entity.DocumentForUpdate(); // await _mainTable.UpdateItemAsync(document); // } // public async Task UpdateBuildings(List entites) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return; // } // if (entites.Count > 0) // { // var batchWrite = _mainTable.CreateBatchWrite(); // foreach (var entity in entites) // { // Document document = entity.DocumentForUpdate(); // batchWrite.AddDocumentToPut(document); // } // await batchWrite.ExecuteAsync(); // } // } // public async Task DeleteBuildings(List builgingGuids) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return; // } // if (builgingGuids.Count > 0) // { // var batchWrite = _mainTable.CreateBatchWrite(); // foreach (var builgingGuid in builgingGuids) // { // Document document= DocumentForDelete(EEntityType.Building, builgingGuid, builgingGuid); // batchWrite.AddItemToDelete(document); // } // await batchWrite.ExecuteAsync(); // } // } // public async Task GetRoomLIst(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.RoomList, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document is null) // { // document = DocumentForInsert(EEntityType.RoomList, accountGuid, "", new RoomListEntity()); // } // return document; // } // public async Task?> GetRoomEntityList(List roomIds) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // List returnLIst = new List(); // if (roomIds.Count > 0) // { // var batchGet = _mainTable.CreateBatchGet(); // batchGet.ConsistentRead = true; // foreach (var roomId in roomIds) // { // Document document = DocumentForGet(EEntityType.Room, roomId.ToString(), roomId.ToString()); // batchGet.AddKey(document); // } // await batchGet.ExecuteAsync(); // foreach (var document in batchGet.Results) // { // var entity = new RoomEntity(document); // returnLIst.Add(entity); // } // } // return returnLIst; // } // public async Task GetSocialActionCollection(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.SocialActionCollection, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document is null) // { // document = DocumentForInsert(EEntityType.SocialActionCollection, accountGuid, "", new SocialActionCollectionAttr()); // } // return document; // } // public async Task GetSocialActionSlot(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.SocialActionSlot, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document is null) // { // document = DocumentForInsert(EEntityType.SocialActionSlot, accountGuid, "", new SocialActionSlotAttr()); // } // return document; // } // public async Task GetEmotionCollection(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.EmotionCollection, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document is null) // { // document = DocumentForInsert(EEntityType.EmotionCollection, accountGuid, "", new EmotionCollectionAttr()); // } // return document; // } // public async Task GetEmotionSlot(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.EmotionSlot, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document is null) // { // document = DocumentForInsert(EEntityType.EmotionSlot, accountGuid, "", new EmotionSlotAttr()); // } // return document; // } // public async Task AddWhiteList() // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // //var document = MainDB.DocumentForInsert(EEntityType.WhiteList, "", "", new WhiteListAttr()); // Document document = new(); // await _mainTable.PutItemAsync(document); // WhiteListEntity resultEntity = new WhiteListEntity(document); // return resultEntity; // } // public async Task UpdateWhiteList(WhiteListEntity entity) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // Document document = entity.DocumentForUpdate(); // await _mainTable.UpdateItemAsync(document); // WhiteListEntity resultEntity = new WhiteListEntity(document); // return resultEntity; // } // public async Task GetWhiteListData() // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // //var key = DocumentForGet(EEntityType.WhiteList, "", ""); // string key = ""; // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document == null) // { // Log.getLogger().error($"WhiteList GetItemAsync Error"); // return null; // } // WhiteListEntity resultEntity = new WhiteListEntity(document); // return resultEntity; // } // public async Task AddBlackList() // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // //var document = MainDB.DocumentForInsert(EEntityType.BlackList, "", "", new BlackListAttr()); // Document document = new(); // await _mainTable.PutItemAsync(document); // BlackListEntity resultEntity = new BlackListEntity(document); // return resultEntity; // } // public async Task UpdateBlackList(BlackListEntity entity) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // Document document = entity.DocumentForUpdate(); // await _mainTable.UpdateItemAsync(document); // BlackListEntity resultEntity = new BlackListEntity(document); // return resultEntity; // } // public async Task GetBlackListData() // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // //var key = DocumentForGet(EEntityType.BlackList, "", ""); // var key = ""; // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document == null) // { // Log.getLogger().error($"BlackList GetItemAsync Error"); // return null; // } // BlackListEntity resultEntity = new BlackListEntity(document); // return resultEntity; // } // public async Task InsertNickName(string nickname, string accountGuid, string accountId) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // NickNameEntityAttr attr = new NickNameEntityAttr(); // attr.AccountGuid = accountGuid; // attr.AccountId = accountId; // var document = MainDB.DocumentForInsert(EEntityType.NickName, nickname, "", attr); // await _mainTable.PutItemAsync(document); // NickNameEntity resultEntity = new NickNameEntity(document); // return resultEntity; // } // public async Task DeleteNickName(NickNameEntity entity) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return false; // } // var document = MainDB.DocumentForDelete(EEntityType.NickName, entity.PK_NickName, entity.SK_Empty); // await _mainTable.DeleteItemAsync(document); // return true; // } // public async Task GetEntityFromNickName(string nickname) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // var key = DocumentForGet(EEntityType.NickName, nickname, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document == null) // { // // Log.getLogger().error($"GetNickName Error"); null 이 에러라고 단정할수 없다. // return null; // } // var resultEntity = new NickNameEntity(document); // return resultEntity; // } // public async Task GetGameOption(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // var key = DocumentForGet(EEntityType.GameOption, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document == null) // { // Log.getLogger().debug($"GetGameOption Error"); // return null; // } // return document; // } // public async Task InsertGameOption(string accountGuid, AccountGameOptionAttr attr) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // var document = MainDB.DocumentForInsert(EEntityType.GameOption, accountGuid, "", attr); // await _mainTable.PutItemAsync(document); // return document; // } // public async Task?> GetMailList(string accountGuid, EMailType mailType) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // EEntityType type; // switch (mailType) // { // case EMailType.RECEIVED_MAIL: type = EEntityType.ReceivedMail; break; // case EMailType.SENDED_MAIL: type = EEntityType.SendedMail; break; // default: return null; // } // List returns = new(); // string pk = MakePK(type, accountGuid); // QueryFilter filter = new QueryFilter(); // filter.AddCondition("PK", QueryOperator.Equal, pk); // filter.AddCondition("SK", QueryOperator.BeginsWith, GetSKPrefix(type)); // QueryOperationConfig operationConfig = new QueryOperationConfig // { // Filter = filter, // ConsistentRead = true, // BackwardSearch = true // }; // Search search = _mainTable.Query(operationConfig); // while (search.IsDone == false) // { // int DocumentCount = 0; // List documents = await search.GetNextSetAsync(); // foreach (Document document in documents) // { // if (DocumentCount >= Constant.MAX_READ_MAIL_DB_COUNT) // { // break; // } // MailEntity entity; // switch (mailType) // { // case EMailType.RECEIVED_MAIL: entity = new ReceivedMailEntity(document); break; // case EMailType.SENDED_MAIL: entity = new SendedMailEntity(document); break; // default: continue; // } // if (Timestamp.FromDateTime(DateTime.UtcNow) > entity.Attr.expireTime) // { // continue; // } // ++DocumentCount; // returns.Add(entity); // } // if (DocumentCount >= Constant.MAX_READ_MAIL_DB_COUNT) // { // break; // } // } // return returns; // } // public async Task UpdateMail(List entityList) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return false; // } // DocumentBatchWrite batch = _mainTable.CreateBatchWrite(); // foreach (var entity in entityList) // { // Document document = entity.DocumentForUpdate(); // batch.AddDocumentToPut(document); // } // await batch.ExecuteAsync(); // return true; // } // public async Task DeleteMail(MailEntity entity) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return false; // } // var document = entity.DocumentForDelete(); // await _mainTable.DeleteItemAsync(document); // return true; // } // public async Task GetCharMetaData(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // var key = DocumentForGet(EEntityType.CharMetaData, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document == null) // { // Log.getLogger().debug($"CharMetaData Error"); // return null; // } // return document; // } // public async Task InsertCharMetaData(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // CharMetaDataAttr attr = new CharMetaDataAttr(); // attr.MailSendCount = 0; // attr.MailSendUpdateDay = 0; // var document = MainDB.DocumentForInsert(EEntityType.CharMetaData, accountGuid, "", attr); // await _mainTable.PutItemAsync(document); // return document; // } // public async Task UpdateCharMetaData(CharMetaDataEntity entity) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // Document document = entity.DocumentForUpdate(); // await _mainTable.UpdateItemAsync(document); // return true; // } // public async Task GetInventory(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.Inventory, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document is null) // { // document = DocumentForInsert(EEntityType.Inventory, accountGuid, "", new InventoryAttr()); // } // return document; // } // public async Task?> GetItemEntityList(List itemGuids) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // List returnLIst = new(); // if (itemGuids.Count > 0) // { // var batchGet = _mainTable.CreateBatchGet(); // batchGet.ConsistentRead = true; // foreach (var itemGuid in itemGuids) // { // Document document = DocumentForGet(EEntityType.Item, itemGuid, itemGuid); // batchGet.AddKey(document); // } // await batchGet.ExecuteAsync(); // foreach (var document in batchGet.Results) // { // var entity = new ItemEntity(document); // returnLIst.Add(entity); // } // } // return returnLIst; // } // public async Task UpdateMailItems(List entites) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return; // } // if (entites.Count > 0) // { // var batchWrite = _mainTable.CreateBatchWrite(); // foreach (var entity in entites) // { // Document document = entity.DocumentForUpdate(); // batchWrite.AddDocumentToPut(document); // } // await batchWrite.ExecuteAsync(); // } // } // public async Task GetToolSlot(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.ToolSlot, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document is null) // { // document = DocumentForInsert(EEntityType.ToolSlot, accountGuid, "", new ToolSlotAttr()); // } // return document; // } // public async Task GetTattooSlot(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.TattooSlot, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document is null) // { // document = DocumentForInsert(EEntityType.TattooSlot, accountGuid, "", new TattooSlotAttr()); // } // return document; // } // public async Task UpdateTattooSlot(TattooSlotEntity tattooSlotEntity) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return false; // } // Document document = tattooSlotEntity.DocumentForUpdate(); // await _mainTable.UpdateItemAsync(document); // return true; // } // public async Task GetCart(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // var key = DocumentForGet(EEntityType.Cart, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document == null) // { // document = DocumentForInsert(EEntityType.Cart, accountGuid, "", new CartEntityAttr()); // } // return new CartEntity(document); // } // public async Task GetFriendList(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable == null"); // return null; // } // var documentList = await DocumentForGetFromPK(EEntityType.FriendList, accountGuid); // return new FriendListEntity(documentList, accountGuid); // } // public async Task GetQuestList(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable == null"); // return null; // } // var key = DocumentForGet(EEntityType.QuestList, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document == null) // { // document = DocumentForInsert(EEntityType.QuestList, accountGuid, "", new QuestListEntity()); // } // return new QuestListEntity(document); // } // public async Task?> GetQuestMailList(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable == null"); // return null; // } // ConcurrentDictionary mails = new(); // string pk = MakePK(EEntityType.QuestMail, accountGuid); // QueryFilter filter = new QueryFilter(); // filter.AddCondition("PK", QueryOperator.Equal, pk); // filter.AddCondition("SK", QueryOperator.BeginsWith, GetSKPrefix(EEntityType.QuestMail)); // QueryOperationConfig operationConfig = new QueryOperationConfig // { // Filter = filter, // ConsistentRead = true // }; // Search search = _mainTable.Query(operationConfig); // while (search.IsDone == false) // { // List documents = await search.GetNextSetAsync(); // foreach (Document document in documents) // { // QuestMailEntity entity = new QuestMailEntity(document); // mails.TryAdd(entity.Attr.questId, entity); // } // } // return mails; // } // public async Task UpdateQuestMail(List entityList) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return false; // } // DocumentBatchWrite batch = _mainTable.CreateBatchWrite(); // foreach (var entity in entityList) // { // Document document = entity.DocumentForUpdate(); // batch.AddDocumentToPut(document); // } // await batch.ExecuteAsync(); // return true; // } // public async Task GetBlockList(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable == null"); // return null; // } // var documentList = await DocumentForGetFromPK(EEntityType.BlockList, accountGuid); // return new BlockListEntity(documentList, accountGuid); // } // public async Task GetClaimRewardNormalList(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable == null"); // return null; // } // var key = DocumentForGet(EEntityType.ClaimRewardNormal, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document == null) // { // document = DocumentForInsert(EEntityType.ClaimRewardNormal, accountGuid, "", new ClaimAttr()); // await _mainTable.PutItemAsync(document); // } // return new ClaimNormalEntity(document); // } // public async Task GetClaimRewardMembershipList(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable == null"); // return null; // } // var key = DocumentForGet(EEntityType.ClaimRewardMembership, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document == null) // { // document = DocumentForInsert(EEntityType.ClaimRewardMembership, accountGuid, "", new ClaimAttr()); // await _mainTable.PutItemAsync(document); // } // return new ClaimMembershipEntity(document); // } // public async Task GetFriendFolderList(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable == null"); // return null; // } // var key = DocumentForGet(EEntityType.FriendFolderList, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document == null) // { // document = DocumentForInsert(EEntityType.FriendFolderList, accountGuid, "", new FriendFolderListAttr()); // await _mainTable.PutItemAsync(document); // } // return new FriendFolderListEntity(document); // } // public async Task GetFriendRequestList(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable == null"); // return null; // } // var documentList = await DocumentForGetFromPK(EEntityType.FriendRequestList, accountGuid); // return new FriendRequestListEntity(documentList, accountGuid); // } // public async Task AddFriendRequest(List documents) // { // bool ret = await UpdateDocuments(documents); // return ret; // } // public async Task AddFriend(List insertDocument, List deleteDocument) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return false; // } // if (insertDocument.Count == 2) // { // Log.getLogger().warn("Add Friend insertDocument count is not 2"); // DocumentBatchWrite batch = _mainTable.CreateBatchWrite(); // foreach (var document in insertDocument) // { // batch.AddDocumentToPut(document); // } // foreach (var document in deleteDocument) // { // batch.AddItemToDelete(document); // } // await batch.ExecuteAsync(); // return true; // } // return false; // } // public async Task InsertUserReport(string Pk, string Sk, UserReportAttr attr) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return false; // } // var key = DocumentForInsert(EEntityType.UserReport, Pk, Sk, attr); // await _mainTable.PutItemAsync(key); // return true; // } // public async Task GetSystemMailList() // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.SystemMail, "", ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document == null) // { // document = DocumentForInsert(EEntityType.SystemMail, "", "", new SystemMailEntityAttr()); // await _mainTable.PutItemAsync(document); // } // return document; // } // public async Task UpdateNoticeChat(NoticeChatEntity entity) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // Document document = entity.DocumentForUpdate(); // await _mainTable.UpdateItemAsync(document); // return true; // } // public async Task UpdateSystemMail(SystemMailEntity entity) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // Document document = entity.DocumentForUpdate(); // await _mainTable.UpdateItemAsync(document); // return true; // } // public async Task GetNoticeChatList() // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.NoticeChat, "", ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document == null) // { // document = DocumentForInsert(EEntityType.NoticeChat, "", "", new NoticeChatEntityAttr()); // await _mainTable.PutItemAsync(document); // } // return document; // } // public async Task GetMinimapMarker(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.MinimapMarker, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document is null) // { // document = DocumentForInsert(EEntityType.MinimapMarker, accountGuid, "", new MinimapMarkerAttr()); // } // return document; // } // public async Task GetDocument(EEntityType entityType, string PK, string SK, Object? attr = null) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(entityType, PK, SK); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document is null) // { // document = DocumentForInsert(entityType, PK, SK, attr); // await _mainTable.PutItemAsync(document); // } // return document; // } // public async Task GetCharProfile(string guid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // var key = DocumentForGet(EEntityType.CharProfile, guid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document is null) // { // Log.getLogger().debug($"CharProfile document is null guid : {guid}"); // return null; // } // return new CharProfileEntity(document); // } // public async Task UpdateCharProfile(CharProfileEntity entity) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return null; // } // Document document = entity.DocumentForUpdate(); // await _mainTable.UpdateItemAsync(document); // return true; // } // private string ToString(List documentList) // { // StringBuilder sb = new(); // foreach (var doc in documentList) // { // sb.AppendLine(doc.ToString()); // } // return sb.ToString(); // } // public async Task GetInstanceLastRoom(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.InstanceLastRoom, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document is null) // { // document = DocumentForInsert(EEntityType.InstanceLastRoom, accountGuid, "", new InstanceLastRoomAttr()); // } // return document; // } // public async Task getEscapePositionTimeInfo(string accountGuid) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return null; // } // var key = DocumentForGet(EEntityType.EscapePosition, accountGuid, ""); // var document = await _mainTable.GetItemAsync(key, operationDefaultConfig); // if (document is null) // { // document = DocumentForInsert(EEntityType.EscapePosition, accountGuid, "", new EscapePositionAttr()); // } // return document; // } // public async Task SaveEscapePositionTime(EscapePositionEntity entity) // { // try // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable is null"); // return false; // } // var document = entity.DocumentForUpdate(); // await _mainTable.UpdateItemAsync(document); // } // catch (Exception ex) // { // Log.getLogger().error($"{ex}, {entity.PK_Guid}, {entity.Attr.m_escape_available_time}"); // return false; // } // return true; // } // public async Task Transaction(List documentList, int retryCount) // { // if (_mainTable == null) // { // Log.getLogger().error("_mainTable== null"); // return false; // } // var documentTransactWrite = _mainTable.CreateTransactWrite(); // foreach (var documentInfo in documentList) // { // if (documentInfo.document == null) // { // Log.getLogger().error($"Transaction document is null"); // continue; // } // if (documentInfo.document["PK"] == string.Empty || documentInfo.document["SK"] == string.Empty) // { // Log.getLogger().error($"Transaction document PK or SK is empty {documentInfo.document["PK"]} {documentInfo.document["SK"]}"); // continue; // } // //json = JsonConvert.SerializeObject(documentList); // switch (documentInfo.executeType) // { // case EDBExecuteType.Insert: // { // documentTransactWrite.AddDocumentToPut(documentInfo.document, notExistsTranConfig); // break; // } // case EDBExecuteType.Update: // { // documentTransactWrite.AddDocumentToUpdate(documentInfo.document); // break; // } // case EDBExecuteType.Delete: // { // documentTransactWrite.AddItemToDelete(documentInfo.document); // break; // } // case EDBExecuteType.ExistsDelete: // { // documentTransactWrite.AddItemToDelete(documentInfo.document, existsTranConfig); // break; // } // default: // return false; // } // } // // 기본(1) + retryCount 만큼 처리 한다. - kangms // for (int i = 0; i <= retryCount; ++i) // { // if (i >= 1) // { // await Task.Delay(2000); // } // try // { // await documentTransactWrite.ExecuteAsync(); // } // catch (TransactionConflictException ex) // { // Log.getLogger().error($"TransactionConflictException message : {ex}, document : {ToString(documentList)}"); // continue; // } // catch (TransactionCanceledException ex) // { // Log.getLogger().error($"TransactionCanceledException message : {ex}, document : {ToString(documentList)}"); // continue; // } // catch (Exception ex) // { // Log.getLogger().error($"Exception message : {ex}, documentList : {ToString(documentList)}"); // continue; // } // return true; // } // return false; // } // public List MakeDBDocumentInfo(List documents, EDBExecuteType type) // { // List dBDocumentInfos = new(); // foreach (Document doc in documents) // { // dBDocumentInfos.Add(new DBDocumentInfo(doc, type)); // } // return dBDocumentInfos; // } // public List AppendDBDocumentInfo(List dBDocumentInfos, List documents, EDBExecuteType type) // { // foreach (Document doc in documents) // { // dBDocumentInfos.Add(new DBDocumentInfo(doc, type)); // } // return dBDocumentInfos; // } // } //}