using ServerCommon; using ServerCore; using ServerBase; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GameServer { internal class BuildingProfitHistoryAgentAction : EntityActionBase { ConcurrentBag m_building_profit_historys = new(); public BuildingProfitHistoryAgentAction(Building owner) : base(owner) { } public override async Task onInit() { var result = new Result(); return await Task.FromResult(result); } public override void onClear() { return; } public async Task tryLoadBuildingProfitHistoryFromDb(int buildingMetaId) { var result = new Result(); var err_msg = string.Empty; var server_logic = GameServerApp.getServerLogic(); var db_client = server_logic.getDynamoDbClient(); var doc = new BuildingProfitHistoryDoc(); doc.setCombinationKeyForPK(buildingMetaId.ToString()); var error_code = doc.onApplyPKSK(); if (error_code.isFail()) { err_msg = $"Failed to onApplyPKSK() !!! : {error_code.toBasicString()}"; result.setFail(error_code, err_msg); Log.getLogger().error(result.toBasicString()); return result; } var query_config = db_client.makeQueryConfigWithPKSKBySKBeginWith(doc.getPK(), BuildingProfitHistoryDoc.getPrefixOfSK()); (result, var read_docs) = await db_client.simpleQueryDocTypesWithQueryOperationConfig(query_config); if (result.isFail()) { err_msg = $"Failed to simpleQueryDocTypesWithQueryOperationConfig() !!! : {result.toBasicString()}"; Log.getLogger().error(err_msg); return result; } var building = getOwner() as Building; NullReferenceCheckHelper.throwIfNull(building, () => $"building is null !!!"); foreach (var read_doc in read_docs) { var building_profit_history = new BuildingProfitHistory(building); await building_profit_history.onInit(); var building_profit_history_action = building_profit_history.getEntityAction(); NullReferenceCheckHelper.throwIfNull(building_profit_history_action, () => $"building_profit_history_attribute is null !!!"); result = building_profit_history_action.tryLoadBuildingProfitHistoryFromDoc(read_doc); if (result.isFail()) { err_msg = $"Failed to tryLoadBuildingProfitHistoryFromDoc() !!! : {result.toBasicString()}"; Log.getLogger().error(err_msg); return result; } var building_profit_history_attribute = building_profit_history.getEntityAttribute(); NullReferenceCheckHelper.throwIfNull(building_profit_history_attribute, () => $"building_profit_history_attribute is null !!!"); m_building_profit_historys.Add(building_profit_history); } return result; } public List getBuildingProfitHistoryInfos() { var building_profit_story_infos = new List(); foreach (var building_profit_history in m_building_profit_historys) { var building_profit_history_info = building_profit_history.toBuildingProfitHistoryInfo(); building_profit_story_infos.Add(building_profit_history_info); } return building_profit_story_infos; } public void addBuildingProfitHistory(BuildingProfitHistory buildingProfitHistory) { m_building_profit_historys.Add(buildingProfitHistory); } } }