228 lines
8.6 KiB
C#
228 lines
8.6 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using ServerCore; using ServerBase;
|
|
|
|
|
|
using META_ID = System.UInt32;
|
|
using USER_GUID = System.String;
|
|
|
|
|
|
namespace ServerCommon
|
|
{
|
|
public class CraftRecipeAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
|
{
|
|
[JsonProperty]
|
|
public META_ID CraftMetaId { get; set; } = 0;
|
|
|
|
public CraftRecipeAttribute(EntityBase owner, EntityBase entityOfOwnerEntityType)
|
|
: base(owner, entityOfOwnerEntityType)
|
|
{
|
|
}
|
|
|
|
public override void onClear()
|
|
{
|
|
CraftMetaId = 0;
|
|
}
|
|
|
|
public override EntityAttributeBase onCloned()
|
|
{
|
|
var entity_of_owner_entity_type = getEntityOfOwnerEntityType();
|
|
NullReferenceCheckHelper.throwIfNull(entity_of_owner_entity_type, () => $"entity_of_owner_entity_type is null !!!");
|
|
|
|
var cloned = new CraftRecipeAttribute(getOwner(), entity_of_owner_entity_type);
|
|
cloned.CraftMetaId = CraftMetaId;
|
|
return cloned;
|
|
}
|
|
|
|
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
|
{
|
|
return new RecipeAttributeTransactor(getOwner());
|
|
}
|
|
|
|
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
|
{
|
|
var result = new Result();
|
|
|
|
var acoount_attribute = getOwner().getRootParent().getEntityAttribute<AccountAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(acoount_attribute, () => $"acoount_attribute is null !!!");
|
|
|
|
USER_GUID user_guid = acoount_attribute.UserGuid;
|
|
|
|
//=====================================================================================
|
|
// Attribute => try pending Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = getTryPendingDocBase() as CraftRecipeDoc;
|
|
if (null == try_pending_doc)
|
|
{
|
|
var to_copy_doc = new CraftRecipeDoc(user_guid, CraftMetaId);
|
|
|
|
var origin_doc = getOriginDocBase<CraftRecipeAttribute>();
|
|
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<CraftRecipeAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(to_copy_doc_attrib, () => $"to_copy_doc_attrib is null !!!");
|
|
|
|
to_copy_doc_attrib.CraftMetaId = CraftMetaId;
|
|
|
|
if (false == isForQuery)
|
|
{
|
|
return (result, try_pending_doc);
|
|
}
|
|
|
|
//=====================================================================================
|
|
// Doc QueryType 반영
|
|
//=====================================================================================
|
|
(result, var to_query_docs) = await applyDoc4Query(try_pending_doc);
|
|
if (result.isFail())
|
|
{
|
|
return (result, to_query_docs);
|
|
}
|
|
|
|
return (result, to_query_docs);
|
|
}
|
|
|
|
public bool copyEntityAttributeFromDoc(DynamoDbDocBase docBase)
|
|
{
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
var to_cast_string = typeof(CraftRecipeDoc).Name;
|
|
|
|
var recipe_doc_base = docBase as CraftRecipeDoc;
|
|
if (null == recipe_doc_base)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, recipe_doc_base is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
//=====================================================================================
|
|
// New Doc => Origin Doc
|
|
//=====================================================================================
|
|
syncOriginDocBaseWithNewDoc<CraftRecipeAttribute>(recipe_doc_base);
|
|
|
|
//=====================================================================================
|
|
// Doc => Attribute
|
|
//=====================================================================================
|
|
var doc_attrib = recipe_doc_base.getAttrib<CraftRecipeAttrib>();
|
|
if (doc_attrib == null)
|
|
{
|
|
err_msg = $"Failed to get craft recipe attrib : {nameof(CraftRecipeAttrib)}";
|
|
result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg);
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
CraftMetaId = doc_attrib.CraftMetaId;
|
|
|
|
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 recipe_attribute = otherEntityAttribute as CraftRecipeAttribute;
|
|
if (null == recipe_attribute)
|
|
{
|
|
err_msg = $"Failed to cast RecipeAttribute !!!, recipe_attribute is null";
|
|
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
CraftMetaId = recipe_attribute.CraftMetaId;
|
|
|
|
//=====================================================================================
|
|
// Attribute Try Pending Doc => Origin Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = recipe_attribute.getTryPendingDocBase() as CraftRecipeDoc;
|
|
if (null != try_pending_doc)
|
|
{
|
|
recipe_attribute.resetTryPendingDocBase();
|
|
|
|
syncOriginDocBaseWithNewDoc<CraftRecipeAttribute>(try_pending_doc);
|
|
}
|
|
|
|
var origin_doc_base = getOriginDocBase<CraftRecipeAttribute>();
|
|
if (null == origin_doc_base)
|
|
{
|
|
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
|
return result;
|
|
}
|
|
|
|
var craft_recipe_attrib = origin_doc_base.getAttrib<CraftRecipeAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(craft_recipe_attrib, () => $"craft_recipe_attrib is null !!! - {owner.toBasicString()}");
|
|
|
|
craft_recipe_attrib.CraftMetaId = CraftMetaId;
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public class RecipeAttributeTransactor : EntityAttributeTransactorBase<CraftRecipeAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
|
|
{
|
|
public RecipeAttributeTransactor(EntityBase owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
|
|
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
|
|
{
|
|
var err_msg = string.Empty;
|
|
|
|
var to_cast_string = typeof(CraftRecipeAttribute).Name;
|
|
|
|
var copy_from_recipe_attribute = entityAttributeBase as CraftRecipeAttribute;
|
|
if (null == copy_from_recipe_attribute)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_from_recipe_attribute is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
var copy_to_recipe_attribute = getClonedEntityAttribute() as CraftRecipeAttribute;
|
|
if (null == copy_to_recipe_attribute)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_to_recipe_attribute is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
copy_to_recipe_attribute.CraftMetaId = copy_from_recipe_attribute.CraftMetaId;
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|