Add EllipsePrimitive to DTO Converter

This commit is contained in:
Evgeny Redikultsev
2024-10-13 17:31:18 +05:00
parent 7e54aa0407
commit d16c0e1f79
54 changed files with 605 additions and 62 deletions

View File

@@ -8,6 +8,7 @@ using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Loggers;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.Models.Materials;
using StructureHelperLogics.NdmCalculations.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -21,6 +22,7 @@ namespace DataAccess.DTOs
private IConvertStrategy<HeadMaterialDTO, IHeadMaterial> materialConvertStrategy;
private IConvertStrategy<ForceCombinationByFactorDTO, IForceCombinationByFactor> forceCombinationByFactorConvertStrategy;
private IConvertStrategy<ForceCombinationListDTO, IForceCombinationList> forceCombinationListConvertStrategy;
private IConvertStrategy<EllipseNdmPrimitiveDTO, IEllipsePrimitive> ellipseConvertStrategy = new EllipsePrimitiveDTOConvertStrategy();
public CrossSectionRepositoryToDTOConvertStrategy(IConvertStrategy<HeadMaterialDTO, IHeadMaterial> materialConvertStrategy,
IConvertStrategy<ForceCombinationByFactorDTO, IForceCombinationByFactor> forceCombinationByFactorConvertStrategy,
@@ -66,12 +68,31 @@ namespace DataAccess.DTOs
Id = source.Id
};
List<IForceAction> forceActions = ProcessForceActions(source);
List<HeadMaterialDTO> materials = ProcessMaterials(source);
newItem.ForceActions.AddRange(forceActions);
List<IHeadMaterial> materials = ProcessMaterials(source);
newItem.HeadMaterials.AddRange(materials);
List<INdmPrimitive> primitives = ProcessPrimitives(source);
newItem.Primitives.AddRange(primitives);
return newItem;
}
private List<INdmPrimitive> ProcessPrimitives(ICrossSectionRepository source)
{
List<INdmPrimitive> primitives = new();
foreach (var item in source.Primitives)
{
if (item is IEllipsePrimitive ellipse)
{
ellipseConvertStrategy.ReferenceDictionary = ReferenceDictionary;
ellipseConvertStrategy.TraceLogger = TraceLogger;
INdmPrimitive ndmPrimitive;
ndmPrimitive = ellipseConvertStrategy.Convert(ellipse);
primitives.Add(ndmPrimitive);
}
}
return primitives;
}
private List<IForceAction> ProcessForceActions(ICrossSectionRepository source)
{
List<IForceAction> forceActions = new();
@@ -113,7 +134,7 @@ namespace DataAccess.DTOs
return forceCombination;
}
private List<HeadMaterialDTO> ProcessMaterials(ICrossSectionRepository source)
private List<IHeadMaterial> ProcessMaterials(ICrossSectionRepository source)
{
materialConvertStrategy.ReferenceDictionary = ReferenceDictionary;
materialConvertStrategy.TraceLogger = TraceLogger;
@@ -123,7 +144,7 @@ namespace DataAccess.DTOs
ConvertStrategy = materialConvertStrategy,
TraceLogger = TraceLogger
};
List<HeadMaterialDTO> materials = new();
List<IHeadMaterial> materials = new();
foreach (var item in source.HeadMaterials)
{
materials.Add(convertLogic.Convert(item));

View File

@@ -0,0 +1,51 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Loggers;
using StructureHelperLogics.NdmCalculations.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class DivisionSizeToDTOConvertStrategy : IConvertStrategy<DivisionSizeDTO, IDivisionSize>
{
private IUpdateStrategy<IDivisionSize> updateStrategy;
public DivisionSizeToDTOConvertStrategy(IUpdateStrategy<IDivisionSize> updateStrategy)
{
this.updateStrategy = updateStrategy;
}
public DivisionSizeToDTOConvertStrategy() : this (new DivisionSizeUpdateStrategy())
{
}
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public DivisionSizeDTO Convert(IDivisionSize source)
{
try
{
return GetNewDivisionSize(source);
}
catch (Exception ex)
{
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Debug);
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
throw;
}
}
private DivisionSizeDTO GetNewDivisionSize(IDivisionSize source)
{
DivisionSizeDTO newItem = new() { Id = source.Id };
updateStrategy.Update(newItem, source);
return newItem;
}
}
}

View File

@@ -0,0 +1,105 @@
using DataAccess.DTOs.Converters;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Loggers;
using StructureHelperCommon.Models.Shapes;
using StructureHelperLogics.NdmCalculations.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class EllipsePrimitiveDTOConvertStrategy : IConvertStrategy<EllipseNdmPrimitiveDTO, IEllipsePrimitive>
{
private IUpdateStrategy<IEllipsePrimitive> updateStrategy;
private IConvertStrategy<RectangleShapeDTO, IRectangleShape> rectangleShapeConvertStrategy;
private IConvertStrategy<NdmElementDTO, INdmElement> ndmElementConvertStrategy;
private IConvertStrategy<Point2DDTO, IPoint2D> pointConvertStrategy;
private IConvertStrategy<VisualPropertyDTO, IVisualProperty> visualPropsConvertStrategy;
private IConvertStrategy<DivisionSizeDTO, IDivisionSize> divisionConvertStrategy;
public EllipsePrimitiveDTOConvertStrategy(
IUpdateStrategy<IEllipsePrimitive> updateStrategy,
IConvertStrategy<RectangleShapeDTO, IRectangleShape> rectangleShapeConvertStrategy,
IConvertStrategy<NdmElementDTO, INdmElement> ndmElementConvertStrategy,
IConvertStrategy<Point2DDTO, IPoint2D> pointConvertStrategy,
IConvertStrategy<VisualPropertyDTO, IVisualProperty> visualPropsConvertStrategy,
IConvertStrategy<DivisionSizeDTO, IDivisionSize> divisionConvertStrategy)
{
this.updateStrategy = updateStrategy;
this.rectangleShapeConvertStrategy = rectangleShapeConvertStrategy;
this.ndmElementConvertStrategy = ndmElementConvertStrategy;
this.pointConvertStrategy = pointConvertStrategy;
this.visualPropsConvertStrategy = visualPropsConvertStrategy;
this.divisionConvertStrategy = divisionConvertStrategy;
}
public EllipsePrimitiveDTOConvertStrategy() : this(
new EllipsePrimitiveUpdateStrategy(),
new RectangleShapeToDTOConvertStrategy(),
new NdmElementDTOConvertStrategy(),
new Point2DToDTOConvertStrategy(),
new VisualPropertyToDTOConvertStrategy(),
new DivisionSizeToDTOConvertStrategy()
)
{
}
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public EllipseNdmPrimitiveDTO Convert(IEllipsePrimitive source)
{
try
{
Check();
PrepareStrategies();
return GetNewEllipsePrimitive(source);
}
catch (Exception ex)
{
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Debug);
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
throw;
}
}
private EllipseNdmPrimitiveDTO GetNewEllipsePrimitive(IEllipsePrimitive source)
{
EllipseNdmPrimitiveDTO newItem = new() { Id = source.Id };
updateStrategy.Update(newItem, source);
newItem.NdmElement = ndmElementConvertStrategy.Convert(source.NdmElement);
newItem.RectangleShape = rectangleShapeConvertStrategy.Convert(source.Shape as IRectangleShape);
newItem.Center = pointConvertStrategy.Convert(source.Center);
newItem.VisualProperty = visualPropsConvertStrategy.Convert(source.VisualProperty);
newItem.DivisionSize = divisionConvertStrategy.Convert(source.DivisionSize);
return newItem;
}
private void PrepareStrategies()
{
rectangleShapeConvertStrategy.ReferenceDictionary =
ndmElementConvertStrategy.ReferenceDictionary =
pointConvertStrategy.ReferenceDictionary =
visualPropsConvertStrategy.ReferenceDictionary =
divisionConvertStrategy.ReferenceDictionary =
ReferenceDictionary;
rectangleShapeConvertStrategy.TraceLogger =
ndmElementConvertStrategy.TraceLogger =
pointConvertStrategy.TraceLogger =
visualPropsConvertStrategy.TraceLogger =
divisionConvertStrategy.TraceLogger =
TraceLogger;
}
private void Check()
{
var checkLogic = new CheckConvertLogic<EllipseNdmPrimitiveDTO, IEllipsePrimitive>(this);
checkLogic.Check();
}
}
}

View File

@@ -0,0 +1,71 @@
using DataAccess.DTOs.Converters;
using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Loggers;
using StructureHelperLogics.NdmCalculations.Primitives;
using StructureHelperLogics.NdmCalculations.Primitives.Logics;
namespace DataAccess.DTOs
{
public class NdmElementDTOConvertStrategy : IConvertStrategy<NdmElementDTO, INdmElement>
{
private IUpdateStrategy<INdmElement> updateStrategy;
private IConvertStrategy<HeadMaterialDTO, IHeadMaterial> headMaterialConvertStrategy;
private IUpdateStrategy<IForceTuple> forceUpdateStrategy = new ForceTupleUpdateStrategy();
public NdmElementDTOConvertStrategy(
IUpdateStrategy<INdmElement> updateStrategy,
IConvertStrategy<HeadMaterialDTO, IHeadMaterial> headMaterialConvertStrategy)
{
this.updateStrategy = updateStrategy;
this.headMaterialConvertStrategy = headMaterialConvertStrategy;
}
public NdmElementDTOConvertStrategy() : this(
new NdmElementUpdateStrategy(),
new HeadMaterialToDTOConvertStrategy())
{
}
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public NdmElementDTO Convert(INdmElement source)
{
Check();
try
{
return GenNewNdmElementDTO(source);
}
catch (Exception ex)
{
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Debug);
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
throw;
}
}
private NdmElementDTO GenNewNdmElementDTO(INdmElement source)
{
NdmElementDTO newItem = new() { Id = source.Id };
updateStrategy.Update(newItem, source);
headMaterialConvertStrategy.ReferenceDictionary = ReferenceDictionary;
headMaterialConvertStrategy.TraceLogger = TraceLogger;
var convertLogic = new DictionaryConvertStrategy<HeadMaterialDTO, IHeadMaterial>(this, headMaterialConvertStrategy);
var headMaterial = convertLogic.Convert(source.HeadMaterial);
newItem.HeadMaterial = headMaterial;
forceUpdateStrategy.Update(newItem.UsersPrestrain, source.UsersPrestrain);
forceUpdateStrategy.Update(newItem.AutoPrestrain, source.AutoPrestrain);
return newItem;
}
private void Check()
{
var checkLogic = new CheckConvertLogic<NdmElementDTO, INdmElement>(this);
checkLogic.Check();
}
}
}

View File

@@ -0,0 +1,31 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Shapes;
namespace DataAccess.DTOs
{
public class RectangleShapeToDTOConvertStrategy : IConvertStrategy<RectangleShapeDTO, IRectangleShape>
{
private IUpdateStrategy<IRectangleShape> updateStrategy;
public RectangleShapeToDTOConvertStrategy(IUpdateStrategy<IRectangleShape> updateStrategy)
{
this.updateStrategy = updateStrategy;
}
public RectangleShapeToDTOConvertStrategy() : this (new RectangleShapeUpdateStrategy())
{
}
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public RectangleShapeDTO Convert(IRectangleShape source)
{
RectangleShapeDTO newItem = new() { Id = source.Id};
updateStrategy.Update(newItem, source);
return newItem;
}
}
}

View File

@@ -1,6 +1,7 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses;
using StructureHelperCommon.Models.Loggers;
using StructureHelperLogics.Models.CrossSections;
using System;
using System.Collections.Generic;
@@ -31,6 +32,21 @@ namespace DataAccess.DTOs
public VersionProcessorDTO Convert(IVersionProcessor source)
{
Check();
try
{
VersionProcessorDTO versionProcessorDTO = GetNewVersionProcessor(source);
return versionProcessorDTO;
}
catch (Exception ex)
{
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Debug);
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
throw;
}
}
private VersionProcessorDTO GetNewVersionProcessor(IVersionProcessor source)
{
VersionProcessorDTO newItem = new()
{
Id = source.Id
@@ -44,6 +60,7 @@ namespace DataAccess.DTOs
}
return newItem;
}
private void Check()
{
checkLogic = new CheckConvertLogic<VersionProcessorDTO, IVersionProcessor>(this);

View File

@@ -0,0 +1,45 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Loggers;
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 VisualPropertyToDTOConvertStrategy : IConvertStrategy<VisualPropertyDTO, IVisualProperty>
{
private IUpdateStrategy<IVisualProperty> updateStrategy;
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public VisualPropertyToDTOConvertStrategy(IUpdateStrategy<IVisualProperty> updateStrategy)
{
this.updateStrategy = updateStrategy;
}
public VisualPropertyToDTOConvertStrategy() : this (new VisualPropsUpdateStrategy())
{
}
public VisualPropertyDTO Convert(IVisualProperty source)
{
try
{
VisualPropertyDTO newItem = new() { Id = source.Id };
updateStrategy.Update(newItem, source);
return newItem;
}
catch (Exception ex)
{
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Debug);
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
throw;
}
}
}
}