using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Amazon.Util.Internal; using Grpc.Core; using Microsoft.AspNetCore.Mvc.TagHelpers; using ServerCore; using ServerBase; namespace ServerBase; public static class DataCopyHelper { #region 데이터 복사 하기 : Doc => Cache public static async Task copyCacheFromDocs(TCacheType toCacheBase, List fromDocBases) where TCacheType : CacheBase { var result = new Result(); var err_msg = string.Empty; var to_copy = toCacheBase as ICopyCacheFromDoc; if (null == to_copy) { err_msg = $"Failed to cast ICopyCacheFromDoc !!! : {typeof(TCacheType).Name} !!!"; result.setFail(ServerErrorCode.ClassDoesNotImplementInterfaceInheritance, err_msg); Log.getLogger().error(result.toBasicString()); return result; } foreach (var doc in fromDocBases) { if (false == to_copy.copyCacheFromDoc(doc)) { err_msg = $"Failed to copyCacheFromDoc() !!!, to:{typeof(TCacheType).Name}, from:{doc.getTypeName()}"; result.setFail(ServerErrorCode.DynamoDbDocCopyToCacheFailed, err_msg); Log.getLogger().error(result.toBasicString()); return result; } } return await Task.FromResult(result); } #endregion #region 데이터 복사 하기 : Doc => EntityAttribute public static async Task copyEntityAttributeFromDocs(TEntityAttributeType toEntityAttributeBase, List fromDocBases) where TEntityAttributeType : EntityAttributeBase { await Task.CompletedTask; var result = new Result(); var err_msg = string.Empty; var to_copy = toEntityAttributeBase as ICopyEntityAttributeFromDoc; if (null == to_copy) { err_msg = $"Failed to cast ICopyEntityAttributeFromDoc !!! : {typeof(TEntityAttributeType).Name}"; result.setFail(ServerErrorCode.ClassDoesNotImplementInterfaceInheritance, err_msg); Log.getLogger().error(result.toBasicString()); return result; } foreach(var doc in fromDocBases) { if (false == to_copy.copyEntityAttributeFromDoc(doc)) { err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, to:{typeof(TEntityAttributeType).Name}, from:{doc.getTypeName()}"; result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg); Log.getLogger().error(result.toBasicString()); return result; } } return result; } #endregion #region 데이터 복사 하기 : Cache => EntityAttribute public static async Task copyEntityAttributeFromCaches(TEntityAttributeType toEntityAttribBase, List fromCacheBases) where TEntityAttributeType : EntityAttributeBase { var result = new Result(); var err_msg = string.Empty; var to_copy = toEntityAttribBase as ICopyEntityAttributeFromCache; if (null == to_copy) { err_msg = $"Failed to cast ICopyEntityAttributeFromCache !!! : {typeof(TEntityAttributeType).Name} !!!"; result.setFail(ServerErrorCode.ClassDoesNotImplementInterfaceInheritance, err_msg); Log.getLogger().error(result.toBasicString()); return result; } foreach (var cache in fromCacheBases) { if (false == to_copy.copyEntityAttributeFromCache(cache)) { err_msg = $"Failed to copyEntityAttributeFromCache() !!!, to:{typeof(TEntityAttributeType).Name}, from:{cache.getTypeName()}"; result.setFail(ServerErrorCode.CacheCopyToEntityAttributeFailed, err_msg); Log.getLogger().error(result.toBasicString()); return result; } } return await Task.FromResult(result); } #endregion #region 데이터 복사 하기 : Cache => Doc public static async Task copyDocFromCache(TDoc toDoc, List fromCacheBases) where TDoc : DynamoDbDocBase { var result = new Result(); var err_msg = string.Empty; var to_copy = toDoc as ICopyDocFromCache; if (null == to_copy) { err_msg = $"Failed to cast ICopyDocFromCache !!! : {typeof(TDoc).Name}"; result.setFail(ServerErrorCode.ClassDoesNotImplementInterfaceInheritance, err_msg); Log.getLogger().error(result.toBasicString()); return result; } foreach (var cache in fromCacheBases) { if (false == to_copy.copyDocFromCache(cache)) { err_msg = $"Failed to copyDocFromCache() !!!, to:{typeof(TDoc).Name}, from:{cache.getTypeName()}"; result.setFail(ServerErrorCode.CacheCopyToEntityAttributeFailed, err_msg); Log.getLogger().error(result.toBasicString()); return result; } } return await Task.FromResult(result); } #endregion #region 데이터 복사 하기 : EntityAttribute => Cache public static async Task copyCacheFromEntityAttributes(TCacheType toCacheBase, List fromEntityAttributeBases) where TCacheType : CacheBase { var result = new Result(); var err_msg = string.Empty; var to_copy = toCacheBase as ICopyCacheFromEntityAttribute; if (null == to_copy) { err_msg = $"Failed to cast ICopyCacheFromEntityAttribute !!! : {typeof(TCacheType).Name} !!!"; result.setFail(ServerErrorCode.ClassDoesNotImplementInterfaceInheritance, err_msg); Log.getLogger().error(result.toBasicString()); return result; } foreach(var attribute in fromEntityAttributeBases) { if (false == to_copy.copyCacheFromEntityAttribute(attribute)) { err_msg = $"Failed to copyCacheFromEntityAttributes() !!!, to:{typeof(TCacheType).Name}, from:{fromEntityAttributeBases.getTypeName()}"; result.setFail(ServerErrorCode.EntityAttributeCopyToCacheFailed, err_msg); Log.getLogger().error(result.toBasicString()); return result; } } return await Task.FromResult(result); } #endregion #region 데이터 복사 하기 : EntityAttribute => Doc public static async Task copyDocFromEntityAttributes(TDoc toDocBase, List fromEntityAttributeBases) where TDoc : DynamoDbDocBase { var result = new Result(); var err_msg = string.Empty; var to_copy = toDocBase as ICopyDocFromEntityAttribute; if (null == to_copy) { err_msg = $"Failed to cast ICopyDocFromEntityAttribute !!! : {fromEntityAttributeBases.getTypeName()}"; result.setFail(ServerErrorCode.ClassDoesNotImplementInterfaceInheritance, err_msg); Log.getLogger().error(result.toBasicString()); return result; } foreach (var entity_attribute in fromEntityAttributeBases) { if (false == to_copy.copyDocFromEntityAttribute(entity_attribute)) { err_msg = $"Failed to copyDocFromEntityAttribute() !!!, to:{typeof(TDoc).Name}, from:{fromEntityAttributeBases.getTypeName()}"; result.setFail(ServerErrorCode.EntityAttributeCopyToDynamoDbDocFailed, err_msg); Log.getLogger().error(result.toBasicString()); return result; } } return await Task.FromResult(result); } #endregion #region 데이터 복사 하기 : EntityAttribute => EntityAttributeTransactor public static async Task copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeTransactorBase toEntityAttributeTransactorBase, EntityAttributeBase fromEntityAttribute) where TEntityAttribute : EntityAttributeBase { var result = new Result(); var err_msg = string.Empty; var to_copy = toEntityAttributeTransactorBase as ICopyEntityAttributeTransactorFromEntityAttribute; if (null == to_copy) { err_msg = $"Failed to cast ICopyEntityAttributeTransactorBaseFromEntityAttribute !!! : {fromEntityAttribute.getTypeName()}"; result.setFail(ServerErrorCode.ClassDoesNotImplementInterfaceInheritance, err_msg); Log.getLogger().error(result.toBasicString()); return result; } if (false == to_copy.copyEntityAttributeTransactorFromEntityAttribute(fromEntityAttribute)) { err_msg = $"Failed to copyEntityAttributeTransactorBaseFromEntityAttribute() !!!, to:{toEntityAttributeTransactorBase.getTypeName()}, from:{fromEntityAttribute.getTypeName()}"; result.setFail(ServerErrorCode.EntityAttributeCopyToEntityAttributeTransactorFailed, err_msg); Log.getLogger().error(result.toBasicString()); return result; } return await Task.FromResult(result); } #endregion #region 데이터 복사 하기 : EntityAttributeTransactor => Doc public static async Task copyDocFromEntityAttributeTransactor(TDynamoDbDocBase toDoc, EntityAttributeTransactorBase fromEntityAttributeTransactorBase) where TDynamoDbDocBase : DynamoDbDocBase where TEntityAttribute : EntityAttributeBase { var result = new Result(); var err_msg = string.Empty; var to_copy = toDoc as ICopyDocFromEntityAttributeTransactor; if (null == to_copy) { err_msg = $"Failed to cast ICopyDocFromEntityAttributeTransactor !!! : {fromEntityAttributeTransactorBase.getTypeName()}"; result.setFail(ServerErrorCode.ClassDoesNotImplementInterfaceInheritance, err_msg); Log.getLogger().error(result.toBasicString()); return result; } if (false == to_copy.copyDocFromEntityAttributeTransactor(fromEntityAttributeTransactorBase)) { err_msg = $"Failed to copyDocFromEntityAttributeTransactor() !!!, to:{typeof(TDynamoDbDocBase).Name}, from:{fromEntityAttributeTransactorBase.getTypeName()}"; result.setFail(ServerErrorCode.EntityAttributeTransactorCopyToDynamoDbDocFailed, err_msg); Log.getLogger().error(result.toBasicString()); return result; } return await Task.FromResult(result); } #endregion }