236 lines
9.6 KiB
C#
236 lines
9.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
using ServerCore; using ServerBase;
|
|
|
|
|
|
using USER_GUID = System.String;
|
|
|
|
|
|
namespace ServerCommon
|
|
{
|
|
public class UserContentsSettingAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
|
{
|
|
[JsonProperty]
|
|
public int MyhomeSlotOpenCount { get; set; } = 0;
|
|
|
|
[JsonProperty]
|
|
public DateTime BeaconAppProfileUploadTime { get; set; } = new();
|
|
|
|
public UserContentsSettingAttribute(EntityBase owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
|
|
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
|
{
|
|
return new UserContentsSettingAttributeTransactor(getOwner());
|
|
}
|
|
|
|
public override void onClear()
|
|
{
|
|
MyhomeSlotOpenCount = 0;
|
|
BeaconAppProfileUploadTime = new();
|
|
|
|
getAttributeState().reset();
|
|
}
|
|
|
|
public override EntityAttributeBase onCloned()
|
|
{
|
|
var cloned = new UserContentsSettingAttribute(getOwner());
|
|
|
|
cloned.deepCopyFromBase(this);
|
|
|
|
cloned.MyhomeSlotOpenCount = MyhomeSlotOpenCount;
|
|
cloned.BeaconAppProfileUploadTime = BeaconAppProfileUploadTime;
|
|
|
|
return cloned;
|
|
}
|
|
|
|
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
|
{
|
|
var result = new Result();
|
|
|
|
var user_base = getOwner() as UserBase;
|
|
NullReferenceCheckHelper.throwIfNull(user_base, () => $"user_base is null !!!");
|
|
|
|
var user_attribute = user_base.getRootParent().getEntityAttribute<UserAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(user_attribute, () => $"user_attribute is null !!! - {user_base.toBasicString()}");
|
|
|
|
USER_GUID user_guid = user_attribute.UserGuid;
|
|
|
|
//=====================================================================================
|
|
// Attribute => try pending Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = getTryPendingDocBase() as UserContentsSettingDoc;
|
|
if (null == try_pending_doc)
|
|
{
|
|
var to_copy_doc = new UserContentsSettingDoc(user_guid);
|
|
|
|
var origin_doc = getOriginDocBase<UserContentsSettingAttribute>();
|
|
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<UserContentsSettingAttrib>();
|
|
ArgumentNullException.ThrowIfNull(to_copy_doc_attrib);
|
|
to_copy_doc_attrib.MyhomeSlotOpenCount = MyhomeSlotOpenCount;
|
|
to_copy_doc_attrib.BeaconAppProfileUploadTime = BeaconAppProfileUploadTime;
|
|
|
|
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(UserContentsSettingDoc).Name;
|
|
|
|
var user_contents_setting_doc_base = docBase as UserContentsSettingDoc;
|
|
if (null == user_contents_setting_doc_base)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, user_contents_setting_doc_base is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
//=====================================================================================
|
|
// New Doc => Origin Doc
|
|
//=====================================================================================
|
|
syncOriginDocBaseWithNewDoc<UserContentsSettingAttribute>(user_contents_setting_doc_base);
|
|
|
|
//=====================================================================================
|
|
// Doc => Attribute
|
|
//=====================================================================================
|
|
var doc_attrib = user_contents_setting_doc_base.getAttrib<UserContentsSettingAttrib>();
|
|
ArgumentNullException.ThrowIfNull(doc_attrib);
|
|
|
|
MyhomeSlotOpenCount = doc_attrib.MyhomeSlotOpenCount;
|
|
BeaconAppProfileUploadTime = doc_attrib.BeaconAppProfileUploadTime;
|
|
|
|
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 user_contents_setting_attribute = otherEntityAttribute as UserContentsSettingAttribute;
|
|
if (null == user_contents_setting_attribute)
|
|
{
|
|
err_msg = $"Failed to cast UserContentsSettingAttribute !!!, user_contents_setting_attribute is null";
|
|
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
MyhomeSlotOpenCount = user_contents_setting_attribute.MyhomeSlotOpenCount;
|
|
BeaconAppProfileUploadTime = user_contents_setting_attribute.BeaconAppProfileUploadTime;
|
|
|
|
//=====================================================================================
|
|
// Attribute Try Pending Doc => Origin Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = user_contents_setting_attribute.getTryPendingDocBase() as UserContentsSettingDoc;
|
|
if (null != try_pending_doc)
|
|
{
|
|
user_contents_setting_attribute.resetTryPendingDocBase();
|
|
|
|
syncOriginDocBaseWithNewDoc<UserContentsSettingAttribute>(try_pending_doc);
|
|
}
|
|
|
|
var origin_doc_base = getOriginDocBase<UserContentsSettingAttribute>();
|
|
if (null == origin_doc_base)
|
|
{
|
|
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
|
return result;
|
|
}
|
|
|
|
var account_base_attrib = origin_doc_base.getAttrib<UserContentsSettingAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(account_base_attrib, () => $"account_base_attrib is null !!! - {owner.toBasicString()}");
|
|
|
|
user_contents_setting_attribute.MyhomeSlotOpenCount = MyhomeSlotOpenCount;
|
|
user_contents_setting_attribute.BeaconAppProfileUploadTime = BeaconAppProfileUploadTime;
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public class UserContentsSettingAttributeTransactor : EntityAttributeTransactorBase<UserContentsSettingAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
|
|
{
|
|
public UserContentsSettingAttributeTransactor(EntityBase owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
|
|
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
|
|
{
|
|
var err_msg = string.Empty;
|
|
|
|
var to_cast_string = typeof(UserContentsSettingAttribute).Name;
|
|
|
|
var copy_from_user_contents_setting_attribute = entityAttributeBase as UserContentsSettingAttribute;
|
|
if (null == copy_from_user_contents_setting_attribute)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeTransactorBaseFromEntityAttribute() !!!, copy_from_user_contents_setting_attribute is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
var copy_to_user_contents_setting_attribute = getClonedEntityAttribute() as UserContentsSettingAttribute;
|
|
if (null == copy_to_user_contents_setting_attribute)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeTransactorBaseFromEntityAttribute() !!!, copy_to_user_contents_setting_attribute is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
copy_to_user_contents_setting_attribute.MyhomeSlotOpenCount = copy_from_user_contents_setting_attribute.MyhomeSlotOpenCount;
|
|
copy_to_user_contents_setting_attribute.BeaconAppProfileUploadTime = copy_from_user_contents_setting_attribute.BeaconAppProfileUploadTime;
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|