Add beam shear converting to DTO
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Forces.BeamShearActions;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class ConcentratedForceToDTOConvertStrategy : ConvertStrategy<ConcentratedForceDTO, IConcentratedForce>
|
||||
{
|
||||
private IUpdateStrategy<IConcentratedForce> updateStrategy;
|
||||
private IConvertStrategy<ForceTupleDTO, IForceTuple> tupleConvertStrategy;
|
||||
private IConvertStrategy<FactoredCombinationPropertyDTO, IFactoredCombinationProperty> combinationConvertStrategy;
|
||||
|
||||
public ConcentratedForceToDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
|
||||
{
|
||||
}
|
||||
|
||||
public override ConcentratedForceDTO GetNewItem(IConcentratedForce source)
|
||||
{
|
||||
try
|
||||
{
|
||||
GetNewConcentratedForce(source);
|
||||
return NewItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceErrorByEntity(this, ex.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void GetNewConcentratedForce(IConcentratedForce source)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Concentrated force converting Id = {source.Id} has been started", TraceLogStatuses.Debug);
|
||||
InitializeStrategies();
|
||||
NewItem = new(source.Id);
|
||||
updateStrategy.Update(NewItem, source);
|
||||
NewItem.ForceValue = tupleConvertStrategy.Convert(source.ForceValue);
|
||||
NewItem.CombinationProperty = combinationConvertStrategy.Convert(source.CombinationProperty);
|
||||
TraceLogger?.AddMessage($"Concentrated force converting Id = {NewItem.Id} has been finished successfully", TraceLogStatuses.Debug);
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
updateStrategy ??= new ConcentratedForceUpdateStrategy();
|
||||
tupleConvertStrategy = new DictionaryConvertStrategy<ForceTupleDTO, IForceTuple>
|
||||
(this, new ForceTupleToDTOConvertStrategy(ReferenceDictionary, TraceLogger));
|
||||
combinationConvertStrategy = new DictionaryConvertStrategy<FactoredCombinationPropertyDTO, IFactoredCombinationProperty>
|
||||
(this, new FactoredCombinationPropertyToDTOConvertStrategy(ReferenceDictionary, TraceLogger));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Forces.BeamShearActions;
|
||||
|
||||
//Copyright (c) 2025 Redikultsev Evgeny, Ekaterinburg, Russia
|
||||
//All rights reserved.
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class DistributedLoadToDTOConvertStrategy : ConvertStrategy<DistributedLoadDTO, IDistributedLoad>
|
||||
{
|
||||
private IUpdateStrategy<IDistributedLoad> updateStrategy;
|
||||
private IConvertStrategy<ForceTupleDTO, IForceTuple> tupleConvertStrategy;
|
||||
private IConvertStrategy<FactoredCombinationPropertyDTO, IFactoredCombinationProperty> combinationConvertStrategy;
|
||||
|
||||
public DistributedLoadToDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
|
||||
{
|
||||
}
|
||||
|
||||
public override DistributedLoadDTO GetNewItem(IDistributedLoad source)
|
||||
{
|
||||
try
|
||||
{
|
||||
GetNewBeamAction(source);
|
||||
return NewItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceErrorByEntity(this, ex.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void GetNewBeamAction(IDistributedLoad source)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Converting of beam shear action Id = {source.Id} has been started", TraceLogStatuses.Debug);
|
||||
InitializeStrategies();
|
||||
NewItem = new(source.Id);
|
||||
updateStrategy.Update(NewItem, source);
|
||||
NewItem.LoadValue = tupleConvertStrategy.Convert(source.LoadValue);
|
||||
NewItem.CombinationProperty = combinationConvertStrategy.Convert(source.CombinationProperty);
|
||||
TraceLogger?.AddMessage($"Converting of beam shear action Id = {source.Id} has been finished", TraceLogStatuses.Debug);
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
updateStrategy ??= new DistributedLoadUpdateStrategy();
|
||||
tupleConvertStrategy = new DictionaryConvertStrategy<ForceTupleDTO, IForceTuple>
|
||||
(this, new ForceTupleToDTOConvertStrategy(ReferenceDictionary, TraceLogger));
|
||||
combinationConvertStrategy = new DictionaryConvertStrategy<FactoredCombinationPropertyDTO, IFactoredCombinationProperty>
|
||||
(this, new FactoredCombinationPropertyToDTOConvertStrategy(ReferenceDictionary, TraceLogger));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Forces.Logics;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class FactoredCombinationPropertyFromDTOConvertStrategy : ConvertStrategy<FactoredCombinationProperty, FactoredCombinationPropertyDTO>
|
||||
{
|
||||
private IUpdateStrategy<IFactoredCombinationProperty> updateStrategy;
|
||||
public override FactoredCombinationProperty GetNewItem(FactoredCombinationPropertyDTO source)
|
||||
{
|
||||
InitializeStrategies();
|
||||
TraceLogger.AddMessage($"Force factored combination property Id={source.Id} converting has been started");
|
||||
FactoredCombinationProperty newItem = new(source.Id);
|
||||
updateStrategy.Update(newItem, source);
|
||||
TraceLogger.AddMessage($"Force factored combination property Id={newItem.Id} converting has been finished");
|
||||
return newItem;
|
||||
}
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
updateStrategy ??= new FactoredCombinationPropertyUpdateStrategy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Forces.Logics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class FactoredCombinationPropertyToDTOConvertStrategy : ConvertStrategy<FactoredCombinationPropertyDTO, IFactoredCombinationProperty>
|
||||
{
|
||||
private IUpdateStrategy<IFactoredCombinationProperty> updateStrategy;
|
||||
|
||||
public FactoredCombinationPropertyToDTOConvertStrategy(IUpdateStrategy<IFactoredCombinationProperty> updateStrategy)
|
||||
{
|
||||
this.updateStrategy = updateStrategy;
|
||||
}
|
||||
|
||||
public FactoredCombinationPropertyToDTOConvertStrategy()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public FactoredCombinationPropertyToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger)
|
||||
: base(referenceDictionary, traceLogger)
|
||||
{
|
||||
}
|
||||
|
||||
public override FactoredCombinationPropertyDTO GetNewItem(IFactoredCombinationProperty source)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Force factored combination property Id={source.Id} converting has been started");
|
||||
InitializeStrategies();
|
||||
FactoredCombinationPropertyDTO newItem = new(source.Id);
|
||||
updateStrategy.Update(newItem, source);
|
||||
TraceLogger?.AddMessage($"Force factored combination property Id={newItem.Id} converting has been finished");
|
||||
return newItem;
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
updateStrategy ??= new FactoredCombinationPropertyUpdateStrategy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class FactoredForceTupleToDTOConvertStrategy : ConvertStrategy<FactoredForceTupleDTO, IFactoredForceTuple>
|
||||
{
|
||||
private IConvertStrategy<ForceTupleDTO, IForceTuple> tupleConvertStrategy;
|
||||
private IConvertStrategy<FactoredCombinationPropertyDTO, IFactoredCombinationProperty> combinationConvertStrategy;
|
||||
|
||||
public FactoredForceTupleToDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
|
||||
{
|
||||
}
|
||||
|
||||
public override FactoredForceTupleDTO GetNewItem(IFactoredForceTuple source)
|
||||
{
|
||||
try
|
||||
{
|
||||
GetNewFactoredForceTuple(source);
|
||||
return NewItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceErrorByEntity(this, ex.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void GetNewFactoredForceTuple(IFactoredForceTuple source)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Converting of factored force tuple Id = {source.Id} has been started", TraceLogStatuses.Debug);
|
||||
InitializeStrategies();
|
||||
NewItem = new(source.Id);
|
||||
NewItem.ForceTuple = tupleConvertStrategy.Convert(source.ForceTuple);
|
||||
NewItem.CombinationProperty = combinationConvertStrategy.Convert(source.CombinationProperty);
|
||||
TraceLogger?.AddMessage($"Converting of factored force tuple Id = {NewItem.Id} has been finished", TraceLogStatuses.Debug);
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
tupleConvertStrategy = new DictionaryConvertStrategy<ForceTupleDTO, IForceTuple>
|
||||
(this, new ForceTupleToDTOConvertStrategy(ReferenceDictionary, TraceLogger));
|
||||
combinationConvertStrategy = new DictionaryConvertStrategy<FactoredCombinationPropertyDTO, IFactoredCombinationProperty>
|
||||
(this, new FactoredCombinationPropertyToDTOConvertStrategy(ReferenceDictionary, TraceLogger));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class ForceActionFromDTOConvertStrategy : ConvertStrategy<IForceAction, IForceAction>
|
||||
{
|
||||
private IConvertStrategy<ForceCombinationList, ForceCombinationListDTO> listConvertStrategy;
|
||||
private IConvertStrategy<ForceFactoredList, ForceCombinationByFactorV1_0DTO> factorConvertStrategy_v1_0;
|
||||
private IConvertStrategy<ForceFactoredList, ForceFactoredListDTO> factorConvertStrategy;
|
||||
private IConvertStrategy<ForceCombinationFromFile, ForceCombinationFromFileDTO> fileConvertStrategy;
|
||||
|
||||
public ForceActionFromDTOConvertStrategy(
|
||||
IConvertStrategy<ForceCombinationList, ForceCombinationListDTO> listConvertStrategy,
|
||||
IConvertStrategy<ForceFactoredList, ForceCombinationByFactorV1_0DTO> factorConvertStrategy_v1_0,
|
||||
IConvertStrategy<ForceFactoredList, ForceFactoredListDTO> factorConvertStrategy,
|
||||
IConvertStrategy<ForceCombinationFromFile, ForceCombinationFromFileDTO> fileConvertStrategy)
|
||||
{
|
||||
this.listConvertStrategy = listConvertStrategy;
|
||||
this.factorConvertStrategy_v1_0 = factorConvertStrategy_v1_0;
|
||||
this.factorConvertStrategy = factorConvertStrategy;
|
||||
this.fileConvertStrategy = fileConvertStrategy;
|
||||
}
|
||||
|
||||
public ForceActionFromDTOConvertStrategy() { }
|
||||
|
||||
public override IForceAction GetNewItem(IForceAction source)
|
||||
{
|
||||
InitializeStrategies();
|
||||
try
|
||||
{
|
||||
NewItem = GetNewItemBySource(source);
|
||||
return NewItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceErrorByEntity(this, ex.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
listConvertStrategy ??= new ForceCombinationListFromDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
factorConvertStrategy ??= new ForceFactoredListFromDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
fileConvertStrategy ??= new ForceCombinationFromFileFromDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
|
||||
}
|
||||
private IForceAction GetNewItemBySource(IForceAction source)
|
||||
{
|
||||
if (source is ForceFactoredListDTO combination)
|
||||
{
|
||||
return GetFactoredCombination(combination);
|
||||
}
|
||||
if (source is ForceCombinationListDTO forceList)
|
||||
{
|
||||
return GetForceList(forceList);
|
||||
}
|
||||
if (source is ForceCombinationFromFileDTO fileCombination)
|
||||
{
|
||||
return GetFileCombination(fileCombination);
|
||||
}
|
||||
if (source is ForceCombinationByFactorV1_0DTO combination_v1_0)
|
||||
{
|
||||
return Obsolete_GetForceCombination_V1_0(combination_v1_0);
|
||||
}
|
||||
string errorString = ErrorStrings.ObjectTypeIsUnknownObj(source);
|
||||
TraceLogger.AddMessage(errorString, TraceLogStatuses.Error);
|
||||
throw new StructureHelperException(errorString);
|
||||
}
|
||||
private ForceCombinationFromFile GetFileCombination(ForceCombinationFromFileDTO source)
|
||||
{
|
||||
TraceLogger?.AddMessage("Force action is combination by factors");
|
||||
ForceCombinationFromFile newItem = fileConvertStrategy.Convert(source);
|
||||
return newItem;
|
||||
}
|
||||
private ForceFactoredList Obsolete_GetForceCombination_V1_0(ForceCombinationByFactorV1_0DTO source)
|
||||
{
|
||||
TraceLogger?.AddMessage("Force action is combination by factors version 1.0 (obsolete)", TraceLogStatuses.Warning);
|
||||
factorConvertStrategy_v1_0 ??= new ForceCombinationByFactorV1_0FromDTOConvertStrategy()
|
||||
{
|
||||
ReferenceDictionary = ReferenceDictionary,
|
||||
TraceLogger = TraceLogger
|
||||
};
|
||||
ForceFactoredList newItem = factorConvertStrategy_v1_0.Convert(source);
|
||||
return newItem;
|
||||
}
|
||||
private IForceAction GetFactoredCombination(ForceFactoredListDTO source)
|
||||
{
|
||||
TraceLogger?.AddMessage("Force action is combination by factors");
|
||||
ForceFactoredList newItem = factorConvertStrategy.Convert(source);
|
||||
return newItem;
|
||||
}
|
||||
private IForceAction GetForceList(ForceCombinationListDTO forceList)
|
||||
{
|
||||
TraceLogger?.AddMessage("Force action is combination by list");
|
||||
ForceCombinationList newItem = listConvertStrategy.Convert(forceList);
|
||||
return newItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class ForceActionToDTOConvertStrategy : ConvertStrategy<IForceAction, IForceAction>
|
||||
{
|
||||
private IConvertStrategy<ForceFactoredListDTO, IForceFactoredList> forceFactoredListConvertStrategy;
|
||||
private IConvertStrategy<ForceCombinationListDTO, IForceCombinationList> forceCombinationListConvertStrategy;
|
||||
private IConvertStrategy<ForceCombinationFromFileDTO, IForceCombinationFromFile> forceCombinationFromFileConvertStrategy;
|
||||
|
||||
public ForceActionToDTOConvertStrategy(
|
||||
IConvertStrategy<ForceFactoredListDTO, IForceFactoredList> forceFactoredListConvertStrategy,
|
||||
IConvertStrategy<ForceCombinationListDTO, IForceCombinationList> forceCombinationListConvertStrategy,
|
||||
IConvertStrategy<ForceCombinationFromFileDTO, IForceCombinationFromFile> forceCombinationFromFileConvertStrategy)
|
||||
{
|
||||
this.forceFactoredListConvertStrategy = forceFactoredListConvertStrategy;
|
||||
this.forceCombinationListConvertStrategy = forceCombinationListConvertStrategy;
|
||||
this.forceCombinationFromFileConvertStrategy = forceCombinationFromFileConvertStrategy;
|
||||
}
|
||||
|
||||
public ForceActionToDTOConvertStrategy() { }
|
||||
|
||||
public override IForceAction GetNewItem(IForceAction source)
|
||||
{
|
||||
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Debug);
|
||||
TraceLogger?.AddMessage($"Force action converting has been started");
|
||||
InitializeStrategies();
|
||||
if (source is IForceFactoredList forceFactoredList)
|
||||
{
|
||||
return GetForceCombinationByFactor(forceFactoredList);
|
||||
}
|
||||
else if (source is IForceCombinationList forceCombinationList)
|
||||
{
|
||||
return GetForceCombinationList(forceCombinationList);
|
||||
}
|
||||
else if (source is IForceCombinationFromFile forceCombinationFile)
|
||||
{
|
||||
return GetForceCombinationFile(forceCombinationFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
string errorString = ErrorStrings.ObjectTypeIsUnknownObj(source);
|
||||
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
|
||||
throw new StructureHelperException(errorString);
|
||||
}
|
||||
}
|
||||
|
||||
private IForceAction GetForceCombinationFile(IForceCombinationFromFile forceCombinationFile)
|
||||
{
|
||||
var convertLogic = new DictionaryConvertStrategy<ForceCombinationFromFileDTO, IForceCombinationFromFile>(this, forceCombinationFromFileConvertStrategy);
|
||||
var forceCombination = convertLogic.Convert(forceCombinationFile);
|
||||
return forceCombination;
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
forceFactoredListConvertStrategy ??= new ForceFactoredListToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
|
||||
forceCombinationListConvertStrategy ??= new ForceCombinationListToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger }; ;
|
||||
forceCombinationFromFileConvertStrategy ??= new ForceCombinaionFromFileToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger }; ;
|
||||
}
|
||||
|
||||
private ForceCombinationListDTO GetForceCombinationList(IForceCombinationList forceCombinationList)
|
||||
{
|
||||
var convertLogic = new DictionaryConvertStrategy<ForceCombinationListDTO, IForceCombinationList>(this, forceCombinationListConvertStrategy);
|
||||
var forceCombination = convertLogic.Convert(forceCombinationList);
|
||||
return forceCombination;
|
||||
}
|
||||
|
||||
private ForceFactoredListDTO GetForceCombinationByFactor(IForceFactoredList forceCombinationByFactor)
|
||||
{
|
||||
var convertLogic = new DictionaryConvertStrategy<ForceFactoredListDTO, IForceFactoredList>(this, forceFactoredListConvertStrategy);
|
||||
var forceCombination = convertLogic.Convert(forceCombinationByFactor);
|
||||
return forceCombination;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class ForceCombinaionFromFileToDTOConvertStrategy : ConvertStrategy<ForceCombinationFromFileDTO, IForceCombinationFromFile>
|
||||
{
|
||||
|
||||
private IUpdateStrategy<IForceCombinationFromFile> updateStrategy;
|
||||
private IConvertStrategy<Point2DDTO, IPoint2D> pointConvertStrategy;
|
||||
private IConvertStrategy<FactoredCombinationPropertyDTO, IFactoredCombinationProperty> combinationPropertyConvertStrategy;
|
||||
private IConvertStrategy<ColumnedFilePropertyDTO, IColumnedFileProperty> filePropertyConvertStrategy;
|
||||
|
||||
|
||||
|
||||
public override ForceCombinationFromFileDTO GetNewItem(IForceCombinationFromFile source)
|
||||
{
|
||||
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Debug);
|
||||
TraceLogger.AddMessage($"Force combination from file, name = {source.Name} converting has been started");
|
||||
InitializeStrategies();
|
||||
ForceCombinationFromFileDTO newItem = new(source.Id);
|
||||
updateStrategy.Update(newItem, source);
|
||||
newItem.ForceFiles.Clear();
|
||||
foreach (var item in source.ForceFiles)
|
||||
{
|
||||
ColumnedFilePropertyDTO columnedFilePropertyDTO = filePropertyConvertStrategy.Convert(item);
|
||||
newItem.ForceFiles.Add(columnedFilePropertyDTO);
|
||||
}
|
||||
SetPoint(source, newItem);
|
||||
SetCombinationProperty(source, newItem);
|
||||
TraceLogger.AddMessage($"Force combination from file, name = {source.Name} converting has been finished successfully");
|
||||
return newItem;
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
updateStrategy ??= new ForceCombinationFromFileUpdateStrategy();
|
||||
pointConvertStrategy ??= new Point2DToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
|
||||
combinationPropertyConvertStrategy ??= new FactoredCombinationPropertyToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
filePropertyConvertStrategy ??= new ColumnedFilePropertyToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
}
|
||||
|
||||
private void SetPoint(IForceCombinationFromFile source, ForceCombinationFromFileDTO newItem)
|
||||
{
|
||||
if (source.ForcePoint is not null)
|
||||
{
|
||||
var convertLogic = new DictionaryConvertStrategy<Point2DDTO, IPoint2D>(this, pointConvertStrategy);
|
||||
newItem.ForcePoint = convertLogic.Convert(source.ForcePoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
string errorMessage = ErrorStrings.NullReference + $"File combination {source.Name} Id={source.Id} does not have force point";
|
||||
TraceLogger.AddMessage(errorMessage, TraceLogStatuses.Error);
|
||||
throw new StructureHelperException(errorMessage);
|
||||
}
|
||||
}
|
||||
private void SetCombinationProperty(IForceCombinationFromFile source, ForceCombinationFromFileDTO newItem)
|
||||
{
|
||||
if (source.CombinationProperty is not null)
|
||||
{
|
||||
var convertLogic = new DictionaryConvertStrategy<FactoredCombinationPropertyDTO, IFactoredCombinationProperty>(this, combinationPropertyConvertStrategy);
|
||||
newItem.CombinationProperty = convertLogic.Convert(source.CombinationProperty);
|
||||
}
|
||||
else
|
||||
{
|
||||
string errorMessage = ErrorStrings.NullReference + $"Factored combination {source.Name} Id={source.Id} does not have combination properties";
|
||||
TraceLogger.AddMessage(errorMessage, TraceLogStatuses.Error);
|
||||
throw new StructureHelperException(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class ForceCombinationFromFileFromDTOConvertStrategy : ConvertStrategy<ForceCombinationFromFile, ForceCombinationFromFileDTO>
|
||||
{
|
||||
private IUpdateStrategy<IForceCombinationFromFile> updateStrategy;
|
||||
private IConvertStrategy<Point2D, Point2DDTO> pointConvertStrategy;
|
||||
private IConvertStrategy<FactoredCombinationProperty, FactoredCombinationPropertyDTO> combinationPropertyConvertStrategy;
|
||||
private IConvertStrategy<ColumnedFileProperty, ColumnedFilePropertyDTO> fileConvertStrategy;
|
||||
|
||||
public ForceCombinationFromFileFromDTOConvertStrategy(
|
||||
IUpdateStrategy<IForceCombinationFromFile> updateStrategy,
|
||||
IConvertStrategy<Point2D, Point2DDTO> pointConvertStrategy,
|
||||
IConvertStrategy<FactoredCombinationProperty, FactoredCombinationPropertyDTO> combinationPropertyConvertStrategy,
|
||||
IConvertStrategy<ColumnedFileProperty, ColumnedFilePropertyDTO> fileConvertStrategy)
|
||||
{
|
||||
this.updateStrategy = updateStrategy;
|
||||
this.pointConvertStrategy = pointConvertStrategy;
|
||||
this.combinationPropertyConvertStrategy = combinationPropertyConvertStrategy;
|
||||
this.fileConvertStrategy = fileConvertStrategy;
|
||||
}
|
||||
|
||||
public ForceCombinationFromFileFromDTOConvertStrategy() { }
|
||||
|
||||
public override ForceCombinationFromFile GetNewItem(ForceCombinationFromFileDTO source)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Force combination from file Name = {source.Name} converting has been started");
|
||||
InitializeStrategies();
|
||||
try
|
||||
{
|
||||
ForceCombinationFromFile newItem = GetForceCombination(source);
|
||||
TraceLogger?.AddMessage($"Force combination from file Name = {newItem.Name} converting has been finished successfully");
|
||||
return newItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Logic: {LoggerStrings.LogicType(this)} made error: {ex.Message}", TraceLogStatuses.Error);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private ForceCombinationFromFile GetForceCombination(ForceCombinationFromFileDTO source)
|
||||
{
|
||||
ForceCombinationFromFile newItem = new(source.Id);
|
||||
updateStrategy.Update(newItem, source);
|
||||
SetForceFiles(source, newItem);
|
||||
SetPoint(source, newItem);
|
||||
SetCombinationProperty(source, newItem);
|
||||
return newItem;
|
||||
}
|
||||
|
||||
private void SetForceFiles(ForceCombinationFromFileDTO source, ForceCombinationFromFile newItem)
|
||||
{
|
||||
newItem.ForceFiles.Clear();
|
||||
foreach (var item in source.ForceFiles)
|
||||
{
|
||||
if (item is ColumnedFilePropertyDTO filePropertyDTO)
|
||||
{
|
||||
ColumnedFileProperty columnFileProperty = fileConvertStrategy.Convert(filePropertyDTO);
|
||||
newItem.ForceFiles.Add(columnFileProperty);
|
||||
}
|
||||
else
|
||||
{
|
||||
string errorString = ErrorStrings.ExpectedWas(typeof(ColumnFilePropertyDTO), item);
|
||||
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
|
||||
throw new StructureHelperException(errorString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetPoint(IForceAction source, IForceAction newItem)
|
||||
{
|
||||
if (source.ForcePoint is Point2DDTO pointDTO)
|
||||
{
|
||||
newItem.ForcePoint = pointConvertStrategy.Convert(pointDTO);
|
||||
}
|
||||
else
|
||||
{
|
||||
string errorMessage = ErrorStrings.ExpectedWas(typeof(Point2DDTO), source.ForcePoint);
|
||||
TraceLogger.AddMessage(errorMessage, TraceLogStatuses.Error);
|
||||
throw new StructureHelperException(errorMessage);
|
||||
}
|
||||
}
|
||||
private void SetCombinationProperty(IForceFactoredCombination source, IForceFactoredCombination newItem)
|
||||
{
|
||||
if (source.CombinationProperty is FactoredCombinationPropertyDTO factoredPropertyDTO)
|
||||
{
|
||||
newItem.CombinationProperty = combinationPropertyConvertStrategy.Convert(factoredPropertyDTO);
|
||||
}
|
||||
else
|
||||
{
|
||||
string errorMessage = ErrorStrings.ExpectedWas(typeof(FactoredCombinationPropertyDTO), source.CombinationProperty);
|
||||
TraceLogger.AddMessage(errorMessage, TraceLogStatuses.Error);
|
||||
throw new StructureHelperException(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
updateStrategy ??= new ForceCombinationFromFileUpdateStrategy();
|
||||
pointConvertStrategy = new Point2DFromDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
|
||||
combinationPropertyConvertStrategy = new FactoredCombinationPropertyFromDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
|
||||
fileConvertStrategy ??= new ColumnedFilePropertyFromDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Forces.Logics;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class ForceCombinationListFromDTOConvertStrategy : ConvertStrategy<ForceCombinationList, ForceCombinationListDTO>
|
||||
{
|
||||
private IUpdateStrategy<IForceAction> baseUpdateStrategy;
|
||||
private IUpdateStrategy<IForceCombinationList> updateStrategy;
|
||||
private IConvertStrategy<Point2D, Point2DDTO> pointConvertStrategy;
|
||||
private IConvertStrategy<DesignForceTuple, DesignForceTupleDTO> designTupleConvertStrategy;
|
||||
|
||||
public ForceCombinationListFromDTOConvertStrategy(
|
||||
IUpdateStrategy<IForceAction> baseUpdateStrategy,
|
||||
IUpdateStrategy<IForceCombinationList> updateStrategy,
|
||||
IConvertStrategy<Point2D, Point2DDTO> pointConvertStrategy,
|
||||
IConvertStrategy<DesignForceTuple, DesignForceTupleDTO> designTupleConvertStrategy)
|
||||
{
|
||||
this.baseUpdateStrategy = baseUpdateStrategy;
|
||||
this.updateStrategy = updateStrategy;
|
||||
this.pointConvertStrategy = pointConvertStrategy;
|
||||
this.designTupleConvertStrategy = designTupleConvertStrategy;
|
||||
}
|
||||
|
||||
public ForceCombinationListFromDTOConvertStrategy() { }
|
||||
|
||||
public override ForceCombinationList GetNewItem(ForceCombinationListDTO source)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Force combination list Id = {source.Id}, Name = {source.Name} converting has been started");
|
||||
InitializeStrategies();
|
||||
try
|
||||
{
|
||||
ForceCombinationList newItem = GetNewItemBySource(source);
|
||||
TraceLogger?.AddMessage($"Force combination list Id = {source.Id}, Name = {source.Name} has been finished successfully");
|
||||
return newItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceErrorByEntity(this, ex.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private ForceCombinationList GetNewItemBySource(ForceCombinationListDTO source)
|
||||
{
|
||||
ForceCombinationList newItem = new(source.Id);
|
||||
baseUpdateStrategy.Update(newItem, source);
|
||||
//updateStrategy.Update(newItem, source);
|
||||
newItem.ForcePoint = pointConvertStrategy.Convert((Point2DDTO)source.ForcePoint);
|
||||
newItem.DesignForces.Clear();
|
||||
foreach (var item in source.DesignForces)
|
||||
{
|
||||
DesignForceTuple newDesignTuple = designTupleConvertStrategy.Convert((DesignForceTupleDTO)item);
|
||||
TraceLogger?.AddMessage($"New Design Tuple Limit state = {newDesignTuple.LimitState}, Calc term = {newDesignTuple.CalcTerm}");
|
||||
TraceLogger?.AddMessage($"Mx = {newDesignTuple.ForceTuple.Mx}, My = {newDesignTuple.ForceTuple.My}, Nz = {newDesignTuple.ForceTuple.Nz}");
|
||||
newItem.DesignForces.Add(newDesignTuple);
|
||||
}
|
||||
|
||||
return newItem;
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
baseUpdateStrategy ??= new ForceActionBaseUpdateStrategy();
|
||||
updateStrategy ??= new ForceCombinationListUpdateStrategy();
|
||||
pointConvertStrategy ??= new Point2DFromDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
|
||||
designTupleConvertStrategy ??= new DesignForceTupleFromDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class ForceCombinationListToDTOConvertStrategy : ConvertStrategy<ForceCombinationListDTO, IForceCombinationList>
|
||||
{
|
||||
private IUpdateStrategy<IForceCombinationList> updateStrategy;
|
||||
private IConvertStrategy<DesignForceTupleDTO, IDesignForceTuple> convertStrategy;
|
||||
private IUpdateStrategy<IForceAction> baseUpdateStrategy;
|
||||
private IConvertStrategy<Point2DDTO, IPoint2D> pointUpdateStrategy;
|
||||
|
||||
public ForceCombinationListToDTOConvertStrategy(
|
||||
IUpdateStrategy<IForceCombinationList> updateStrategy,
|
||||
IConvertStrategy<DesignForceTupleDTO, IDesignForceTuple> convertStrategy,
|
||||
IUpdateStrategy<IForceAction> baseUpdateStrategy,
|
||||
IConvertStrategy<Point2DDTO, IPoint2D> pointUpdateStrategy)
|
||||
{
|
||||
this.updateStrategy = updateStrategy;
|
||||
this.convertStrategy = convertStrategy;
|
||||
this.baseUpdateStrategy = baseUpdateStrategy;
|
||||
this.pointUpdateStrategy = pointUpdateStrategy;
|
||||
}
|
||||
|
||||
public ForceCombinationListToDTOConvertStrategy() { }
|
||||
|
||||
public override ForceCombinationListDTO GetNewItem(IForceCombinationList source)
|
||||
{
|
||||
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Debug);
|
||||
TraceLogger?.AddMessage($"Factored combination list Name: {source.Name} has been started");
|
||||
ForceCombinationListDTO forceCombinationListDTO = GetNewForceCombinationList(source);
|
||||
TraceLogger?.AddMessage($"Factored combination list Name: {source.Name} has been finished");
|
||||
return forceCombinationListDTO;
|
||||
}
|
||||
|
||||
private ForceCombinationListDTO GetNewForceCombinationList(IForceCombinationList source)
|
||||
{
|
||||
InitializeStrategies();
|
||||
ForceCombinationListDTO newItem = new() { Id = source.Id};
|
||||
baseUpdateStrategy.Update(newItem, source);
|
||||
updateStrategy.Update(newItem, source);
|
||||
convertStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||
convertStrategy.TraceLogger = TraceLogger;
|
||||
var convertLogic = new DictionaryConvertStrategy<DesignForceTupleDTO, IDesignForceTuple>(this, convertStrategy);
|
||||
GetNewForcePoint(newItem, source);
|
||||
newItem.DesignForces.Clear();
|
||||
foreach (var item in source.DesignForces)
|
||||
{
|
||||
newItem.DesignForces.Add(convertLogic.Convert(item));
|
||||
}
|
||||
return newItem;
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
updateStrategy ??= new ForceCombinationListUpdateStrategy();
|
||||
convertStrategy ??= new DesignForceTupleToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
|
||||
baseUpdateStrategy ??= new ForceActionBaseUpdateStrategy();
|
||||
pointUpdateStrategy ??= new Point2DToDTOConvertStrategy();
|
||||
}
|
||||
|
||||
private void GetNewForcePoint(ForceCombinationListDTO newItem, IForceCombinationList source)
|
||||
{
|
||||
if (source.ForcePoint is not null)
|
||||
{
|
||||
pointUpdateStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||
pointUpdateStrategy.TraceLogger = TraceLogger;
|
||||
var convertLogic = new DictionaryConvertStrategy<Point2DDTO, IPoint2D>(this, pointUpdateStrategy);
|
||||
newItem.ForcePoint = convertLogic.Convert(source.ForcePoint);
|
||||
}
|
||||
}
|
||||
|
||||
private void Check()
|
||||
{
|
||||
var checkLogic = new CheckConvertLogic<ForceCombinationListDTO, IForceCombinationList>(this);
|
||||
checkLogic.Check();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using StructureHelperCommon.Services;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class ForceFactoredListFromDTOConvertStrategy : ConvertStrategy<ForceFactoredList, ForceFactoredListDTO>
|
||||
{
|
||||
private IUpdateStrategy<IForceAction> baseUpdateStrategy;
|
||||
private IUpdateStrategy<IForceFactoredList> updateStrategy;
|
||||
private IConvertStrategy<Point2D, Point2DDTO> pointConvertStrategy;
|
||||
private IConvertStrategy<ForceTuple, ForceTupleDTO> forceTupleConvertStrategy;
|
||||
private IConvertStrategy<FactoredCombinationProperty, FactoredCombinationPropertyDTO> combinationPropertyConvertStrategy;
|
||||
|
||||
public ForceFactoredListFromDTOConvertStrategy(
|
||||
IUpdateStrategy<IForceAction> baseUpdateStrategy,
|
||||
IUpdateStrategy<IForceFactoredList> updateStrategy,
|
||||
IConvertStrategy<Point2D, Point2DDTO> pointConvertStrategy,
|
||||
IConvertStrategy<ForceTuple, ForceTupleDTO> forceTupleConvertStrategy,
|
||||
IConvertStrategy<FactoredCombinationProperty, FactoredCombinationPropertyDTO> combinationPropertyConvertStrategy)
|
||||
{
|
||||
this.baseUpdateStrategy = baseUpdateStrategy;
|
||||
this.updateStrategy = updateStrategy;
|
||||
this.pointConvertStrategy = pointConvertStrategy;
|
||||
this.forceTupleConvertStrategy = forceTupleConvertStrategy;
|
||||
this.combinationPropertyConvertStrategy = combinationPropertyConvertStrategy;
|
||||
}
|
||||
|
||||
public ForceFactoredListFromDTOConvertStrategy() { }
|
||||
|
||||
public override ForceFactoredList GetNewItem(ForceFactoredListDTO source)
|
||||
{
|
||||
InitializeStrategies();
|
||||
TraceLogger.AddMessage($"Force combination by factor name = {source.Name} converting is starting");
|
||||
ForceFactoredList newItem = new(source.Id);
|
||||
baseUpdateStrategy.Update(newItem, source);
|
||||
updateStrategy.Update(newItem, source);
|
||||
SetPoint(source, newItem);
|
||||
SetCombinationProperty(source, newItem);
|
||||
SetForceTuples(source, newItem);
|
||||
TraceLogger.AddMessage($"Force combination by factor name = {newItem.Name} converting has been finished");
|
||||
return newItem;
|
||||
}
|
||||
|
||||
private void SetForceTuples(ForceFactoredListDTO source, ForceFactoredList newItem)
|
||||
{
|
||||
CheckObject.IsNull(newItem.ForceTuples, nameof(newItem.ForceTuples));
|
||||
newItem.ForceTuples.Clear();
|
||||
foreach (var item in source.ForceTuples)
|
||||
{
|
||||
var newTuple = forceTupleConvertStrategy.Convert((ForceTupleDTO)item);
|
||||
newItem.ForceTuples.Add(newTuple);
|
||||
}
|
||||
}
|
||||
private void SetPoint(ForceFactoredListDTO source, ForceFactoredList newItem)
|
||||
{
|
||||
if (source.ForcePoint is Point2DDTO pointDTO)
|
||||
{
|
||||
newItem.ForcePoint = pointConvertStrategy.Convert(pointDTO);
|
||||
}
|
||||
else
|
||||
{
|
||||
string errorMessage = ErrorStrings.ExpectedWas(typeof(Point2DDTO), source.ForcePoint);
|
||||
TraceLogger.AddMessage(errorMessage, TraceLogStatuses.Error);
|
||||
throw new StructureHelperException(errorMessage);
|
||||
}
|
||||
}
|
||||
private void SetCombinationProperty(ForceFactoredListDTO source, ForceFactoredList newItem)
|
||||
{
|
||||
if (source.CombinationProperty is FactoredCombinationPropertyDTO factoredPropertyDTO)
|
||||
{
|
||||
newItem.CombinationProperty = combinationPropertyConvertStrategy.Convert(factoredPropertyDTO);
|
||||
}
|
||||
else
|
||||
{
|
||||
string errorMessage = ErrorStrings.ExpectedWas(typeof(FactoredCombinationPropertyDTO), source.CombinationProperty);
|
||||
TraceLogger.AddMessage(errorMessage, TraceLogStatuses.Error);
|
||||
throw new StructureHelperException(errorMessage);
|
||||
}
|
||||
}
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
baseUpdateStrategy ??= new ForceActionBaseUpdateStrategy();
|
||||
updateStrategy ??= new ForceFactoredListUpdateStrategy();
|
||||
pointConvertStrategy ??= new Point2DFromDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
|
||||
forceTupleConvertStrategy ??= new ForceTupleFromDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
combinationPropertyConvertStrategy ??= new FactoredCombinationPropertyFromDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class ForceFactoredListToDTOConvertStrategy : ConvertStrategy<ForceFactoredListDTO, IForceFactoredList>
|
||||
{
|
||||
private IUpdateStrategy<IForceFactoredList> updateStrategy;
|
||||
private IConvertStrategy<Point2DDTO, IPoint2D> pointConvertStrategy;
|
||||
private IConvertStrategy<ForceTupleDTO, IForceTuple> forceTupleConvertStrategy;
|
||||
private IUpdateStrategy<IForceAction> baseUpdateStrategy;
|
||||
private IConvertStrategy<FactoredCombinationPropertyDTO, IFactoredCombinationProperty> combinationPropertyConvertStrategy;
|
||||
|
||||
public ForceFactoredListToDTOConvertStrategy(IUpdateStrategy<IForceFactoredList> updateStrategy,
|
||||
IConvertStrategy<Point2DDTO, IPoint2D> pointConvertStrategy,
|
||||
IConvertStrategy<ForceTupleDTO, IForceTuple> forceTupleConvertStrategy,
|
||||
IUpdateStrategy<IForceAction> baseUpdateStrategy)
|
||||
{
|
||||
this.updateStrategy = updateStrategy;
|
||||
this.pointConvertStrategy = pointConvertStrategy;
|
||||
this.forceTupleConvertStrategy = forceTupleConvertStrategy;
|
||||
this.baseUpdateStrategy = baseUpdateStrategy;
|
||||
}
|
||||
|
||||
public ForceFactoredListToDTOConvertStrategy() { }
|
||||
|
||||
public override ForceFactoredListDTO GetNewItem(IForceFactoredList source)
|
||||
{
|
||||
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Debug);
|
||||
TraceLogger?.AddMessage($"Force combination by factor, name = {source.Name} converting has been started");
|
||||
InitializeStrategies();
|
||||
ForceFactoredListDTO newItem = GetNewForceTuple(source);
|
||||
TraceLogger?.AddMessage($"Force combination by factor, name = {newItem.Name} converting has been finished successfully");
|
||||
return newItem;
|
||||
|
||||
}
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
baseUpdateStrategy ??= new ForceActionBaseUpdateStrategy();
|
||||
updateStrategy ??= new ForceFactoredListUpdateStrategy();
|
||||
forceTupleConvertStrategy ??= new ForceTupleToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
|
||||
pointConvertStrategy ??= new Point2DToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
|
||||
combinationPropertyConvertStrategy ??= new FactoredCombinationPropertyToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
|
||||
}
|
||||
|
||||
private ForceFactoredListDTO GetNewForceTuple(IForceFactoredList source)
|
||||
{
|
||||
ForceFactoredListDTO newItem = new(source.Id);
|
||||
baseUpdateStrategy.Update(newItem, source);
|
||||
updateStrategy.Update(newItem, source);
|
||||
SetPoint(source, newItem);
|
||||
SetForces(source, newItem);
|
||||
SetCombinationProperty(source, newItem);
|
||||
return newItem;
|
||||
}
|
||||
private void SetForces(IForceFactoredList source, ForceFactoredListDTO newItem)
|
||||
{
|
||||
if (source.ForceTuples is not null)
|
||||
{
|
||||
var convertForceTupleLogic = new DictionaryConvertStrategy<ForceTupleDTO, IForceTuple>(this, forceTupleConvertStrategy);
|
||||
newItem.ForceTuples.Clear();
|
||||
foreach (var item in source.ForceTuples)
|
||||
{
|
||||
var forceTuple = convertForceTupleLogic.Convert(item);
|
||||
newItem.ForceTuples.Add(forceTuple);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string errorMessage = ErrorStrings.NullReference + $"Factored combination {source.Name} Id={source.Id} does not have list of forces";
|
||||
TraceLogger?.AddMessage(errorMessage, TraceLogStatuses.Error);
|
||||
throw new StructureHelperException(errorMessage);
|
||||
}
|
||||
}
|
||||
private void SetPoint(IForceFactoredList source, ForceFactoredListDTO newItem)
|
||||
{
|
||||
if (source.ForcePoint is not null)
|
||||
{
|
||||
var convertLogic = new DictionaryConvertStrategy<Point2DDTO, IPoint2D>(this, pointConvertStrategy);
|
||||
newItem.ForcePoint = convertLogic.Convert(source.ForcePoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
string errorMessage = ErrorStrings.NullReference + $"Factored combination {source.Name} Id={source.Id} does not have force point";
|
||||
TraceLogger?.AddMessage(errorMessage, TraceLogStatuses.Error);
|
||||
throw new StructureHelperException(errorMessage);
|
||||
}
|
||||
}
|
||||
private void SetCombinationProperty(IForceFactoredList source, ForceFactoredListDTO newItem)
|
||||
{
|
||||
if (source.CombinationProperty is not null)
|
||||
{
|
||||
var convertLogic = new DictionaryConvertStrategy<FactoredCombinationPropertyDTO, IFactoredCombinationProperty>(this, combinationPropertyConvertStrategy);
|
||||
newItem.CombinationProperty = convertLogic.Convert(source.CombinationProperty);
|
||||
}
|
||||
else
|
||||
{
|
||||
string errorMessage = ErrorStrings.NullReference + $"Factored combination {source.Name} Id={source.Id} does not have combination properties";
|
||||
TraceLogger?.AddMessage(errorMessage, TraceLogStatuses.Error);
|
||||
throw new StructureHelperException(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class ForceTupleFromDTOConvertStrategy : ConvertStrategy<ForceTuple, ForceTupleDTO>
|
||||
{
|
||||
private readonly IUpdateStrategy<IForceTuple> updateStrategy;
|
||||
|
||||
public ForceTupleFromDTOConvertStrategy(IUpdateStrategy<IForceTuple> updateStrategy)
|
||||
{
|
||||
this.updateStrategy = updateStrategy;
|
||||
}
|
||||
|
||||
public ForceTupleFromDTOConvertStrategy() : this(new ForceTupleUpdateStrategy())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override ForceTuple GetNewItem(ForceTupleDTO source)
|
||||
{
|
||||
ForceTuple newItem = new(source.Id);
|
||||
updateStrategy.Update(newItem, source);
|
||||
return newItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class ForceTupleToDTOConvertStrategy : ConvertStrategy<ForceTupleDTO, IForceTuple>
|
||||
{
|
||||
private IUpdateStrategy<IForceTuple> updateStrategy;
|
||||
|
||||
public ForceTupleToDTOConvertStrategy(IUpdateStrategy<IForceTuple> updateStrategy)
|
||||
{
|
||||
this.updateStrategy = updateStrategy;
|
||||
}
|
||||
|
||||
public ForceTupleToDTOConvertStrategy() : this(new ForceTupleUpdateStrategy())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ForceTupleToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger)
|
||||
: base(referenceDictionary, traceLogger)
|
||||
{
|
||||
}
|
||||
|
||||
public override ForceTupleDTO GetNewItem(IForceTuple source)
|
||||
{
|
||||
try
|
||||
{
|
||||
GetNewBeamForceTuple(source);
|
||||
return NewItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceErrorByEntity(this, ex.Message);
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void GetNewBeamForceTuple(IForceTuple source)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Converting of force tuple Id = {source.Id} has been started", TraceLogStatuses.Debug);
|
||||
updateStrategy ??= new ForceTupleUpdateStrategy();
|
||||
NewItem = new(source.Id);
|
||||
updateStrategy.Update(NewItem, source);
|
||||
TraceLogger?.AddMessage($"Converting of force tuple Id = {source.Id} has been finished", TraceLogStatuses.Debug);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user