using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using ServerCore; using ServerBase; using SESSION_ID = System.Int32; using WORLD_ID = System.UInt32; 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 NicknameAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute { [JsonProperty] public string Nickname { get; set; } = string.Empty; public NicknameAttribute(EntityBase owner) : base(owner) { } public override void onClear() { Nickname = string.Empty; getAttributeState().reset(); } public override EntityAttributeBase onCloned() { var owner = getOwner(); ArgumentNullException.ThrowIfNull(owner); var cloned = new NicknameAttribute(owner); cloned.Nickname = Nickname; return cloned; } public override IEntityAttributeTransactor onNewEntityAttributeTransactor() { var owner = getOwner(); ArgumentNullException.ThrowIfNull(owner); return new NicknameAttributeTransactor(owner); } public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true) { var result = new Result(); var owner = getOwner(); NullReferenceCheckHelper.throwIfNull(owner, () => "owner is null"); var user_attribute = owner.getEntityAttribute(); NullReferenceCheckHelper.throwIfNull(user_attribute, () => "user_attribute is null"); USER_GUID user_guid = user_attribute.UserGuid; //===================================================================================== // Attribute => try pending Doc //===================================================================================== var try_pending_doc = getTryPendingDocBase() as NicknameDoc; if (null == try_pending_doc) { var to_copy_doc = new NicknameDoc(OwnerEntityType.User, user_guid, string.Empty); 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, () => $"to_copy_doc_attrib is null !!!"); to_copy_doc_attrib.Nickname = Nickname; 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, to_query_doc); } return (result, to_query_doc); } public Result onMerge(EntityAttributeBase otherEntityAttribute) { var result = new Result(); var err_msg = string.Empty; var owner = getOwner(); NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!"); 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 nickname_attribute = otherEntityAttribute as NicknameAttribute; if (null == nickname_attribute) { err_msg = $"Failed to cast NicknameAttribute !!!, nickname_attribute is null"; result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg); Log.getLogger().error(result.toBasicString()); return result; } Nickname = nickname_attribute.Nickname; //===================================================================================== // Attribute Try Pending Doc => Origin Doc //===================================================================================== var try_pending_doc = nickname_attribute.getTryPendingDocBase() as NicknameDoc; if (null != try_pending_doc) { nickname_attribute.resetTryPendingDocBase(); syncOriginDocBaseWithNewDoc(try_pending_doc); } var origin_doc_base = getOriginDocBase(); if (null == origin_doc_base) { // DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!! return result; } var nickname_attrib = origin_doc_base.getAttrib(); NullReferenceCheckHelper.throwIfNull(nickname_attrib, () => $"nickname_attrib is null !!! - {owner.toBasicString()}"); nickname_attrib.Nickname = Nickname; return result; } public bool copyEntityAttributeFromDoc(DynamoDbDocBase? docBase) { var err_msg = string.Empty; var to_cast_string = typeof(NicknameDoc).Name; var nickame_doc_base = docBase as NicknameDoc; if (null == nickame_doc_base) { err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, nickame_doc_base is null :{to_cast_string}"; Log.getLogger().error(err_msg); return false; } //===================================================================================== // New Doc => Origin Doc //===================================================================================== syncOriginDocBaseWithNewDoc(nickame_doc_base); //===================================================================================== // Doc => Attribute //===================================================================================== var nickname_attrib = nickame_doc_base.getAttrib(); NullReferenceCheckHelper.throwIfNull(nickname_attrib, () => $"nickname_attrib is null !!!"); Nickname = nickname_attrib.Nickname; return true; } } public class NicknameAttributeTransactor : EntityAttributeTransactorBase, ICopyEntityAttributeTransactorFromEntityAttribute { public NicknameAttributeTransactor(EntityBase owner) : base(owner) { } public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttributeBase) { var err_msg = string.Empty; var to_cast_string = typeof(NicknameAttribute).Name; var copy_from_nickname_attribute = entityAttributeBase as NicknameAttribute; if (null == copy_from_nickname_attribute) { err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_from_nickname_attribute is null :{to_cast_string}"; Log.getLogger().error(err_msg); return false; } var copy_to_nickname_attribute = getClonedEntityAttribute() as NicknameAttribute; if (null == copy_to_nickname_attribute) { err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_to_nickname_attribute is null :{to_cast_string}"; Log.getLogger().error(err_msg); return false; } copy_to_nickname_attribute.Nickname = copy_from_nickname_attribute.Nickname; return true; } } }