초기커밋

This commit is contained in:
2025-05-01 07:20:41 +09:00
commit 98bb2e3c5c
2747 changed files with 646947 additions and 0 deletions

View File

@@ -0,0 +1,290 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
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;
using Amazon.S3.Model;
namespace ServerCommon
{
public class ToolActionAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
{
[JsonProperty]
public ITEM_GUID ItemGuid { get; set; } = string.Empty;
[JsonProperty]
public META_ID ItemMetaId { get; set; } = 0;
[JsonProperty]
public Int32 Step { get; set; } = 0;
[JsonProperty]
public Int32 RandomState { get; set; } = 0;
[JsonProperty]
public Int64 ActionStartDateTime { get; set; } = 0;
public ToolActionAttribute(EntityBase owner, EntityBase entityOfOwnerEntityType)
: base(owner, entityOfOwnerEntityType)
{
}
public override void onClear()
{
ItemGuid = string.Empty;
ItemMetaId = 0;
Step = 0;
RandomState = 0;
ActionStartDateTime = 0;
getAttributeState().reset();
}
public override EntityAttributeBase onCloned()
{
var owner = getOwner();
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
var parent = getEntityOfOwnerEntityType();
NullReferenceCheckHelper.throwIfNull(parent, () => $"parent is null !!!");
var cloned = new ToolActionAttribute(owner, parent);
cloned.ItemGuid = ItemGuid;
cloned.ItemMetaId = ItemMetaId;
cloned.Step = Step;
cloned.RandomState = RandomState;
cloned.ActionStartDateTime = ActionStartDateTime;
return cloned;
}
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
{
var owner = getOwner();
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
return new ToolActionAttributeTransactor(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 root_parent = owner.getRootParent();
NullReferenceCheckHelper.throwIfNull(root_parent, () => $"root_parent is null !!! - {owner.toBasicString()}");
var user_attribute = root_parent.getEntityAttribute<UserAttribute>();
NullReferenceCheckHelper.throwIfNull(user_attribute, () => $"user_attribute is null !!! - {root_parent.toBasicString()}");
USER_GUID user_guid = user_attribute.UserGuid;
//=====================================================================================
// Attribute => try pending Doc
//=====================================================================================
var try_pending_doc = getTryPendingDocBase() as ToolActionDoc;
if (null == try_pending_doc)
{
var to_copy_doc = new ToolActionDoc(OwnerEntityType.User, user_guid, ItemMetaId);
var origin_doc = getOriginDocBase<ToolActionAttribute>();
if (null != origin_doc)
{
to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc);
}
try_pending_doc = to_copy_doc;
setTryPendingDocBase(try_pending_doc);
}
var to_copy_doc_tool_action_attrib = try_pending_doc.getAttrib<ToolActionAttrib>();
NullReferenceCheckHelper.throwIfNull(to_copy_doc_tool_action_attrib, () => $"to_copy_doc_tool_action_attrib is null !!! - {root_parent.toBasicString()}");
to_copy_doc_tool_action_attrib.ItemGuid = ItemGuid;
to_copy_doc_tool_action_attrib.ItemMetaId = ItemMetaId;
to_copy_doc_tool_action_attrib.Step = Step;
to_copy_doc_tool_action_attrib.RandomState = RandomState;
to_copy_doc_tool_action_attrib.ActionStartDateTime = ActionStartDateTime;
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 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 tool_action_attribute = otherEntityAttribute as ToolActionAttribute;
if (null == tool_action_attribute)
{
err_msg = $"Failed to cast ToolActionAttribute !!!, tool_action_attribute is null";
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
ItemGuid = tool_action_attribute.ItemGuid;
ItemMetaId = tool_action_attribute.ItemMetaId;
Step = tool_action_attribute.Step;
RandomState = tool_action_attribute.RandomState;
ActionStartDateTime = tool_action_attribute.ActionStartDateTime;
//=====================================================================================
// Attribute Try Pending Doc => Origin Doc
//=====================================================================================
var try_pending_doc = tool_action_attribute.getTryPendingDocBase() as ToolActionDoc;
if (null != try_pending_doc)
{
tool_action_attribute.resetTryPendingDocBase();
syncOriginDocBaseWithNewDoc<ToolActionAttribute>(try_pending_doc);
}
var origin_doc_base = getOriginDocBase<ToolActionAttribute>();
if (null == origin_doc_base)
{
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
return result;
}
var tool_action_attrib = origin_doc_base.getAttrib<ToolActionAttrib>();
NullReferenceCheckHelper.throwIfNull(tool_action_attrib, () => $"tool_action_attrib is null !!! - {owner.toBasicString()}");
tool_action_attrib.ItemGuid = ItemGuid;
tool_action_attrib.ItemMetaId = ItemMetaId;
tool_action_attrib.Step = Step;
tool_action_attrib.RandomState = RandomState;
tool_action_attrib.ActionStartDateTime = ActionStartDateTime;
return result;
}
public bool copyEntityAttributeFromDoc(DynamoDbDocBase? docBase)
{
var err_msg = string.Empty;
var owner = getOwner();
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
var root_parent = owner.getRootParent();
NullReferenceCheckHelper.throwIfNull(root_parent, () => $"root_parent is null !!! - {owner.toBasicString()}");
var to_cast_string = typeof(ToolActionDoc).Name;
var tool_action_doc_base = docBase as ToolActionDoc;
if (null == tool_action_doc_base)
{
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, tool_action_doc_base is null :{to_cast_string}";
Log.getLogger().error(err_msg);
return false;
}
//=====================================================================================
// New Doc => Origin Doc
//=====================================================================================
syncOriginDocBaseWithNewDoc<ToolActionAttribute>(tool_action_doc_base);
//=====================================================================================
// Doc => Attribute
//=====================================================================================
var tool_action_attrib = tool_action_doc_base.getAttrib<ToolActionAttrib>();
NullReferenceCheckHelper.throwIfNull(tool_action_attrib, () => $"tool_action_attrib is null !!! - {root_parent.toBasicString()}");
ItemGuid = tool_action_attrib.ItemGuid;
ItemMetaId = tool_action_attrib.ItemMetaId;
Step = tool_action_attrib.Step;
RandomState = tool_action_attrib.RandomState;
ActionStartDateTime = tool_action_attrib.ActionStartDateTime;
return true;
}
}
public class ToolActionAttributeTransactor : EntityAttributeTransactorBase<ToolActionAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
{
public ToolActionAttributeTransactor(EntityBase owner)
: base(owner)
{
}
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
{
var err_msg = string.Empty;
var to_cast_string = typeof(ToolActionAttribute).Name;
var copy_from_tool_action_attribute = entityAttributeBase as ToolActionAttribute;
if (null == copy_from_tool_action_attribute)
{
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_from_tool_action_attribute is null :{to_cast_string}";
Log.getLogger().error(err_msg);
return false;
}
var copy_to_tool_action_attribute = getClonedEntityAttribute() as ToolActionAttribute;
if (null == copy_to_tool_action_attribute)
{
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_to_tool_action_attribute is null :{to_cast_string}";
Log.getLogger().error(err_msg);
return false;
}
copy_to_tool_action_attribute.ItemGuid = copy_from_tool_action_attribute.ItemGuid;
copy_to_tool_action_attribute.ItemMetaId = copy_from_tool_action_attribute.ItemMetaId;
copy_to_tool_action_attribute.Step = copy_from_tool_action_attribute.Step;
copy_to_tool_action_attribute.RandomState = copy_from_tool_action_attribute.RandomState;
copy_to_tool_action_attribute.ActionStartDateTime = copy_from_tool_action_attribute.ActionStartDateTime;
return true;
}
}
}