Add beam shear converting to DTO

This commit is contained in:
Evgeny Redikultsev
2025-06-08 15:49:17 +05:00
parent 3dab65e3bd
commit 0d7f47653b
150 changed files with 710 additions and 259 deletions

View File

@@ -0,0 +1,57 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Forces.BeamShearActions;
namespace DataAccess.DTOs
{
public class BeamShearActionConvertStrategy : ConvertStrategy<BeamShearActionDTO, IBeamShearAction>
{
private IUpdateStrategy<IBeamShearAction> updateStrategy;
private IConvertStrategy<FactoredForceTupleDTO, IFactoredForceTuple> factoredTupleConvertStrategy;
private IConvertStrategy<BeamShearAxisActionDTO, IBeamShearAxisAction> axisActionConvertStrategy;
public BeamShearActionConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
{
}
public BeamShearActionConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger)
: base(referenceDictionary, traceLogger)
{
}
public override BeamShearActionDTO GetNewItem(IBeamShearAction source)
{
try
{
GetNewBeamAction(source);
return NewItem;
}
catch (Exception ex)
{
TraceErrorByEntity(this, ex.Message);
throw;
}
}
private void GetNewBeamAction(IBeamShearAction source)
{
TraceLogger?.AddMessage($"Beam shear action converting Id = {source.Id} has been started", TraceLogStatuses.Debug);
InitializeStrategies();
NewItem = new(source.Id);
updateStrategy.Update(NewItem, source);
NewItem.ExternalForce = factoredTupleConvertStrategy.Convert(source.ExternalForce);
NewItem.SupportAction = axisActionConvertStrategy.Convert(source.SupportAction);
TraceLogger?.AddMessage($"Beam shear action converting Id = {NewItem.Id} has been finished", TraceLogStatuses.Debug);
}
private void InitializeStrategies()
{
updateStrategy ??= new BeamShearActionUpdateStrategy();
factoredTupleConvertStrategy = new DictionaryConvertStrategy<FactoredForceTupleDTO, IFactoredForceTuple>
(this, new FactoredForceTupleToDTOConvertStrategy(this));
axisActionConvertStrategy = new DictionaryConvertStrategy<BeamShearAxisActionDTO, IBeamShearAxisAction>
(this, new BeamShearAxisActionToDTOConvertStrategy(this));
}
}
}

View File

@@ -0,0 +1,54 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses;
using StructureHelperLogics.Models.Analyses;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces.LimitCurve;
namespace DataAccess.DTOs
{
public class BeamShearAnalysisToDTOConvertStrategy : ConvertStrategy<BeamShearAnalysisDTO, IBeamShearAnalysis>
{
private IUpdateStrategy<IBeamShearAnalysis> updateStrategy;
private IConvertStrategy<VersionProcessorDTO, IVersionProcessor> convertStrategy;
public BeamShearAnalysisToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger) : base(referenceDictionary, traceLogger)
{
}
public override BeamShearAnalysisDTO GetNewItem(IBeamShearAnalysis source)
{
updateStrategy ??= new BeamShearAnalysisUpdateStrategy();
try
{
GetNewAnalysis(source);
return NewItem;
}
catch (Exception ex)
{
TraceErrorByEntity(this, ex.Message);
throw;
}
}
private void GetNewAnalysis(IBeamShearAnalysis source)
{
TraceLogger?.AddMessage($"Converting beam shear analysis id = {source.Id} has been started");
InitializeStrategies();
NewItem = new(source.Id);
updateStrategy.Update(NewItem, source);
NewItem.VersionProcessor = convertStrategy.Convert(source.VersionProcessor);
TraceLogger?.AddMessage($"Converting beam shear analysis id = {NewItem.Id} has done successfully");
}
private void InitializeStrategies()
{
updateStrategy ??= new BeamShearAnalysisUpdateStrategy();
convertStrategy = new DictionaryConvertStrategy<VersionProcessorDTO, IVersionProcessor>()
{
ReferenceDictionary = ReferenceDictionary,
ConvertStrategy = new VersionProcessorToDTOConvertStrategy(ReferenceDictionary, TraceLogger),
TraceLogger = TraceLogger
};
}
}
}

View File

@@ -0,0 +1,60 @@
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 BeamShearAxisActionToDTOConvertStrategy : ConvertStrategy<BeamShearAxisActionDTO, IBeamShearAxisAction>
{
private IUpdateStrategy<IBeamShearAxisAction> updateStrategy;
private IConvertStrategy<FactoredForceTupleDTO, IFactoredForceTuple> factoredTupleConvertStrategy;
private IConvertStrategy<IBeamSpanLoad, IBeamSpanLoad> spanLoadConvertStrategy;
public BeamShearAxisActionToDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
{
}
public override BeamShearAxisActionDTO GetNewItem(IBeamShearAxisAction source)
{
try
{
GetNewBeamAction(source);
return NewItem;
}
catch (Exception ex)
{
TraceErrorByEntity(this, ex.Message);
throw;
}
}
private void GetNewBeamAction(IBeamShearAxisAction 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.SupportForce = factoredTupleConvertStrategy.Convert(source.SupportForce);
NewItem.ShearLoads.Clear();
foreach (var spanLoad in source.ShearLoads)
{
var newSpanLoad = spanLoadConvertStrategy.Convert(spanLoad);
NewItem.ShearLoads.Add(newSpanLoad);
}
TraceLogger?.AddMessage($"Converting of beam shear action Id = {source.Id} has been finished", TraceLogStatuses.Debug);
}
private void InitializeStrategies()
{
updateStrategy ??= new BeamShearAxisActionUpdateStrategy();
factoredTupleConvertStrategy = new DictionaryConvertStrategy<FactoredForceTupleDTO, IFactoredForceTuple>
(this, new FactoredForceTupleToDTOConvertStrategy(this));
spanLoadConvertStrategy = new DictionaryConvertStrategy<IBeamSpanLoad, IBeamSpanLoad>
(this, new BeamSpanLoadToDTOConvertStrategy(this));
}
}
}

View File

@@ -0,0 +1,50 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.BeamShears;
namespace DataAccess.DTOs
{
public class BeamShearCalculatorInputDataToDTOConvertStrategy : ConvertStrategy<BeamShearCalculatorInputDataDTO, IBeamShearCalculatorInputData>
{
private IUpdateStrategy<IHasBeamShearActions> actionUpdateStrategy;
private IUpdateStrategy<IHasBeamShearSections> sectionUpdateStrategy;
private IUpdateStrategy<IHasStirrups> stirrupUpdateStrategy;
public BeamShearCalculatorInputDataToDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
{
}
public override BeamShearCalculatorInputDataDTO GetNewItem(IBeamShearCalculatorInputData source)
{
try
{
GetNewInputData(source);
return NewItem;
}
catch (Exception ex)
{
TraceErrorByEntity(this, ex.Message);
throw;
}
}
private void GetNewInputData(IBeamShearCalculatorInputData source)
{
TraceLogger?.AddMessage($"Input data converting Id = {source.Id} has been started", TraceLogStatuses.Debug);
InitializeStrategies();
NewItem = new(source.Id);
actionUpdateStrategy.Update(NewItem, source);
sectionUpdateStrategy.Update(NewItem, source);
stirrupUpdateStrategy.Update(NewItem, source);
TraceLogger?.AddMessage($"Input data converting Id = {NewItem.Id} has been finished", TraceLogStatuses.Debug);
}
private void InitializeStrategies()
{
actionUpdateStrategy ??= new HasBeamShearActionToDTOConvertStrategy(ReferenceDictionary, TraceLogger);
sectionUpdateStrategy ??= new HasBeamShearSectionToDTOConvertStrategy(ReferenceDictionary, TraceLogger);
stirrupUpdateStrategy ??= new HasStirrupToDTOConvertStrategy(ReferenceDictionary, TraceLogger);
}
}
}

View File

@@ -0,0 +1,48 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.BeamShears;
namespace DataAccess.DTOs
{
public class BeamShearCalculatorToDTOConvertStrategy : ConvertStrategy<BeamShearCalculatorDTO, IBeamShearCalculator>
{
private IUpdateStrategy<IBeamShearCalculator> updateStrategy;
private IConvertStrategy<BeamShearCalculatorInputDataDTO, IBeamShearCalculatorInputData> inputDataConvertStrategy;
public BeamShearCalculatorToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger)
: base(referenceDictionary, traceLogger)
{
}
public override BeamShearCalculatorDTO GetNewItem(IBeamShearCalculator source)
{
try
{
GetNewCalculator(source);
return NewItem;
}
catch (Exception ex)
{
TraceErrorByEntity(this, ex.Message);
throw;
}
}
private void GetNewCalculator(IBeamShearCalculator source)
{
TraceLogger?.AddMessage($"Beam shear calculator converting Id = {source.Id} has been started", TraceLogStatuses.Debug);
InitializeStrategies();
NewItem = new(source.Id);
updateStrategy.Update(NewItem, source);
NewItem.InputData = inputDataConvertStrategy.Convert(source.InputData);
TraceLogger?.AddMessage($"Beam shear calculator converting Id = {NewItem.Id} has been finished successfully", TraceLogStatuses.Debug);
}
private void InitializeStrategies()
{
updateStrategy ??= new BeamShearCalculatorUpdateStrategy();
inputDataConvertStrategy = new DictionaryConvertStrategy<BeamShearCalculatorInputDataDTO, IBeamShearCalculatorInputData>
(this, new BeamShearCalculatorInputDataToDTOConvertStrategy(this));
}
}
}

View File

@@ -0,0 +1,60 @@
using DataAccess.DTOs.Converters;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Forces.BeamShearActions;
using StructureHelperLogics.Models.BeamShears;
//Copyright (c) 2025 Redikultsev Evgeny, Ekaterinburg, Russia
//All rights reserved.
namespace DataAccess.DTOs
{
public class BeamShearRepositoryToDTOConvertStrategy : ConvertStrategy<BeamShearRepositoryDTO, IBeamShearRepository>
{
private IUpdateStrategy<IHasBeamShearActions> actionUpdateStrategy;
private IUpdateStrategy<IHasBeamShearSections> sectionUpdateStrategy;
private IUpdateStrategy<IHasStirrups> stirrupUpdateStrategy;
private IUpdateStrategy<IHasCalculators> calculatorUpdateStrategy;
public BeamShearRepositoryToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger) : base(referenceDictionary, traceLogger)
{
}
public override BeamShearRepositoryDTO GetNewItem(IBeamShearRepository source)
{
try
{
GetNewBeamRepository(source);
return NewItem;
}
catch (Exception ex)
{
TraceErrorByEntity(this, ex.Message);
throw;
}
}
private void GetNewBeamRepository(IBeamShearRepository source)
{
TraceLogger?.AddMessage($"Converting of beam shear repository Id = {source.Id} has been started", TraceLogStatuses.Debug);
InitializeStrategies();
NewItem = new(source.Id);
actionUpdateStrategy.Update(NewItem, source);
sectionUpdateStrategy.Update(NewItem, source);
stirrupUpdateStrategy.Update(NewItem, source);
calculatorUpdateStrategy.Update(NewItem, source);
TraceLogger?.AddMessage($"Converting of beam shear repository Id = {NewItem.Id} has been finished", TraceLogStatuses.Service);
}
private void InitializeStrategies()
{
actionUpdateStrategy ??= new HasBeamShearActionToDTOConvertStrategy(ReferenceDictionary, TraceLogger);
sectionUpdateStrategy ??= new HasBeamShearSectionToDTOConvertStrategy(ReferenceDictionary, TraceLogger);
stirrupUpdateStrategy ??= new HasStirrupToDTOConvertStrategy(ReferenceDictionary, TraceLogger);
calculatorUpdateStrategy ??= new HasBeamShearCalculatorToDTOConvertStrategy(ReferenceDictionary, TraceLogger);
}
}
}

View File

@@ -0,0 +1,58 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Materials;
using StructureHelperCommon.Models.Shapes;
using StructureHelperLogics.Models.BeamShears;
namespace DataAccess.DTOs
{
public class BeamShearSectionToDTOConvertStrategy : ConvertStrategy<BeamShearSectionDTO, IBeamShearSection>
{
private IUpdateStrategy<IBeamShearSection> updateStrategy;
private IConvertStrategy<IShape, IShape> shapeConvertStrategy;
private ConcreteLibMaterialToDTOConvertStrategy concreteConvertStrategy;
private IUpdateStrategy<IHelperMaterial> safetyFactorUpdateStrategy;
public BeamShearSectionToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger)
: base(referenceDictionary, traceLogger)
{
}
public override BeamShearSectionDTO GetNewItem(IBeamShearSection source)
{
try
{
GetNewSection(source);
return NewItem;
}
catch (Exception ex)
{
TraceErrorByEntity(this, ex.Message);
throw;
}
}
private void GetNewSection(IBeamShearSection source)
{
TraceLogger?.AddMessage($"Beam shear section converting Id = {source.Id} has been started", TraceLogStatuses.Debug);
InitializeStrategies();
NewItem = new(source.Id);
updateStrategy.Update(NewItem, source);
NewItem.Shape = shapeConvertStrategy.Convert(source.Shape);
NewItem.Material = concreteConvertStrategy.Convert(source.Material);
safetyFactorUpdateStrategy.Update(NewItem.Material, source.Material);
TraceLogger?.AddMessage($"Beam shear section converting Id = {NewItem.Id} has been finished succesfully", TraceLogStatuses.Debug);
}
private void InitializeStrategies()
{
updateStrategy ??= new BeamShearSectionUpdateStrategy();
shapeConvertStrategy = new DictionaryConvertStrategy<IShape, IShape>
(this, new ShapeToDTOConvertStrategy(this));
concreteConvertStrategy = new ConcreteLibMaterialToDTOConvertStrategy()
{ ReferenceDictionary = ReferenceDictionary,
TraceLogger = TraceLogger};
safetyFactorUpdateStrategy = new HelperMaterialDTOSafetyFactorUpdateStrategy(new MaterialSafetyFactorToDTOLogic());
}
}
}

View File

@@ -0,0 +1,53 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.BeamShears;
//Copyright (c) 2025 Redikultsev Evgeny, Ekaterinburg, Russia
//All rights reserved.
namespace DataAccess.DTOs
{
public class BeamShearToDTOConvertStrategy : ConvertStrategy<BeamShearDTO, IBeamShear>
{
private IUpdateStrategy<IBeamShear> updateStrategy;
private IConvertStrategy<BeamShearRepositoryDTO, IBeamShearRepository> repositoryConvertStrategy;
public BeamShearToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger)
: base(referenceDictionary, traceLogger)
{
}
public override BeamShearDTO GetNewItem(IBeamShear source)
{
try
{
GetNewBeamShear(source);
return NewItem;
}
catch (Exception ex)
{
TraceErrorByEntity(this, ex.Message);
throw;
}
}
private void GetNewBeamShear(IBeamShear source)
{
TraceLogger?.AddMessage($"Converting of beam shear Id = {source.Id} has been started");
InitializeStrategies();
NewItem = new(source.Id);
updateStrategy.Update(NewItem, source);
NewItem.Repository = repositoryConvertStrategy.Convert(source.Repository);
TraceLogger?.AddMessage($"Converting of beam shear Id = {NewItem.Id} has been finished successfully");
}
private void InitializeStrategies()
{
updateStrategy ??= new BeamShearUpdateStrategy();
repositoryConvertStrategy = new DictionaryConvertStrategy<BeamShearRepositoryDTO, IBeamShearRepository>(
ReferenceDictionary,
TraceLogger,
new BeamShearRepositoryToDTOConvertStrategy(ReferenceDictionary, TraceLogger)
);
}
}
}

View File

@@ -0,0 +1,62 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Forces;
namespace DataAccess.DTOs
{
public class BeamSpanLoadToDTOConvertStrategy : ConvertStrategy<IBeamSpanLoad, IBeamSpanLoad>
{
public BeamSpanLoadToDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
{
}
public override IBeamSpanLoad GetNewItem(IBeamSpanLoad source)
{
try
{
GetNewBeamAction(source);
return NewItem;
}
catch (Exception ex)
{
TraceErrorByEntity(this, ex.Message);
throw;
}
}
private void GetNewBeamAction(IBeamSpanLoad source)
{
TraceLogger?.AddMessage($"Converting of beam shear action Id = {source.Id} has been started", TraceLogStatuses.Debug);
if (source is IDistributedLoad distributedLoad)
{
ProcessDistributedLoad(distributedLoad);
}
else if (source is IConcentratedForce concentratedForce)
{
ProcessConcentratedForce(concentratedForce);
}
else
{
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(source) + ": type of span load");
}
TraceLogger?.AddMessage($"Converting of beam shear action Id = {source.Id} has been finished", TraceLogStatuses.Debug);
}
private void ProcessConcentratedForce(IConcentratedForce concentratedForce)
{
var convertStrategy = new DictionaryConvertStrategy<ConcentratedForceDTO, IConcentratedForce>
(this, new ConcentratedForceToDTOConvertStrategy(this));
ConcentratedForceDTO concentratedForceDTO = convertStrategy.Convert(concentratedForce);
NewItem = concentratedForceDTO;
}
private void ProcessDistributedLoad(IDistributedLoad distributedLoad)
{
var convertStrategy = new DictionaryConvertStrategy<DistributedLoadDTO, IDistributedLoad>
(this, new DistributedLoadToDTOConvertStrategy(this));
DistributedLoadDTO distributedLoadDTO = convertStrategy.Convert(distributedLoad);
NewItem = distributedLoadDTO;
}
}
}

View File

@@ -0,0 +1,38 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Services;
namespace DataAccess.DTOs
{
public class HasBeamShearActionToDTOConvertStrategy : IUpdateStrategy<IHasBeamShearActions>
{
private Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get;}
private IShiftTraceLogger TraceLogger { get;}
public HasBeamShearActionToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger)
{
ReferenceDictionary = referenceDictionary;
TraceLogger = traceLogger;
}
public void Update(IHasBeamShearActions targetObject, IHasBeamShearActions sourceObject)
{
CheckObject.IsNull(targetObject);
CheckObject.IsNull(sourceObject);
if (ReferenceEquals(targetObject, sourceObject)) { return; }
CheckObject.IsNull(sourceObject.Actions);
CheckObject.IsNull(targetObject.Actions);
targetObject.Actions.Clear();
foreach (var action in sourceObject.Actions)
{
var convertStrategy = new DictionaryConvertStrategy<BeamShearActionDTO, IBeamShearAction>(
ReferenceDictionary,
TraceLogger,
new BeamShearActionConvertStrategy(ReferenceDictionary, TraceLogger));
var newAction = convertStrategy.Convert(action);
targetObject.Actions.Add(newAction);
}
}
}
}

View File

@@ -0,0 +1,64 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Services;
using StructureHelperLogics.Models.BeamShears;
namespace DataAccess.DTOs
{
public class HasBeamShearCalculatorToDTOConvertStrategy : IUpdateStrategy<IHasCalculators>
{
private Dictionary<(Guid id, Type type), ISaveable> referenceDictionary;
private IShiftTraceLogger traceLogger;
public HasBeamShearCalculatorToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger)
{
this.referenceDictionary = referenceDictionary;
this.traceLogger = traceLogger;
}
public void Update(IHasCalculators targetObject, IHasCalculators sourceObject)
{
CheckObject.IsNull(targetObject);
CheckObject.IsNull(sourceObject);
if (ReferenceEquals(targetObject, sourceObject)) { return; }
CheckObject.IsNull(sourceObject.Calculators);
CheckObject.IsNull(targetObject.Calculators);
targetObject.Calculators.Clear();
List<ICalculator> calculators = GetCalculators(sourceObject.Calculators);
targetObject.Calculators.AddRange(calculators);
}
private List<ICalculator> GetCalculators(IEnumerable<ICalculator> sourceCalculators)
{
List<ICalculator> calculators = new();
foreach (var calculator in sourceCalculators)
{
ICalculator newCalculator = ProcessCalculator(calculator);
calculators.Add(newCalculator);
}
return calculators;
}
private ICalculator ProcessCalculator(ICalculator calculator)
{
if (calculator is IBeamShearCalculator shearCalculator)
{
return ProcessShearCalculator(shearCalculator);
}
else
{
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(calculator));
}
}
private ICalculator ProcessShearCalculator(IBeamShearCalculator shearCalculator)
{
traceLogger?.AddMessage("Calcultor is beam shear calculator", TraceLogStatuses.Debug);
var convertStrategy = new DictionaryConvertStrategy<BeamShearCalculatorDTO, IBeamShearCalculator>
(referenceDictionary, traceLogger, new BeamShearCalculatorToDTOConvertStrategy(referenceDictionary, traceLogger));
return convertStrategy.Convert(shearCalculator);
}
}
}

View File

@@ -0,0 +1,42 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Services;
using StructureHelperLogics.Models.BeamShears;
namespace DataAccess.DTOs
{
public class HasBeamShearSectionToDTOConvertStrategy : IUpdateStrategy<IHasBeamShearSections>
{
private IConvertStrategy<BeamShearSectionDTO, IBeamShearSection> convertStrategy;
private Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; }
private IShiftTraceLogger TraceLogger { get; }
public HasBeamShearSectionToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger)
{
ReferenceDictionary = referenceDictionary;
TraceLogger = traceLogger;
}
public void Update(IHasBeamShearSections targetObject, IHasBeamShearSections sourceObject)
{
CheckObject.IsNull(targetObject);
CheckObject.IsNull(sourceObject);
if (ReferenceEquals(targetObject, sourceObject)) { return; }
CheckObject.IsNull(sourceObject.Sections);
CheckObject.IsNull(targetObject.Sections);
InitializeStrategies();
targetObject.Sections.Clear();
foreach (var section in sourceObject.Sections)
{
var newSection = convertStrategy.Convert(section);
targetObject.Sections.Add(newSection);
}
}
private void InitializeStrategies()
{
convertStrategy = new DictionaryConvertStrategy<BeamShearSectionDTO, IBeamShearSection>
(ReferenceDictionary, TraceLogger, new BeamShearSectionToDTOConvertStrategy(ReferenceDictionary, TraceLogger));
}
}
}

View File

@@ -0,0 +1,84 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Services;
using StructureHelperLogics.Models.BeamShears;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace DataAccess.DTOs
{
public class HasStirrupToDTOConvertStrategy : IUpdateStrategy<IHasStirrups>
{
private Dictionary<(Guid id, Type type), ISaveable> referenceDictionary;
private IShiftTraceLogger traceLogger;
public HasStirrupToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger)
{
this.referenceDictionary = referenceDictionary;
this.traceLogger = traceLogger;
}
public void Update(IHasStirrups targetObject, IHasStirrups sourceObject)
{
CheckObject.IsNull(targetObject);
CheckObject.IsNull(sourceObject);
if (ReferenceEquals(targetObject, sourceObject)) { return; }
CheckObject.IsNull(sourceObject.Stirrups);
CheckObject.IsNull(targetObject.Stirrups);
targetObject.Stirrups.Clear();
List<IStirrup> stirrups = GetStirrups(sourceObject.Stirrups);
targetObject.Stirrups.AddRange(stirrups);
}
private List<IStirrup> GetStirrups(IEnumerable<IStirrup> sourceStirrups)
{
List<IStirrup> stirrups = new();
foreach (var stirrup in sourceStirrups)
{
IStirrup newItem = ProcessStirrup(stirrup);
stirrups.Add(newItem);
}
return stirrups;
}
private IStirrup ProcessStirrup(IStirrup stirrup)
{
IStirrup newItem;
if (stirrup is IStirrupByRebar rebar)
{
newItem = ProcessRebar(rebar);
}
else if (stirrup is IStirrupByDensity density)
{
newItem = ProcessDensity(density);
}
else
{
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(stirrup));
}
return newItem;
}
private IStirrup ProcessDensity(IStirrupByDensity density)
{
traceLogger?.AddMessage("Stirrup is stirrup by density");
var convertStrategy = new DictionaryConvertStrategy<StirrupByDensityDTO, IStirrupByDensity>
(referenceDictionary, traceLogger, new StirrupByDensityToDTOConvertStrategy(referenceDictionary, traceLogger));
return convertStrategy.Convert(density);
}
private StirrupByRebarDTO ProcessRebar(IStirrupByRebar rebar)
{
traceLogger?.AddMessage("Stirrup is stirrup by rebar");
var convertStrategy = new DictionaryConvertStrategy<StirrupByRebarDTO, IStirrupByRebar>
(referenceDictionary, traceLogger, new StirrupByRebarToDTOConvertStrategy(referenceDictionary, traceLogger));
return convertStrategy.Convert(rebar);
}
}
}

View File

@@ -0,0 +1,44 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.BeamShears;
namespace DataAccess.DTOs
{
public class StirrupByDensityToDTOConvertStrategy : ConvertStrategy<StirrupByDensityDTO, IStirrupByDensity>
{
private IUpdateStrategy<IStirrupByDensity> updateStrategy;
public StirrupByDensityToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger)
: base(referenceDictionary, traceLogger)
{
}
public override StirrupByDensityDTO GetNewItem(IStirrupByDensity source)
{
try
{
GetNewStirrup(source);
return NewItem;
}
catch (Exception ex)
{
TraceErrorByEntity(this, ex.Message);
throw;
}
}
private void GetNewStirrup(IStirrupByDensity source)
{
TraceLogger?.AddMessage($"Stirrup by density converting Id = {source.Id} has been started", TraceLogStatuses.Debug);
InitializeStrategies();
NewItem = new(source.Id);
updateStrategy.Update(NewItem, source);
TraceLogger?.AddMessage($"Stirrup by density converting Id = {NewItem.Id} has been finished succesfully", TraceLogStatuses.Debug);
}
private void InitializeStrategies()
{
updateStrategy ??= new StirrupByDensityUpdateStrategy();
}
}
}

View File

@@ -0,0 +1,54 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.BeamShears;
namespace DataAccess.DTOs
{
public class StirrupByRebarToDTOConvertStrategy : ConvertStrategy<StirrupByRebarDTO, IStirrupByRebar>
{
private StirrupByRebarUpdateStrategy updateStrategy;
private ReinforcementLibMaterialToDTOConvertStrategy reinforcementConvertStrategy;
private HelperMaterialDTOSafetyFactorUpdateStrategy safetyFactorUpdateStrategy;
public StirrupByRebarToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger)
: base(referenceDictionary, traceLogger)
{
}
public override StirrupByRebarDTO GetNewItem(IStirrupByRebar source)
{
try
{
GetNewStirrup(source);
return NewItem;
}
catch (Exception ex)
{
TraceErrorByEntity(this, ex.Message);
throw;
}
}
private void GetNewStirrup(IStirrupByRebar source)
{
TraceLogger?.AddMessage($"Stirrup by density converting Id = {source.Id} has been started", TraceLogStatuses.Debug);
InitializeStrategies();
NewItem = new(source.Id);
updateStrategy.Update(NewItem, source);
NewItem.Material = reinforcementConvertStrategy.Convert(source.Material);
safetyFactorUpdateStrategy.Update(NewItem.Material, source.Material);
TraceLogger?.AddMessage($"Stirrup by density converting Id = {NewItem.Id} has been finished succesfully", TraceLogStatuses.Debug);
}
private void InitializeStrategies()
{
updateStrategy ??= new StirrupByRebarUpdateStrategy();
reinforcementConvertStrategy = new ReinforcementLibMaterialToDTOConvertStrategy()
{
ReferenceDictionary = ReferenceDictionary,
TraceLogger = TraceLogger
};
safetyFactorUpdateStrategy = new HelperMaterialDTOSafetyFactorUpdateStrategy(new MaterialSafetyFactorToDTOLogic());
}
}
}