using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.Security.Cryptography.Xml; using Newtonsoft.Json; using ServerCore; using ServerBase; using USER_GUID = System.String; using Amazon.S3.Model; namespace ServerCommon { public class GameOptionAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute { [JsonProperty] public string options { get; set; } = string.Empty; public GameOptionAttribute(EntityBase owner) : base(owner) { } public override void onClear() { options = string.Empty; getAttributeState().reset(); } public override EntityAttributeBase onCloned() { var owner = getOwner() as UserBase; NullReferenceCheckHelper.throwIfNull(owner, () => "UserBase is null !!!"); var cloned = new GameOptionAttribute(owner); return cloned; } public override IEntityAttributeTransactor onNewEntityAttributeTransactor() { var owner = getOwner() as UserBase; NullReferenceCheckHelper.throwIfNull(owner, () => "UserBase is null !!!"); return new GameOptionAttributeTransactor(owner); } public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true) { var result = new Result(); var owner = getOwner(); NullReferenceCheckHelper.throwIfNull(owner, () => "UserBase is null !!!"); var acoount_attribute = owner.getEntityAttribute(); NullReferenceCheckHelper.throwIfNull(acoount_attribute, () => $"account attribute is null !!! - {owner.toBasicString()}"); USER_GUID user_guid = acoount_attribute.UserGuid; //===================================================================================== // Attribute => try pending Doc //===================================================================================== var try_pending_doc = getTryPendingDocBase() as GameOptionDoc; if (null == try_pending_doc) { var to_copy_doc = new GameOptionDoc(user_guid); var origin_doc = getOriginDocBase(); if (null != origin_doc) { to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc); } try_pending_doc = to_copy_doc; setTryPendingDocBase(try_pending_doc); } var to_copy_doc_attrib = try_pending_doc.getAttrib(); NullReferenceCheckHelper.throwIfNull(to_copy_doc_attrib, () => $"game option attrib is null !!! - {owner.toBasicString()}"); to_copy_doc_attrib.options = options; if (false == isForQuery) { return (result, try_pending_doc); } //===================================================================================== // Doc QueryType 반영 //===================================================================================== (result, var to_query_doc) = await applyDoc4Query(try_pending_doc); if (result.isFail()) { return (result, null); } return (result, to_query_doc); } public bool copyEntityAttributeFromDoc(DynamoDbDocBase docBase) { var result = new Result(); var err_msg = string.Empty; var to_cast_string = typeof(GameOptionDoc).Name; var game_option_doc_base = docBase as GameOptionDoc; if (null == game_option_doc_base) { err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, game_option_doc_base is null :{to_cast_string}"; Log.getLogger().error(err_msg); return false; } //===================================================================================== // New Doc => Origin Doc //===================================================================================== syncOriginDocBaseWithNewDoc(game_option_doc_base); //===================================================================================== // Doc => Attribute //===================================================================================== var doc_attrib = game_option_doc_base.getAttrib(); if (doc_attrib == null) { err_msg = $"Failed to get game option attrib : {nameof(GameOptionAttrib)}"; result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg); Log.getLogger().error(err_msg); return false; } options = doc_attrib.options; return true; } public Result onMerge(EntityAttributeBase otherEntityAttribute) { var owner = getOwner(); NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!"); var result = new Result(); var err_msg = string.Empty; if (null == otherEntityAttribute) { err_msg = $"Invalid Param !!!, otherEntityAttribute is null"; result.setFail(ServerErrorCode.FunctionParamNull, err_msg); Log.getLogger().error(result.toBasicString()); return result; } //===================================================================================== // OtherAttribute => Attribute //===================================================================================== var game_option_attribute = otherEntityAttribute as GameOptionAttribute; if (null == game_option_attribute) { err_msg = $"Failed to cast GameOptionAttribute !!!, game_option_attribute is null"; result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg); Log.getLogger().error(result.toBasicString()); return result; } options = game_option_attribute.options; //===================================================================================== // Attribute Try Pending Doc => Origin Doc //===================================================================================== var try_pending_doc = game_option_attribute.getTryPendingDocBase() as GameOptionDoc; if (null != try_pending_doc) { game_option_attribute.resetTryPendingDocBase(); syncOriginDocBaseWithNewDoc(try_pending_doc); } var origin_doc_base = getOriginDocBase(); if (null == origin_doc_base) { // DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!! return result; } var game_option_attrib = origin_doc_base.getAttrib(); NullReferenceCheckHelper.throwIfNull(game_option_attrib, () => $"game_option_attrib is null !!! - {owner.toBasicString()}"); game_option_attrib.options = options; return result; } } public class GameOptionAttributeTransactor : EntityAttributeTransactorBase, ICopyEntityAttributeTransactorFromEntityAttribute { public GameOptionAttributeTransactor(UserBase owner) : base(owner) { } public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttributeBase) { var err_msg = string.Empty; var to_cast_string = typeof(GameOptionAttribute).Name; var copy_from_game_option_attribute = entityAttributeBase as GameOptionAttribute; if (null == copy_from_game_option_attribute) { err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_from_game_option_attribute is null :{to_cast_string}"; Log.getLogger().error(err_msg); return false; } var copy_to_game_option_attribute = getClonedEntityAttribute() as GameOptionAttribute; if (null == copy_to_game_option_attribute) { err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_to_game_option_attribute is null :{to_cast_string}"; Log.getLogger().error(err_msg); return false; } copy_to_game_option_attribute.options = copy_from_game_option_attribute.options; return true; } } }