초기커밋

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,277 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using Amazon.Auth.AccessControlPolicy;
using Newtonsoft.Json;
using ServerCore; using ServerBase;
using USER_GUID = System.String;
using Amazon.S3.Model;
namespace ServerCommon
{
public class FriendFolderAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
{
[JsonProperty]
public Int16 m_folder_order_type { get; set; } = 0;
[JsonProperty]
public ConcurrentDictionary<string, FriendFolder> m_folders { get; set; } = new();
public FriendFolderAttribute(EntityBase owner)
: base(owner)
{
}
public override void onClear()
{
m_folder_order_type = 0;
m_folders.Clear();
getAttributeState().reset();
}
public void fillNewData()
{
FriendFolder folder = new();
folder.FolderName = Constant.FRIEND_FOLDER_DEFUALT_NAME;
folder.IsHold = 0;
folder.HoldTime = DateTimeHelper.Current;
folder.CreateTime = DateTimeHelper.Current;
m_folders.TryAdd(folder.FolderName, folder);
}
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
{
var owner = getOwner();
var result = new Result();
var user_attribute = owner.getEntityAttribute<UserAttribute>();
NullReferenceCheckHelper.throwIfNull(user_attribute, () => $"user_attribute is null !!!");
USER_GUID user_guid = user_attribute.UserGuid;
//=====================================================================================
// Attribute => try pending Doc
//=====================================================================================
var try_pending_doc = getTryPendingDocBase() as FriendFolderDoc;
if (null == try_pending_doc)
{
var to_copy_doc = new FriendFolderDoc(user_guid);
var origin_doc = getOriginDocBase<FriendFolderAttribute>();
if (null != origin_doc)
{
to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc);
}
try_pending_doc = to_copy_doc;
setTryPendingDocBase(try_pending_doc);
}
var to_copy_friend_folder_attrib = try_pending_doc.getAttrib<FriendFolderAttrib>();
NullReferenceCheckHelper.throwIfNull(to_copy_friend_folder_attrib, () => $"to_copy_friend_folder_attrib is null !!!");
to_copy_friend_folder_attrib.FolderOrderType = m_folder_order_type;
to_copy_friend_folder_attrib.Folders.Clear();
foreach (var folder in m_folders.Values)
{
FriendFolder copy_folder = new();
copy_folder.FolderName = folder.FolderName;
copy_folder.IsHold = folder.IsHold;
copy_folder.HoldTime = folder.HoldTime;
copy_folder.CreateTime = folder.CreateTime;
to_copy_friend_folder_attrib.Folders.TryAdd(copy_folder.FolderName, copy_folder);
}
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 override EntityAttributeBase onCloned()
{
var cloned = new FriendFolderAttribute(getOwner());
cloned.deepCopyFromBase(this);
cloned.m_folder_order_type = m_folder_order_type;
cloned.m_folders = new();
foreach (var folder in m_folders)
{
FriendFolder new_folder = new();
new_folder.FolderName = new (folder.Value.FolderName);
new_folder.IsHold = folder.Value.IsHold;
new_folder.HoldTime = folder.Value.HoldTime;
new_folder.CreateTime = folder.Value.CreateTime;
cloned.m_folders.TryAdd(folder.Key, new_folder);
}
return cloned;
}
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
{
return new FriendFolderAttributeTransactor(getOwner());
}
public bool copyEntityAttributeFromDoc(DynamoDbDocBase? docBase)
{
var result = new Result();
var err_msg = string.Empty;
var to_cast_string = typeof(FriendFolderDoc).Name;
var friend_folder_doc = docBase as FriendFolderDoc;
if (null == friend_folder_doc)
{
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, item_doc_base is null :{to_cast_string}";
Log.getLogger().error(err_msg);
return false;
}
//=====================================================================================
// New Doc => Origin Doc
//=====================================================================================
syncOriginDocBaseWithNewDoc<FriendFolderAttribute>(friend_folder_doc);
//=====================================================================================
// Doc => Attribute
//=====================================================================================
var friend_folder_attrib = friend_folder_doc.getAttrib<FriendFolderAttrib>();
NullReferenceCheckHelper.throwIfNull(friend_folder_attrib, () => $"friend_folder_attrib is null !!!");
m_folder_order_type = friend_folder_attrib.FolderOrderType;
m_folders = new();
foreach (var folder in friend_folder_attrib.Folders.Values)
{
var clone_folder = new FriendFolder();
clone_folder.FolderName = folder.FolderName;
clone_folder.IsHold = folder.IsHold;
clone_folder.HoldTime = folder.HoldTime;
clone_folder.CreateTime = folder.CreateTime;
m_folders.TryAdd(folder.FolderName, clone_folder);
}
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 other_attribute = otherEntityAttribute as FriendFolderAttribute;
if (null == other_attribute)
{
err_msg = $"Failed to cast FriendFolderAttribute !!!, other_attribute is null";
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
m_folder_order_type = other_attribute.m_folder_order_type;
foreach (var folder in other_attribute.m_folders.Values)
{
var clone_folder = new FriendFolder();
clone_folder.FolderName = folder.FolderName;
clone_folder.IsHold = folder.IsHold;
clone_folder.HoldTime = folder.HoldTime;
clone_folder.CreateTime = folder.CreateTime;
m_folders.TryAdd(folder.FolderName, clone_folder);
}
//=====================================================================================
// Attribute Try Pending Doc => Origin Doc
//=====================================================================================
var try_pending_doc = other_attribute.getTryPendingDocBase() as FriendFolderDoc;
if (null != try_pending_doc)
{
other_attribute.resetTryPendingDocBase();
syncOriginDocBaseWithNewDoc<FriendFolderAttribute>(try_pending_doc);
}
var origin_doc_base = getOriginDocBase<FriendFolderAttribute>();
if (null == origin_doc_base)
{
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
return result;
}
var friend_folder_attrib = origin_doc_base.getAttrib<FriendFolderAttrib>();
NullReferenceCheckHelper.throwIfNull(friend_folder_attrib, () => $"friend_folder_attrib is null !!! - {owner.toBasicString()}");
friend_folder_attrib.FolderOrderType = m_folder_order_type;
foreach (var folder in m_folders.Values)
{
var clone_folder = new FriendFolder();
clone_folder.FolderName = folder.FolderName;
clone_folder.IsHold = folder.IsHold;
clone_folder.HoldTime = folder.HoldTime;
clone_folder.CreateTime = folder.CreateTime;
friend_folder_attrib.Folders.TryAdd(folder.FolderName, clone_folder);
}
return result;
}
}
public class FriendFolderAttributeTransactor : EntityAttributeTransactorBase<FriendFolderAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
{
public FriendFolderAttributeTransactor(EntityBase owner)
: base(owner)
{
}
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
{
return true;
}
}
}