309 lines
11 KiB
C#
309 lines
11 KiB
C#
|
|
|
|
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 MailProfileAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
|
{
|
|
[JsonProperty]
|
|
public Int32 SendMailCount { get; set; } = 0;
|
|
|
|
[JsonProperty]
|
|
public Int64 SendMailUpdateDay { get; set; } = 0;
|
|
|
|
[JsonProperty]
|
|
public Int32 LastSystemMailId { get; set; } = 0;
|
|
|
|
public Dictionary<Int32, DateTime> ReceivedSystemMails { get; set; } = new();
|
|
|
|
|
|
public MailProfileAttribute(UserBase owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
public override void onClear()
|
|
{
|
|
SendMailCount = 0;
|
|
SendMailUpdateDay = 0;
|
|
LastSystemMailId = 0;
|
|
ReceivedSystemMails.Clear();
|
|
|
|
getAttributeState().reset();
|
|
}
|
|
|
|
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
|
{
|
|
var owner = getOwner() as UserBase;
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => "owner is null !!!");
|
|
|
|
return new MailProfileAttributeTransactor(owner);
|
|
}
|
|
|
|
public override EntityAttributeBase onCloned()
|
|
{
|
|
var owner = getOwner() as UserBase;
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => "owner is null !!!");
|
|
|
|
var cloned = new MailProfileAttribute(owner);
|
|
cloned.SendMailCount = SendMailCount;
|
|
cloned.SendMailUpdateDay = SendMailUpdateDay;
|
|
cloned.LastSystemMailId = LastSystemMailId;
|
|
|
|
cloned.ReceivedSystemMails = new();
|
|
foreach (var mail in ReceivedSystemMails)
|
|
{
|
|
if (false == cloned.ReceivedSystemMails.TryAdd(mail.Key, mail.Value))
|
|
{
|
|
Log.getLogger().warn($"ReceivedSystemMails add return false key : {mail.Key}, value : {mail.Value}");
|
|
}
|
|
}
|
|
|
|
return cloned;
|
|
}
|
|
|
|
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
|
{
|
|
var result = new Result();
|
|
|
|
var owner = getOwner() as UserBase;
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => "owner is null !!!");
|
|
|
|
var acoount_attribute = owner.getEntityAttribute<AccountAttribute>();
|
|
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 MailProfileDoc;
|
|
if (null == try_pending_doc)
|
|
{
|
|
var to_copy_doc = new MailProfileDoc(user_guid);
|
|
|
|
var origin_doc = getOriginDocBase<MailProfileAttribute>();
|
|
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<MailProfileAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(to_copy_doc_attrib, () => $"to_copy_doc_attrib is null !!! - user_guid: {user_guid}");
|
|
|
|
to_copy_doc_attrib.SendMailUpdateDay = SendMailUpdateDay;
|
|
to_copy_doc_attrib.LastSystemMailId = LastSystemMailId;
|
|
to_copy_doc_attrib.SendMailCount = SendMailCount;
|
|
|
|
to_copy_doc_attrib.ReceivedSystemMails = new();
|
|
foreach (var mail in ReceivedSystemMails)
|
|
{
|
|
if (false == to_copy_doc_attrib.ReceivedSystemMails.TryAdd(mail.Key, mail.Value))
|
|
{
|
|
Log.getLogger().warn($"ReceivedSystemMails add return false key : {mail.Key}, value : {mail.Value}");
|
|
}
|
|
}
|
|
|
|
|
|
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 err_msg = string.Empty;
|
|
|
|
var to_cast_string = typeof(MailProfileDoc).Name;
|
|
|
|
var mail_profile_doc_base = docBase as MailProfileDoc;
|
|
if (null == mail_profile_doc_base)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, mail_profile_doc_base is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
//=====================================================================================
|
|
// New Doc => Origin Doc
|
|
//=====================================================================================
|
|
syncOriginDocBaseWithNewDoc<MailProfileAttribute>(mail_profile_doc_base);
|
|
|
|
//=====================================================================================
|
|
// Doc => Attribute
|
|
//=====================================================================================
|
|
var doc_attrib = mail_profile_doc_base.getAttrib<MailProfileAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(doc_attrib, () => "doc_attrib is null !!!");
|
|
|
|
SendMailUpdateDay = doc_attrib.SendMailUpdateDay;
|
|
LastSystemMailId = doc_attrib.LastSystemMailId;
|
|
SendMailCount = doc_attrib.SendMailCount;
|
|
|
|
ReceivedSystemMails = new();
|
|
foreach (var mail in doc_attrib.ReceivedSystemMails)
|
|
{
|
|
if (false == ReceivedSystemMails.TryAdd(mail.Key, mail.Value))
|
|
{
|
|
Log.getLogger().warn($"ReceivedSystemMails add return false key : {mail.Key}, value : {mail.Value}");
|
|
}
|
|
}
|
|
|
|
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 mail_profile_attribute = otherEntityAttribute as MailProfileAttribute;
|
|
if (null == mail_profile_attribute)
|
|
{
|
|
err_msg = $"Failed to cast MailProfileAttribute !!!, mail_profile_attribute is null";
|
|
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
SendMailUpdateDay = mail_profile_attribute.SendMailUpdateDay;
|
|
LastSystemMailId = mail_profile_attribute.LastSystemMailId;
|
|
SendMailCount = mail_profile_attribute.SendMailCount;
|
|
|
|
ReceivedSystemMails = new();
|
|
foreach (var mail in mail_profile_attribute.ReceivedSystemMails)
|
|
{
|
|
if (false == ReceivedSystemMails.TryAdd(mail.Key, mail.Value))
|
|
{
|
|
Log.getLogger().warn($"ReceivedSystemMails add return false key : {mail.Key}, value : {mail.Value}");
|
|
}
|
|
}
|
|
|
|
//=====================================================================================
|
|
// Attribute Try Pending Doc => Origin Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = mail_profile_attribute.getTryPendingDocBase() as MailProfileDoc ;
|
|
if (null != try_pending_doc)
|
|
{
|
|
mail_profile_attribute.resetTryPendingDocBase();
|
|
|
|
syncOriginDocBaseWithNewDoc<MailProfileAttribute>(try_pending_doc);
|
|
}
|
|
|
|
var origin_doc_base = getOriginDocBase<MailProfileAttribute>();
|
|
if (null == origin_doc_base)
|
|
{
|
|
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
|
return result;
|
|
}
|
|
|
|
var mail_profile_attrib = origin_doc_base.getAttrib<MailProfileAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(mail_profile_attrib, () => $"mail_profile_attrib is null !!! - {owner.toBasicString()}");
|
|
|
|
mail_profile_attrib.SendMailUpdateDay = SendMailUpdateDay;
|
|
mail_profile_attrib.LastSystemMailId = LastSystemMailId;
|
|
mail_profile_attrib.SendMailCount = SendMailCount;
|
|
|
|
foreach (var mail in ReceivedSystemMails)
|
|
{
|
|
mail_profile_attrib.ReceivedSystemMails.TryAdd(mail.Key, mail.Value);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public class MailProfileAttributeTransactor : EntityAttributeTransactorBase<MailProfileAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
|
|
{
|
|
public MailProfileAttributeTransactor(UserBase owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
|
|
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
|
|
{
|
|
var err_msg = string.Empty;
|
|
|
|
var to_cast_string = typeof(MailProfileAttribute).Name;
|
|
|
|
var copy_from_mail_profile_attribute = entityAttributeBase as MailProfileAttribute;
|
|
if (null == copy_from_mail_profile_attribute)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_from_mail_profile_attribute is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
var copy_to_mail_attribute = getClonedEntityAttribute() as MailProfileAttribute;
|
|
if (null == copy_to_mail_attribute)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_to_mail_attribute is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
copy_to_mail_attribute.SendMailCount = copy_from_mail_profile_attribute.SendMailCount;
|
|
copy_to_mail_attribute.SendMailUpdateDay = copy_from_mail_profile_attribute.SendMailUpdateDay;
|
|
copy_to_mail_attribute.LastSystemMailId = copy_from_mail_profile_attribute.LastSystemMailId;
|
|
|
|
copy_to_mail_attribute.ReceivedSystemMails = new();
|
|
foreach (var mail in copy_from_mail_profile_attribute.ReceivedSystemMails)
|
|
{
|
|
if (false == copy_to_mail_attribute.ReceivedSystemMails.TryAdd(mail.Key, mail.Value))
|
|
{
|
|
Log.getLogger().warn($"ReceivedSystemMails add return false key : {mail.Key}, value : {mail.Value}");
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|