Files
2025-05-01 07:20:41 +09:00

256 lines
9.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Amazon.OpenSearchService.Model.Internal.MarshallTransformations;
using Google.Protobuf.WellKnownTypes;
using Newtonsoft.Json;
using ServerControlCenter;
using ServerCore; using ServerBase;
using System.Collections.Concurrent;
using USER_GUID = System.String;
using Amazon.S3.Model;
namespace ServerCommon
{
public class FriendAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
{
[JsonProperty]
public USER_GUID UserGuid { get; set; } = string.Empty;
[JsonProperty]
public USER_GUID FriendGuid { get; set; } = string.Empty;
[JsonProperty]
public string Nickname { get; set; } = string.Empty;
public string FolderName { get; set; } = string.Empty;
public Int32 IsNew { get; set; } = 0;
[JsonProperty]
public DateTime CreateTime { get; set; } = DateTimeHelper.MinTime;
public Int16 IsChannel { get; set; } = 0; //1:채널서버, 0:인스턴스 서버
public Int32 Id { get; set; } = 0;
public Int32 ChannelNumber { get; set; } = 0;
public Int32 Language { get; set; } = 0;
public FriendAttribute( EntityBase owner
, string userGuid, EntityBase entityOfOwnerEntityType)
: base(owner, entityOfOwnerEntityType)
{
UserGuid = userGuid;
}
public override void onClear()
{
UserGuid = string.Empty;
FriendGuid = string.Empty;
Nickname = string.Empty;
FolderName = string.Empty;
IsNew = 0;
CreateTime = new();
IsChannel = 0;
Id = 0;
ChannelNumber = 0;
Language = 0;
getAttributeState().reset();
}
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
{
var owner = getOwner();
var result = new Result();
var user_guid = UserGuid;
//=====================================================================================
// Attribute => try pending Doc
//=====================================================================================
var try_pending_doc = getTryPendingDocBase() as FriendDoc;
if (null == try_pending_doc)
{
var to_copy_doc = new FriendDoc(user_guid, FriendGuid);
var origin_doc = getOriginDocBase<FriendAttribute>();
if (null != origin_doc)
{
to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc);
}
try_pending_doc = to_copy_doc;
setTryPendingDocBase(try_pending_doc);
}
var to_copy_friend_attrib = try_pending_doc.getAttrib<FriendAttrib>();
NullReferenceCheckHelper.throwIfNull(to_copy_friend_attrib, () => $"to_copy_friend_attrib is null !!!");
to_copy_friend_attrib.FriendGuid = FriendGuid;
to_copy_friend_attrib.FolderName = FolderName;
to_copy_friend_attrib.IsNew = IsNew;
to_copy_friend_attrib.CreateTime = CreateTime;
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 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 FriendAttribute(owner, UserGuid, entity_of_owner_entity_type);
cloned.deepCopyFromBase(this);
cloned.FriendGuid = FriendGuid;
cloned.Nickname = Nickname;
cloned.FolderName = FolderName;
cloned.IsNew = IsNew;
cloned.CreateTime = CreateTime;
cloned.IsChannel = IsChannel;
cloned.Id = Id;
cloned.ChannelNumber = ChannelNumber;
cloned.Language = Language;
return cloned;
}
public Result onMerge(EntityAttributeBase otherEntityAttribute)
{
var owner = getOwner();
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
var result = new Result();
var other_attribute = otherEntityAttribute as FriendAttribute;
if (null == other_attribute)
{
var err_msg = $"Failed to cast FriendFolderAttribute !!!, other_attribute is null";
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
//=====================================================================================
// OtherAttribute => Attribute
//=====================================================================================
UserGuid = other_attribute.UserGuid;
FriendGuid = other_attribute.FriendGuid;
FolderName = other_attribute.FolderName;
Nickname = other_attribute.Nickname;
IsNew = other_attribute.IsNew;
CreateTime = other_attribute.CreateTime;
IsChannel = other_attribute.IsChannel;
Id = other_attribute.Id;
ChannelNumber = other_attribute.ChannelNumber;
Language = other_attribute.Language;
//=====================================================================================
// Attribute Try Pending Doc => Origin Doc
//=====================================================================================
var try_pending_doc = other_attribute.getTryPendingDocBase() as FriendDoc;
if (null != try_pending_doc)
{
other_attribute.resetTryPendingDocBase();
syncOriginDocBaseWithNewDoc<FriendAttribute>(try_pending_doc);
}
var origin_doc_base = getOriginDocBase<FriendAttribute>();
if (null == origin_doc_base)
{
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
return result;
}
var friend_attrib = origin_doc_base.getAttrib<FriendAttrib>();
NullReferenceCheckHelper.throwIfNull(friend_attrib, () => $"friend_attrib is null !!! - {owner.toBasicString()}");
return result;
}
public bool copyEntityAttributeFromDoc(DynamoDbDocBase? docBase)
{
var friend_doc_base = docBase as FriendDoc;
if (null == friend_doc_base)
{
var to_cast_string = typeof(FriendDoc).Name;
var err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, friend_doc_base is null :{to_cast_string}";
Log.getLogger().error(err_msg);
return false;
}
//=====================================================================================
// New Doc => Origin Doc
//=====================================================================================
syncOriginDocBaseWithNewDoc<FriendAttribute>(friend_doc_base);
//=====================================================================================
// Doc => Attribute
//=====================================================================================
var doc_attrib = friend_doc_base.getAttrib<FriendAttrib>();
NullReferenceCheckHelper.throwIfNull(doc_attrib, () => $"doc_attrib is null !!!");
FriendGuid = doc_attrib.FriendGuid;
FolderName = doc_attrib.FolderName;
IsNew = doc_attrib.IsNew;
CreateTime = doc_attrib.CreateTime;
return true;
}
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
{
return new FriendsAttributeTransactor(getOwner());
}
}
public class FriendsAttributeTransactor : EntityAttributeTransactorBase<FriendAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
{
public FriendsAttributeTransactor(EntityBase owner)
: base(owner)
{
}
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase entityAttributeBase)
{
//아직 미사용
Log.getLogger().info("copyEntityDbTransactBaseFromEntityAttribute call");
return true;
}
}
}