Add polygon to DTO convert strategy

This commit is contained in:
Evgeny Redikultsev
2025-10-19 17:37:17 +05:00
parent 5bf01bcb09
commit ed66da123c
64 changed files with 759 additions and 266 deletions

View File

@@ -70,7 +70,7 @@ namespace DataAccess.DTOs
private EllipseNdmPrimitiveDTO GetNewPrimitive(IEllipseNdmPrimitive source)
{
EllipseNdmPrimitiveDTO newItem = new() { Id = source.Id };
EllipseNdmPrimitiveDTO newItem = new(source.Id);
updateStrategy.Update(newItem, source);
newItem.NdmElement = ndmElementConvertStrategy.Convert(source.NdmElement);
newItem.RectangleShape = rectangleShapeConvertStrategy.Convert(source.Shape as IRectangleShape);

View File

@@ -55,8 +55,11 @@ namespace DataAccess.DTOs
headMaterialConvertStrategy.ReferenceDictionary = ReferenceDictionary;
headMaterialConvertStrategy.TraceLogger = TraceLogger;
var convertLogic = new DictionaryConvertStrategy<HeadMaterialDTO, IHeadMaterial>(this, headMaterialConvertStrategy);
var headMaterial = convertLogic.Convert(source.HeadMaterial);
newItem.HeadMaterial = headMaterial;
if (source.HeadMaterial != null)
{
var headMaterial = convertLogic.Convert(source.HeadMaterial);
newItem.HeadMaterial = headMaterial;
}
forceUpdateStrategy.Update(newItem.UsersPrestrain, source.UsersPrestrain);
(newItem.UsersPrestrain as ForceTupleDTO).Id = source.UsersPrestrain.Id;
forceUpdateStrategy.Update(newItem.AutoPrestrain, source.AutoPrestrain);

View File

@@ -11,6 +11,7 @@ namespace DataAccess.DTOs.Converters
private readonly IConvertStrategy<PointNdmPrimitiveDTO, IPointNdmPrimitive> pointConvertStrategy;
private readonly IConvertStrategy<EllipseNdmPrimitiveDTO, IEllipseNdmPrimitive> ellipseConvertStrategy;
private readonly IConvertStrategy<RectangleNdmPrimitiveDTO, IRectangleNdmPrimitive> rectangleConvertStrategy;
private IConvertStrategy<ShapeNdmPrimitiveDTO, IShapeNdmPrimitive> shapeConvertStrategy;
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
@@ -55,10 +56,21 @@ namespace DataAccess.DTOs.Converters
{
return ProcessRectangle(rectangle);
}
if (source is IShapeNdmPrimitive shape)
{
return ProcessShape(shape);
}
TraceLogger.AddMessage("Object type is unknown", TraceLogStatuses.Error);
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(source));
}
private ShapeNdmPrimitiveDTO ProcessShape(IShapeNdmPrimitive shape)
{
shapeConvertStrategy = new DictionaryConvertStrategy<ShapeNdmPrimitiveDTO,IShapeNdmPrimitive>(this, new ShapeNdmPrimitiveToDTOConvertStrategy(this));
ShapeNdmPrimitiveDTO shapeNdmPrimitiveDTO = shapeConvertStrategy.Convert(shape);
return shapeNdmPrimitiveDTO;
}
private RebarNdmPrimitiveDTO ProcessRebar(IRebarNdmPrimitive rebar)
{
rebarConvertStrategy.ReferenceDictionary = ReferenceDictionary;

View File

@@ -1,48 +0,0 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Shapes;
namespace DataAccess.DTOs
{
public class RectangleShapeToDTOConvertStrategy : ConvertStrategy<RectangleShapeDTO, IRectangleShape>
{
private IUpdateStrategy<IRectangleShape> updateStrategy;
public RectangleShapeToDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
{
}
public RectangleShapeToDTOConvertStrategy()
{
}
public override RectangleShapeDTO GetNewItem(IRectangleShape source)
{
try
{
GetNewRectangleShape(source);
return NewItem;
}
catch (Exception ex)
{
TraceErrorByEntity(this, ex.Message);
throw;
}
}
private void GetNewRectangleShape(IRectangleShape source)
{
TraceLogger?.AddMessage($"Rectangle shape converting Id = {source.Id} has been started", TraceLogStatuses.Debug);
InitializeStrategies();
NewItem = new(source.Id);
updateStrategy.Update(NewItem, source);
TraceLogger?.AddMessage($"Rectangle shape converting Id = {NewItem.Id} has been finished successfully", TraceLogStatuses.Debug);
}
private void InitializeStrategies()
{
updateStrategy ??= new RectangleShapeUpdateStrategy();
}
}
}

View File

@@ -0,0 +1,50 @@
using DataAccess.DTOs.Converters;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Shapes;
using StructureHelperLogics.NdmCalculations.Primitives;
namespace DataAccess.DTOs
{
public class ShapeNdmPrimitiveToDTOConvertStrategy : ConvertStrategy<ShapeNdmPrimitiveDTO, IShapeNdmPrimitive>
{
private IUpdateStrategy<IShapeNdmPrimitive> updateStrategy;
private IConvertStrategy<IShape, IShape> shapeConvertStrategy;
private IConvertStrategy<NdmElementDTO, INdmElement> ndmElementConvertStrategy;
private IConvertStrategy<Point2DDTO, IPoint2D> pointConvertStrategy;
private IConvertStrategy<VisualPropertyDTO, IVisualProperty> visualPropsConvertStrategy;
private IConvertStrategy<DivisionSizeDTO, IDivisionSize> divisionConvertStrategy;
public ShapeNdmPrimitiveToDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
{
}
public override ShapeNdmPrimitiveDTO GetNewItem(IShapeNdmPrimitive source)
{
ChildClass = this;
NewItem = new(source.Id);
InitializeStrategies();
updateStrategy.Update(NewItem, source);
updateChildProperties(source);
return NewItem;
}
private void updateChildProperties(IShapeNdmPrimitive source)
{
NewItem.SetShape(shapeConvertStrategy.Convert(source.Shape));
NewItem.NdmElement = ndmElementConvertStrategy.Convert(source.NdmElement);
NewItem.Center = pointConvertStrategy.Convert(source.Center);
NewItem.VisualProperty = visualPropsConvertStrategy.Convert(source.VisualProperty);
NewItem.DivisionSize = divisionConvertStrategy.Convert(source.DivisionSize);
}
private void InitializeStrategies()
{
updateStrategy = new ShapeNdmPrimitiveUpdateStrategy() { UpdateChildren = false };
shapeConvertStrategy = new DictionaryConvertStrategy<IShape, IShape>(this, new ShapeToDTOConvertStrategy(this));
ndmElementConvertStrategy = new NdmElementToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
pointConvertStrategy = new Point2DToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
visualPropsConvertStrategy = new VisualPropertyToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
divisionConvertStrategy = new DivisionSizeToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
}
}
}