221 lines
8.1 KiB
C#
221 lines
8.1 KiB
C#
using Newtonsoft.Json;
|
|
|
|
|
|
using ServerCore;
|
|
using ServerBase;
|
|
|
|
|
|
using USER_GUID = System.String;
|
|
using META_ID = System.UInt32;
|
|
|
|
|
|
namespace ServerCommon;
|
|
|
|
public class EscapePositionAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
|
{
|
|
[JsonProperty]
|
|
public DateTime escape_available_time = new();
|
|
|
|
public EscapePositionAttribute(UserBase owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
|
|
public bool copyEntityAttributeFromDoc(DynamoDbDocBase docBase)
|
|
{
|
|
var err_msg = string.Empty;
|
|
|
|
var to_cast_string = typeof(EscapePositionDoc).Name;
|
|
|
|
var escape_position_doc_base = docBase as EscapePositionDoc;
|
|
if (null == escape_position_doc_base)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, escape_position_doc_base is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
//=====================================================================================
|
|
// New Doc => Origin Doc
|
|
//=====================================================================================
|
|
syncOriginDocBaseWithNewDoc<EscapePositionAttribute>(escape_position_doc_base);
|
|
|
|
//=====================================================================================
|
|
// Doc => Doc, Attribute
|
|
//=====================================================================================
|
|
var doc_attrib = escape_position_doc_base.getAttrib<EscapePositionAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(doc_attrib, () => $"doc_attrib is null !!!");
|
|
|
|
escape_available_time = doc_attrib.escape_available_time;
|
|
|
|
return true;
|
|
}
|
|
|
|
public override void onClear()
|
|
{
|
|
escape_available_time = new();
|
|
}
|
|
|
|
public override EntityAttributeBase onCloned()
|
|
{
|
|
var owner = getOwner() as UserBase;
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
|
|
var cloned = new EscapePositionAttribute(owner);
|
|
cloned.escape_available_time = escape_available_time;
|
|
|
|
return cloned;
|
|
}
|
|
|
|
public Result onMerge(EntityAttributeBase otherEntityAttribute)
|
|
{
|
|
var owner = getOwner();
|
|
|
|
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 escape_position_attribute = otherEntityAttribute as EscapePositionAttribute;
|
|
if (null == escape_position_attribute)
|
|
{
|
|
err_msg = $"Failed to cast EscapePositionAttribute !!!, escape_position_attribute is null";
|
|
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
escape_available_time = escape_position_attribute.escape_available_time;
|
|
|
|
//=====================================================================================
|
|
// Attribute Try Pending Doc => Origin Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = escape_position_attribute.getTryPendingDocBase() as EscapePositionDoc;
|
|
if (null != try_pending_doc)
|
|
{
|
|
escape_position_attribute.resetTryPendingDocBase();
|
|
|
|
syncOriginDocBaseWithNewDoc<EscapePositionAttribute>(try_pending_doc);
|
|
}
|
|
|
|
var origin_doc_base = getOriginDocBase<EscapePositionAttribute>();
|
|
if (null == origin_doc_base)
|
|
{
|
|
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
|
return result;
|
|
}
|
|
|
|
var escape_position_attrib = origin_doc_base.getAttrib<EscapePositionAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(escape_position_attrib, () => $"escape_position_attrib is null !!! - {owner.toBasicString()}");
|
|
|
|
escape_position_attrib.escape_available_time = escape_available_time;
|
|
|
|
return result;
|
|
}
|
|
|
|
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
|
{
|
|
var owner = getOwner() as UserBase;
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
|
|
return new EscapePositionAttributeTransactor(owner);
|
|
}
|
|
|
|
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, () => $"acoount_attribute is null !!!");
|
|
|
|
USER_GUID user_guid = acoount_attribute.UserGuid;
|
|
|
|
//=====================================================================================
|
|
// Attribute => Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = getTryPendingDocBase() as EscapePositionDoc;
|
|
if (try_pending_doc == null)
|
|
{
|
|
var to_copy_doc = new EscapePositionDoc(user_guid);
|
|
|
|
var origin_doc = getOriginDocBase<EscapePositionAttribute>();
|
|
if (null != origin_doc)
|
|
{
|
|
to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc);
|
|
}
|
|
|
|
try_pending_doc = to_copy_doc;
|
|
|
|
setTryPendingDocBase(try_pending_doc);
|
|
}
|
|
|
|
var escape_position_attrib = try_pending_doc.getAttrib<EscapePositionAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(escape_position_attrib, () => $"escape_position_attrib is null !!!");
|
|
|
|
escape_position_attrib.escape_available_time = escape_available_time;
|
|
|
|
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 class EscapePositionAttributeTransactor : EntityAttributeTransactorBase<EscapePositionAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
|
|
{
|
|
public EscapePositionAttributeTransactor(UserBase owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
|
|
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
|
|
{
|
|
var err_msg = string.Empty;
|
|
|
|
var to_cast_string = typeof(EscapePositionAttribute).Name;
|
|
|
|
var copy_from_escape_position_attribute = entityAttributeBase as EscapePositionAttribute;
|
|
if (null == copy_from_escape_position_attribute)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_from_escape_position_attribute is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
var copy_to_escape_position_attribute = getClonedEntityAttribute() as EscapePositionAttribute;
|
|
if (null == copy_to_escape_position_attribute)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_to_escape_position_attribute is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
copy_to_escape_position_attribute.escape_available_time = copy_from_escape_position_attribute.escape_available_time;
|
|
return true;
|
|
}
|
|
}
|