197 lines
6.9 KiB
C#
197 lines
6.9 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 META_ID = System.UInt32;
|
|
using USER_GUID = System.String;
|
|
|
|
|
|
namespace ServerCommon;
|
|
|
|
public abstract class SocialActionAttributeBase : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
|
{
|
|
[JsonProperty]
|
|
public META_ID SocialActionMetaId { get; set; } = 0;
|
|
|
|
[JsonProperty]
|
|
public UInt16 EquipedPos { get; set; } = 0;
|
|
|
|
|
|
public SocialActionAttributeBase(EntityBase owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
|
|
public override void onClear()
|
|
{
|
|
SocialActionMetaId = 0;
|
|
EquipedPos = 0;
|
|
|
|
getAttributeState().reset();
|
|
}
|
|
|
|
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
|
{
|
|
var result = new Result();
|
|
|
|
var owner = getOwner();
|
|
|
|
var user_attribute = owner.getRootParent().getEntityAttribute<UserAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(user_attribute, () => $"user_attribute is null !!! - {owner.toBasicString()}");
|
|
|
|
USER_GUID user_guid = user_attribute.UserGuid;
|
|
|
|
//=====================================================================================
|
|
// Attribute => try pending Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = getTryPendingDocBase() as SocialActionDoc;
|
|
if (null == try_pending_doc)
|
|
{
|
|
var to_copy_doc = onCreateDocBase() as SocialActionDoc;
|
|
NullReferenceCheckHelper.throwIfNull(to_copy_doc, () => $"to_copy_doc is null !!! - {owner.toBasicString()}");
|
|
|
|
var origin_doc = getOriginDocBase<SocialActionAttributeBase>();
|
|
if (null != origin_doc)
|
|
{
|
|
to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc);
|
|
}
|
|
|
|
try_pending_doc = to_copy_doc;
|
|
|
|
setTryPendingDocBase(try_pending_doc);
|
|
}
|
|
|
|
var social_action_attrib = try_pending_doc.getAttrib<SocialActionAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(social_action_attrib, () => $"social_action_attrib is null !!! - {owner.toBasicString()}");
|
|
|
|
social_action_attrib.SocialActionMetaId = SocialActionMetaId;
|
|
social_action_attrib.EquipedPos = EquipedPos;
|
|
|
|
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(SocialActionDoc).Name;
|
|
|
|
var social_action_doc = docBase as SocialActionDoc;
|
|
if (null == social_action_doc)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, social_action_doc is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
//=====================================================================================
|
|
// New Doc => Origin Doc
|
|
//=====================================================================================
|
|
syncOriginDocBaseWithNewDoc<SocialActionAttributeBase>(social_action_doc);
|
|
|
|
//=====================================================================================
|
|
// Doc => Attribute
|
|
//=====================================================================================
|
|
var doc_attrib = social_action_doc.getAttrib<SocialActionAttrib>();
|
|
ArgumentNullException.ThrowIfNull(doc_attrib);
|
|
|
|
SocialActionMetaId = doc_attrib.SocialActionMetaId;
|
|
EquipedPos = doc_attrib.EquipedPos;
|
|
|
|
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 social_action_attribute = otherEntityAttribute as SocialActionAttributeBase;
|
|
if (null == social_action_attribute)
|
|
{
|
|
err_msg = $"Failed to cast SocialActionAttribute !!!, social_action_attribute is null";
|
|
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
SocialActionMetaId = social_action_attribute.SocialActionMetaId;
|
|
EquipedPos = social_action_attribute.EquipedPos;
|
|
|
|
//=====================================================================================
|
|
// Attribute Try Pending Doc => Origin Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = social_action_attribute.getTryPendingDocBase() as SocialActionDoc;
|
|
if (null != try_pending_doc)
|
|
{
|
|
social_action_attribute.resetTryPendingDocBase();
|
|
|
|
syncOriginDocBaseWithNewDoc<SocialActionAttributeBase>(try_pending_doc);
|
|
}
|
|
|
|
var origin_doc_base = getOriginDocBase<SocialActionAttributeBase>();
|
|
if (null == origin_doc_base)
|
|
{
|
|
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
|
return result;
|
|
}
|
|
|
|
var social_action_attrib = origin_doc_base.getAttrib<SocialActionAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(social_action_attrib, () => $"social_action_attrib is null !!! - {owner.toBasicString()}");
|
|
|
|
social_action_attrib.SocialActionMetaId = SocialActionMetaId;
|
|
social_action_attrib.EquipedPos = EquipedPos;
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public class SocialActionAttributeBaseTransactor<TSocialActionAttributeBase> : EntityAttributeTransactorBase<TSocialActionAttributeBase>
|
|
where TSocialActionAttributeBase : SocialActionAttributeBase
|
|
{
|
|
public SocialActionAttributeBaseTransactor(EntityBase owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
}
|