Add beam shear analysis converting from DTO
This commit is contained in:
@@ -1,64 +1,34 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Analyses;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperLogic.Models.Analyses;
|
||||
using StructureHelperLogics.Models.Analyses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs.Converters
|
||||
{
|
||||
public class CrossSectionNdmAnalysisFromDTOConvertStrategy : IConvertStrategy<ICrossSectionNdmAnalysis, ICrossSectionNdmAnalysis>
|
||||
public class CrossSectionNdmAnalysisFromDTOConvertStrategy : ConvertStrategy<ICrossSectionNdmAnalysis, ICrossSectionNdmAnalysis>
|
||||
{
|
||||
private IUpdateStrategy<ICrossSectionNdmAnalysis> updateStrategy;
|
||||
|
||||
public CrossSectionNdmAnalysisFromDTOConvertStrategy(IUpdateStrategy<ICrossSectionNdmAnalysis> updateStrategy)
|
||||
public CrossSectionNdmAnalysisFromDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
|
||||
{
|
||||
this.updateStrategy = updateStrategy;
|
||||
}
|
||||
|
||||
public CrossSectionNdmAnalysisFromDTOConvertStrategy() : this(new CrossSectionNdmAnalysisUpdateStrategy())
|
||||
public override ICrossSectionNdmAnalysis GetNewItem(ICrossSectionNdmAnalysis source)
|
||||
{
|
||||
|
||||
ChildClass = this;
|
||||
GetAnalysis(source);
|
||||
return NewItem;
|
||||
}
|
||||
|
||||
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
||||
public IShiftTraceLogger TraceLogger { get; set; }
|
||||
|
||||
public ICrossSectionNdmAnalysis Convert(ICrossSectionNdmAnalysis source)
|
||||
private void GetAnalysis(ICrossSectionNdmAnalysis source)
|
||||
{
|
||||
try
|
||||
{
|
||||
Check();
|
||||
ICrossSectionNdmAnalysis newItem = GetCrossSectionNDMAnalysis(source);
|
||||
return newItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
|
||||
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
|
||||
throw;
|
||||
}
|
||||
|
||||
TraceLogger?.AddMessage("Cross-section analysis converting has been started");
|
||||
updateStrategy ??= new CrossSectionNdmAnalysisUpdateStrategy();
|
||||
NewItem = new CrossSectionNdmAnalysis(source.Id);
|
||||
updateStrategy.Update(NewItem, source);
|
||||
TraceLogger?.AddMessage("Cross-section analysis has been finished successfully");
|
||||
}
|
||||
|
||||
private ICrossSectionNdmAnalysis GetCrossSectionNDMAnalysis(ICrossSectionNdmAnalysis source)
|
||||
{
|
||||
TraceLogger?.AddMessage("Cross-section sonverting is started");
|
||||
CrossSectionNdmAnalysis newItem = new(source.Id);
|
||||
updateStrategy.Update(newItem, source);
|
||||
TraceLogger?.AddMessage("Cross-section analysis was obtained successfully");
|
||||
return newItem;
|
||||
}
|
||||
|
||||
private void Check()
|
||||
{
|
||||
var checkLogic = new CheckConvertLogic<ICrossSectionNdmAnalysis, ICrossSectionNdmAnalysis>(this);
|
||||
checkLogic.Check();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Services;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs.Converters
|
||||
{
|
||||
public class HasPrimitivesFromDTOUpdateStrategy : IUpdateStrategy<IHasPrimitives>
|
||||
{
|
||||
private IConvertStrategy<INdmPrimitive, INdmPrimitive> convertStrategy;
|
||||
|
||||
public HasPrimitivesFromDTOUpdateStrategy(IConvertStrategy<INdmPrimitive, INdmPrimitive> convertStrategy)
|
||||
{
|
||||
this.convertStrategy = convertStrategy;
|
||||
}
|
||||
|
||||
public void Update(IHasPrimitives targetObject, IHasPrimitives sourceObject)
|
||||
{
|
||||
CheckObject.IsNull(targetObject, sourceObject);
|
||||
if (ReferenceEquals(targetObject, sourceObject)) { return; }
|
||||
targetObject.Primitives.Clear();
|
||||
foreach (var item in sourceObject.Primitives)
|
||||
{
|
||||
var newItem = convertStrategy.Convert(item);
|
||||
targetObject.Primitives.Add(newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
|
||||
namespace DataAccess.DTOs.Converters
|
||||
{
|
||||
public class HasPrimitivesProcessLogic : IHasPrimitivesProcessLogic
|
||||
{
|
||||
private const string convertStarted = " converting has been started";
|
||||
private const string convertFinished = " converting has been finished successfully";
|
||||
private ConvertDirection convertDirection;
|
||||
|
||||
public HasPrimitivesProcessLogic(ConvertDirection convertDirection)
|
||||
{
|
||||
this.convertDirection = convertDirection;
|
||||
}
|
||||
|
||||
public IHasPrimitives Source { get; set; }
|
||||
public IHasPrimitives Target { get; set; }
|
||||
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
||||
public IShiftTraceLogger TraceLogger { get; set; }
|
||||
|
||||
public void Process()
|
||||
{
|
||||
TraceLogger?.AddMessage("Primitives" + convertStarted);
|
||||
IUpdateStrategy<IHasPrimitives> updateStrategy = GetUpdateStrategyFactory();
|
||||
updateStrategy.Update(Target, Source);
|
||||
TraceLogger?.AddMessage($"Primitives {convertFinished}, totally {Target.Primitives.Count} have been obtained");
|
||||
}
|
||||
|
||||
private IUpdateStrategy<IHasPrimitives> GetUpdateStrategyFactory()
|
||||
{
|
||||
if (convertDirection == ConvertDirection.FromDTO)
|
||||
{
|
||||
NdmPrimitiveFromDTOConvertStrategy convertStrategy = new()
|
||||
{
|
||||
ReferenceDictionary = ReferenceDictionary,
|
||||
TraceLogger = TraceLogger
|
||||
};
|
||||
return GetUpdateStrategy(convertStrategy);
|
||||
}
|
||||
else if (convertDirection == ConvertDirection.ToDTO)
|
||||
{
|
||||
NdmPrimitiveToDTOConvertStrategy convertStrategy = new()
|
||||
{
|
||||
ReferenceDictionary = ReferenceDictionary,
|
||||
TraceLogger = TraceLogger
|
||||
};
|
||||
return GetUpdateStrategy(convertStrategy);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(convertDirection));
|
||||
}
|
||||
}
|
||||
|
||||
private IUpdateStrategy<IHasPrimitives> GetUpdateStrategy(IConvertStrategy<INdmPrimitive, INdmPrimitive> convertStrategy)
|
||||
{
|
||||
|
||||
DictionaryConvertStrategy<INdmPrimitive, INdmPrimitive> convertLogic = new()
|
||||
{
|
||||
ReferenceDictionary = ReferenceDictionary,
|
||||
TraceLogger = TraceLogger,
|
||||
ConvertStrategy = convertStrategy
|
||||
};
|
||||
HasPrimitivesFromDTOUpdateStrategy updateStrategy = new(convertLogic);
|
||||
return updateStrategy;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperLogics.Models.CrossSections;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs.Converters
|
||||
{
|
||||
public class HasPrimitivesToDTOUpdateStrategy : IUpdateStrategy<IHasPrimitives>
|
||||
{
|
||||
private IConvertStrategy<INdmPrimitive, INdmPrimitive> convertStrategy;
|
||||
|
||||
public HasPrimitivesToDTOUpdateStrategy(IConvertStrategy<INdmPrimitive, INdmPrimitive> primitiveConvertStrategy)
|
||||
{
|
||||
this.convertStrategy = primitiveConvertStrategy;
|
||||
}
|
||||
|
||||
public HasPrimitivesToDTOUpdateStrategy() : this(new NdmPrimitiveToDTOConvertStrategy())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
||||
public IShiftTraceLogger TraceLogger { get; set; }
|
||||
|
||||
public void Update(IHasPrimitives targetObject, IHasPrimitives sourceObject)
|
||||
{
|
||||
if (sourceObject.Primitives is null)
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.ParameterIsNull);
|
||||
}
|
||||
targetObject.Primitives.Clear();
|
||||
ProcessPrimitives(targetObject, sourceObject);
|
||||
}
|
||||
|
||||
private void ProcessPrimitives(IHasPrimitives targetObject, IHasPrimitives sourceObject)
|
||||
{
|
||||
convertStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||
convertStrategy.TraceLogger = TraceLogger;
|
||||
foreach (var item in sourceObject.Primitives)
|
||||
{
|
||||
INdmPrimitive primtiveDTO = convertStrategy.Convert(item);
|
||||
targetObject.Primitives.Add(primtiveDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperLogics.NdmCalculations.Cracking;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class UserCrackInputDataFromDTOConvertStrategy : ConvertStrategy<UserCrackInputData, UserCrackInputDataDTO>
|
||||
{
|
||||
private IUpdateStrategy<IUserCrackInputData> updateStrategy;
|
||||
|
||||
public UserCrackInputDataFromDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger)
|
||||
{
|
||||
ReferenceDictionary = referenceDictionary;
|
||||
TraceLogger = traceLogger;
|
||||
}
|
||||
|
||||
public override UserCrackInputData GetNewItem(UserCrackInputDataDTO source)
|
||||
{
|
||||
InitializeStrategies();
|
||||
try
|
||||
{
|
||||
GetNewItemBySource(source);
|
||||
return NewItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceErrorByEntity(this, ex.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void GetNewItemBySource(IUserCrackInputData source)
|
||||
{
|
||||
NewItem = new(source.Id);
|
||||
updateStrategy.Update(NewItem, source);
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
updateStrategy ??= new UserCrackInputDataUpdateStrategy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperLogics.NdmCalculations.Cracking;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class UserCrackInputDataToDTOConvertStrategy : ConvertStrategy<UserCrackInputDataDTO, IUserCrackInputData>
|
||||
{
|
||||
private IUpdateStrategy<IUserCrackInputData> updateStrategy;
|
||||
|
||||
public UserCrackInputDataToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger)
|
||||
{
|
||||
ReferenceDictionary = referenceDictionary;
|
||||
TraceLogger = traceLogger;
|
||||
}
|
||||
|
||||
public override UserCrackInputDataDTO GetNewItem(IUserCrackInputData source)
|
||||
{
|
||||
InitializeStrategies();
|
||||
try
|
||||
{
|
||||
GetNewItemBySource(source);
|
||||
return NewItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceErrorByEntity(this, ex.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void GetNewItemBySource(IUserCrackInputData source)
|
||||
{
|
||||
NewItem = new(source.Id);
|
||||
updateStrategy.Update(NewItem, source);
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
updateStrategy ??= new UserCrackInputDataUpdateStrategy();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user