272 lines
11 KiB
C#
272 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Runtime.InteropServices;
|
|
using System.Collections.Concurrent;
|
|
using System.Xml.Linq;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
using Microsoft.AspNetCore.DataProtection.KeyManagement;
|
|
|
|
|
|
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 UI_KEY = System.String;
|
|
using DATA_KEY = System.String;
|
|
|
|
|
|
|
|
namespace ServerCommon
|
|
{
|
|
//=============================================================================================
|
|
//
|
|
// 클라이언트 UI 전용 DB 저장 정보
|
|
//
|
|
// - 서버측에서 로직 관여 하지 않는다. (읽기, 쓰기 only)
|
|
// - 추후 String 타입으로 하나의 변수로 저장 하도록 수정 한다. (전용 패킷 추가, 클라이언트와 협의)
|
|
//
|
|
//=============================================================================================
|
|
|
|
public class CustomDefinedUiAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
|
{
|
|
public UI_KEY UiKey { get; set; } = string.Empty;
|
|
public string CustomDefinedUi { get; set; } = string.Empty;
|
|
|
|
|
|
public CustomDefinedUiAttribute(EntityBase owner, EntityBase entityOfOwnerEntityType)
|
|
: base(owner, entityOfOwnerEntityType)
|
|
{
|
|
}
|
|
|
|
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
|
{
|
|
return new CustomDefinedUiAttributeTransactor(getOwner().getRootParent());
|
|
}
|
|
|
|
public override void onClear()
|
|
{
|
|
UiKey = string.Empty;
|
|
CustomDefinedUi = string.Empty;
|
|
|
|
getAttributeState().reset();
|
|
}
|
|
|
|
public override EntityAttributeBase onCloned()
|
|
{
|
|
var owner = getOwner();
|
|
|
|
var entity_of_owner_entity_type = getEntityOfOwnerEntityType();
|
|
NullReferenceCheckHelper.throwIfNull(entity_of_owner_entity_type, () => $"entity_of_owner_entity_type is null !!!");
|
|
|
|
var cloned = new CustomDefinedUiAttribute(owner, entity_of_owner_entity_type);
|
|
|
|
cloned.deepCopyFromBase(this);
|
|
|
|
cloned.UiKey = UiKey;
|
|
cloned.CustomDefinedUi = CustomDefinedUi;
|
|
|
|
return cloned;
|
|
}
|
|
|
|
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
|
{
|
|
var owner = getOwner();
|
|
var parent = owner.getRootParent();
|
|
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
if (false == parent.isValidOwnerEntityType())
|
|
{
|
|
err_msg = $"Invalid OwnerEntityType Invalid !!! - {parent.toBasicString()}";
|
|
result.setFail(ServerErrorCode.OwnerEntityTypeInvalid, err_msg);
|
|
Log.getLogger().error(err_msg);
|
|
|
|
return (result, null);
|
|
}
|
|
|
|
//=====================================================================================
|
|
// Attribute => try pending Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = getTryPendingDocBase() as CustomDefinedUiDoc;
|
|
if (null == try_pending_doc)
|
|
{
|
|
var to_copy_doc = new CustomDefinedUiDoc( parent.getEntityType().toOwnerEntityType(), parent.onGetDbGuid()
|
|
, UiKey);
|
|
|
|
var origin_doc = getOriginDocBase<CustomDefinedUiAttribute>();
|
|
if (null != origin_doc)
|
|
{
|
|
to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc);
|
|
}
|
|
|
|
try_pending_doc = to_copy_doc;
|
|
|
|
setTryPendingDocBase(try_pending_doc);
|
|
}
|
|
|
|
var to_copy_doc_custom_defined_ui_attrib = try_pending_doc.getAttrib<CustomDefinedUiAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(to_copy_doc_custom_defined_ui_attrib, () => $"to_copy_doc_custom_defined_ui_attrib is null !!! - {owner.toBasicString()}");
|
|
|
|
to_copy_doc_custom_defined_ui_attrib.CustomDefinedUi = CustomDefinedUi;
|
|
|
|
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 owner = getOwner();
|
|
var parent = owner.getRootParent();
|
|
|
|
var err_msg = string.Empty;
|
|
|
|
var to_cast_string = typeof(CustomDefinedUiDoc).Name;
|
|
|
|
var custom_defined_ui_doc = docBase as CustomDefinedUiDoc;
|
|
if (null == custom_defined_ui_doc)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, custom_defined_ui_doc is null :{to_cast_string} - {owner.toBasicString()}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
//=====================================================================================
|
|
// New Doc => Origin Doc
|
|
//=====================================================================================
|
|
syncOriginDocBaseWithNewDoc<CustomDefinedUiAttribute>(custom_defined_ui_doc);
|
|
|
|
//=====================================================================================
|
|
// Doc => Attribute
|
|
//=====================================================================================
|
|
var doc_custom_defined_ui_attrib = custom_defined_ui_doc.getAttrib<CustomDefinedUiAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(doc_custom_defined_ui_attrib, () => $"doc_custom_defined_ui_attrib is null !!! - {owner.toBasicString()}");
|
|
|
|
UiKey = doc_custom_defined_ui_attrib.UiKey;
|
|
CustomDefinedUi = doc_custom_defined_ui_attrib.CustomDefinedUi;
|
|
|
|
return true;
|
|
}
|
|
|
|
public Result onMerge(EntityAttributeBase otherEntityAttribute)
|
|
{
|
|
var owner = getOwner();
|
|
var parent = owner.getRootParent();
|
|
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
if (null == otherEntityAttribute)
|
|
{
|
|
err_msg = $"Invalid Param !!!, otherEntityAttribute is null - {parent.toBasicString()}";
|
|
result.setFail(ServerErrorCode.FunctionParamNull, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
//=====================================================================================
|
|
// OtherAttribute => Attribute
|
|
//=====================================================================================
|
|
var custom_defined_ui_attribute = otherEntityAttribute as CustomDefinedUiAttribute;
|
|
if (null == custom_defined_ui_attribute)
|
|
{
|
|
err_msg = $"Failed to cast CustomDefinedUISaveAttribute !!!, custom_defined_ui_attribute is null - {parent.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
CustomDefinedUi = custom_defined_ui_attribute.CustomDefinedUi;
|
|
|
|
//=====================================================================================
|
|
// Attribute Try Pending Doc => Origin Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = custom_defined_ui_attribute.getTryPendingDocBase() as CustomDefinedUiDoc;
|
|
if (null != try_pending_doc)
|
|
{
|
|
custom_defined_ui_attribute.resetTryPendingDocBase();
|
|
|
|
syncOriginDocBaseWithNewDoc<CustomDefinedUiAttribute>(try_pending_doc);
|
|
}
|
|
|
|
var origin_doc_base = getOriginDocBase<CustomDefinedUiAttribute>();
|
|
if (null == origin_doc_base)
|
|
{
|
|
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
|
return result;
|
|
}
|
|
|
|
var custom_defined_ui_attrib = origin_doc_base.getAttrib<CustomDefinedUiAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(custom_defined_ui_attrib, () => $"custom_defined_ui_attrib is null !!! - {owner.toBasicString()}");
|
|
|
|
custom_defined_ui_attrib.CustomDefinedUi = CustomDefinedUi;
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public class CustomDefinedUiAttributeTransactor : EntityAttributeTransactorBase<CustomDefinedUiAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
|
|
{
|
|
public CustomDefinedUiAttributeTransactor(EntityBase owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
|
|
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
|
|
{
|
|
var err_msg = string.Empty;
|
|
|
|
var to_cast_string = typeof(CustomDefinedUiAttribute).Name;
|
|
|
|
var copy_from_custom_defined_ui_attribute = entityAttributeBase as CustomDefinedUiAttribute;
|
|
if (null == copy_from_custom_defined_ui_attribute)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeTransactorBaseFromEntityAttribute() !!!, copy_from_custom_defined_ui_attribute is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
var copy_to_custom_defined_ui_attribute = getClonedEntityAttribute() as CustomDefinedUiAttribute;
|
|
if (null == copy_to_custom_defined_ui_attribute)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeTransactorBaseFromEntityAttribute() !!!, copy_to_custom_defined_ui_attribute is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
copy_to_custom_defined_ui_attribute.UiKey = copy_from_custom_defined_ui_attribute.UiKey;
|
|
copy_to_custom_defined_ui_attribute.CustomDefinedUi = copy_from_custom_defined_ui_attribute.CustomDefinedUi;
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|