83 lines
2.0 KiB
C#
83 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection.Metadata;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Serialization;
|
|
using Amazon.DynamoDBv2.DocumentModel;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
namespace ServerBase;
|
|
|
|
public abstract partial class AttribBase
|
|
{
|
|
// AttribType은 DynamoDb Document 정보를 Read시 식별키로 사용되기 때문에 고유하게 정의되어야 한다 !!! - kangms
|
|
[JsonProperty("attrib_type")]
|
|
public readonly string AttribType;
|
|
|
|
private readonly bool m_is_save_to_json_in_db = false;
|
|
|
|
public AttribBase(string attribType, bool isSaveToJsonInDb = true)
|
|
{
|
|
AttribType = attribType;
|
|
m_is_save_to_json_in_db = isSaveToJsonInDb;
|
|
}
|
|
|
|
public bool isSaveToJsonInDb() => m_is_save_to_json_in_db;
|
|
|
|
public virtual string toJsonString()
|
|
{
|
|
return JsonConvert.SerializeObject(this);
|
|
}
|
|
|
|
public virtual Amazon.DynamoDBv2.DocumentModel.Document toDocument()
|
|
{
|
|
return DynamoDbClientHelper.classToDynamoDbDocument(this);
|
|
}
|
|
public virtual string toBasicString()
|
|
{
|
|
return $"AttribType:{AttribType}, {toJsonString()}";
|
|
}
|
|
}
|
|
|
|
public partial class AttribWrapper<TAttrib> : IAttribWrapper
|
|
where TAttrib : AttribBase, new()
|
|
{
|
|
private TAttrib m_attrib = new();
|
|
|
|
public AttribWrapper()
|
|
{}
|
|
|
|
public bool onCopyFromDynamoDbEntry(Amazon.DynamoDBv2.DocumentModel.Document doc)
|
|
{
|
|
if(false == doc.fillupAttribObject<TAttrib>(out var fillup_attrib))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (fillup_attrib == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
m_attrib = fillup_attrib;
|
|
|
|
return true;
|
|
}
|
|
|
|
public bool onCopyToDynamoDbEntry(ref Amazon.DynamoDBv2.DocumentModel.Document doc)
|
|
{
|
|
return doc.setAttribObject<TAttrib>(m_attrib);
|
|
}
|
|
|
|
public bool onFillupJsonStringToJObject(ref JObject jobject)
|
|
{
|
|
return jobject.setAttribObjectWithJsonString<TAttrib>(m_attrib);
|
|
}
|
|
}
|