초기커밋
This commit is contained in:
262
ServerCommon/Entity/Attribute/LandAttribute.cs
Normal file
262
ServerCommon/Entity/Attribute/LandAttribute.cs
Normal file
@@ -0,0 +1,262 @@
|
||||
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 class LandAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
||||
{
|
||||
[JsonProperty]
|
||||
public string OwnerUserGuid { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public META_ID LandMetaId { get; set; } = 0;
|
||||
|
||||
[JsonProperty]
|
||||
public string LandName { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
public bool IsLoadFromDb = false;
|
||||
|
||||
public LandAttribute(EntityBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
||||
{
|
||||
return new LandAttributeTransactor(getOwner());
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
LandMetaId = 0;
|
||||
LandName = string.Empty;
|
||||
Description = string.Empty;
|
||||
OwnerUserGuid = string.Empty;
|
||||
IsLoadFromDb = false;
|
||||
|
||||
getAttributeState().reset();
|
||||
}
|
||||
|
||||
public override EntityAttributeBase onCloned()
|
||||
{
|
||||
var cloned = new LandAttribute(getOwner());
|
||||
|
||||
cloned.deepCopyFromBase(this);
|
||||
|
||||
cloned.LandMetaId = LandMetaId;
|
||||
cloned.LandName = LandName;
|
||||
cloned.Description = Description;
|
||||
cloned.OwnerUserGuid = OwnerUserGuid;
|
||||
cloned.IsLoadFromDb = IsLoadFromDb;
|
||||
|
||||
return cloned;
|
||||
}
|
||||
|
||||
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => "owner is null !!!");
|
||||
|
||||
//=====================================================================================
|
||||
// Attribute => try pending Doc
|
||||
//=====================================================================================
|
||||
var try_pending_doc = getTryPendingDocBase() as LandDoc;
|
||||
if (null == try_pending_doc)
|
||||
{
|
||||
var to_copy_doc = new LandDoc(LandMetaId);
|
||||
|
||||
var origin_doc = getOriginDocBase<LandAttribute>();
|
||||
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<LandAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(to_copy_doc_attrib, () => $"to_copy_doc_attrib is null !!! - {owner.toBasicString()}");
|
||||
|
||||
to_copy_doc_attrib.LandMetaId = LandMetaId;
|
||||
to_copy_doc_attrib.LandName = LandName;
|
||||
to_copy_doc_attrib.Description = Description;
|
||||
to_copy_doc_attrib.OwnerUserGuid = OwnerUserGuid;
|
||||
|
||||
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(LandDoc).Name;
|
||||
|
||||
var land_doc_base = docBase as LandDoc;
|
||||
if (null == land_doc_base)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, land_doc_base is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// New Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
syncOriginDocBaseWithNewDoc<LandAttribute>(land_doc_base);
|
||||
|
||||
//=====================================================================================
|
||||
// Doc => Attribute
|
||||
//=====================================================================================
|
||||
var doc_attrib = land_doc_base.getAttrib<LandAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(doc_attrib, () => "doc_attrib is null !!!");
|
||||
|
||||
LandMetaId = doc_attrib.LandMetaId;
|
||||
LandName = doc_attrib.LandName;
|
||||
Description = doc_attrib.Description;
|
||||
OwnerUserGuid = doc_attrib.OwnerUserGuid;
|
||||
IsLoadFromDb = true;
|
||||
|
||||
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 land_attribute = otherEntityAttribute as LandAttribute;
|
||||
if (null == land_attribute)
|
||||
{
|
||||
err_msg = $"Failed to cast LandAttribute !!!, land_attribute is null";
|
||||
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
LandMetaId = land_attribute.LandMetaId;
|
||||
LandName = land_attribute.LandName;
|
||||
Description = land_attribute.Description;
|
||||
OwnerUserGuid = land_attribute.OwnerUserGuid;
|
||||
IsLoadFromDb = land_attribute.IsLoadFromDb;
|
||||
|
||||
//=====================================================================================
|
||||
// Attribute Try Pending Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
var try_pending_doc = land_attribute.getTryPendingDocBase() as LandDoc;
|
||||
if (null != try_pending_doc)
|
||||
{
|
||||
land_attribute.resetTryPendingDocBase();
|
||||
|
||||
syncOriginDocBaseWithNewDoc<LandAttribute>(try_pending_doc);
|
||||
}
|
||||
|
||||
var origin_doc_base = getOriginDocBase<LandAttribute>();
|
||||
if (null == origin_doc_base)
|
||||
{
|
||||
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
||||
return result;
|
||||
}
|
||||
|
||||
var land_attrib = origin_doc_base.getAttrib<LandAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(land_attrib, () => $"land_attrib is null !!! - {owner.toBasicString()}");
|
||||
|
||||
land_attrib.LandMetaId = LandMetaId;
|
||||
land_attrib.LandName = LandName;
|
||||
land_attrib.Description = Description;
|
||||
land_attrib.OwnerUserGuid = OwnerUserGuid;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class LandAttributeTransactor : EntityAttributeTransactorBase<LandAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
|
||||
{
|
||||
public LandAttributeTransactor(EntityBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
|
||||
{
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var to_cast_string = typeof(LandAttribute).Name;
|
||||
|
||||
var copy_from_land_attribute = entityAttributeBase as LandAttribute;
|
||||
if (null == copy_from_land_attribute)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeTransactorBaseFromEntityAttribute() !!!, copy_from_land_attribute is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
var copy_to_land_attribute = getClonedEntityAttribute() as LandAttribute;
|
||||
if (null == copy_to_land_attribute)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeTransactorBaseFromEntityAttribute() !!!, copy_to_land_attribute is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
copy_to_land_attribute.LandMetaId = copy_from_land_attribute.LandMetaId;
|
||||
copy_to_land_attribute.LandName = copy_from_land_attribute.LandName;
|
||||
copy_to_land_attribute.Description = copy_from_land_attribute.Description;
|
||||
copy_to_land_attribute.OwnerUserGuid = copy_from_land_attribute.OwnerUserGuid;
|
||||
copy_to_land_attribute.IsLoadFromDb = copy_from_land_attribute.IsLoadFromDb;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user