Add polygon to DTO convert strategy
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
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 CircleShapeFromDTOConvertStrategy : ConvertStrategy<CircleShape, CircleShapeDTO>
|
||||
{
|
||||
private IUpdateStrategy<ICircleShape> updateStrategy;
|
||||
|
||||
public CircleShapeFromDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
|
||||
{
|
||||
}
|
||||
|
||||
public override CircleShape GetNewItem(CircleShapeDTO source)
|
||||
{
|
||||
ChildClass = this;
|
||||
ChildClass = this;
|
||||
updateStrategy ??= new CircleShapeUpdateStrategy();
|
||||
NewItem = new CircleShape(source.Id);
|
||||
updateStrategy.Update(NewItem, source);
|
||||
return NewItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class CircleShapeToDTOConvertStrategy : ConvertStrategy<CircleShapeDTO, ICircleShape>
|
||||
{
|
||||
private IUpdateStrategy<ICircleShape> updateStrategy;
|
||||
|
||||
public CircleShapeToDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
|
||||
{
|
||||
}
|
||||
|
||||
public override CircleShapeDTO GetNewItem(ICircleShape source)
|
||||
{
|
||||
ChildClass = this;
|
||||
updateStrategy ??= new CircleShapeUpdateStrategy();
|
||||
NewItem = new(source.Id);
|
||||
updateStrategy.Update(NewItem, source);
|
||||
return NewItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
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 LinePolygonToDTOConvertStrategy : ConvertStrategy<LinePolygonShapeDTO, ILinePolygonShape>
|
||||
{
|
||||
private IUpdateStrategy<ILinePolygonShape> updateStrategy;
|
||||
private IConvertStrategy<VertexDTO, IVertex> vertexConvertStrategy;
|
||||
|
||||
public LinePolygonToDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
|
||||
{
|
||||
}
|
||||
|
||||
public override LinePolygonShapeDTO GetNewItem(ILinePolygonShape source)
|
||||
{
|
||||
ChildClass = this;
|
||||
NewItem = new(source.Id);
|
||||
updateStrategy = new LinePolygonShapeUpdateStrategy() { UpdateChildren = false };
|
||||
vertexConvertStrategy = new VertexToDTOConvertStrategy(this);
|
||||
updateStrategy.Update(NewItem, source);
|
||||
NewItem.Clear();
|
||||
foreach (var item in source.Vertices)
|
||||
{
|
||||
VertexDTO newVertex = vertexConvertStrategy.Convert(item);
|
||||
NewItem.AddVertex(newVertex);
|
||||
}
|
||||
return NewItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models;
|
||||
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 Point2DFromDTOConvertStrategy : ConvertStrategy<Point2D, Point2DDTO>
|
||||
{
|
||||
private IUpdateStrategy<IPoint2D> updateStrategy;
|
||||
|
||||
public Point2DFromDTOConvertStrategy(IUpdateStrategy<IPoint2D> updateStrategy)
|
||||
{
|
||||
this.updateStrategy = updateStrategy;
|
||||
}
|
||||
|
||||
public Point2DFromDTOConvertStrategy() : this (new Point2DUpdateStrategy())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override Point2D GetNewItem(Point2DDTO source)
|
||||
{
|
||||
TraceLogger?.AddMessage("Point 2D converting has been started");
|
||||
try
|
||||
{
|
||||
Point2D newItem = GetNewItemBySource(source);
|
||||
TraceLogger?.AddMessage("Point 2D converting has been finished");
|
||||
return newItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Logic: {LoggerStrings.LogicType(this)} made error: {ex.Message}", TraceLogStatuses.Error);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private Point2D GetNewItemBySource(Point2DDTO source)
|
||||
{
|
||||
Point2D newItem = new(source.Id);
|
||||
updateStrategy.Update(newItem, source);
|
||||
return newItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
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 Point2DToDTOConvertStrategy : IConvertStrategy<Point2DDTO, IPoint2D>
|
||||
{
|
||||
private IUpdateStrategy<IPoint2D> updateStrategy;
|
||||
|
||||
public Point2DToDTOConvertStrategy(IUpdateStrategy<IPoint2D> updateStrategy)
|
||||
{
|
||||
this.updateStrategy = updateStrategy;
|
||||
}
|
||||
|
||||
public Point2DToDTOConvertStrategy() : this (new Point2DUpdateStrategy())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary {get; set; }
|
||||
public IShiftTraceLogger TraceLogger { get; set; }
|
||||
|
||||
public Point2DDTO Convert(IPoint2D source)
|
||||
{
|
||||
try
|
||||
{
|
||||
Point2DDTO 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
internal class RectangleShapeFromDTOConvertStrategy : ConvertStrategy<RectangleShape, RectangleShapeDTO>
|
||||
{
|
||||
private IUpdateStrategy<IRectangleShape> updateStrategy;
|
||||
|
||||
public RectangleShapeFromDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
|
||||
{
|
||||
}
|
||||
|
||||
public override RectangleShape GetNewItem(RectangleShapeDTO source)
|
||||
{
|
||||
InitializeStrategies();
|
||||
NewItem = new(source.Id);
|
||||
updateStrategy.Update(NewItem, source);
|
||||
return NewItem;
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
updateStrategy ??= new RectangleShapeUpdateStrategy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
internal class ShapeFromDTOConvertStrategy : ConvertStrategy<IShape, IShape>
|
||||
{
|
||||
private IConvertStrategy<RectangleShape, RectangleShapeDTO> rectangleConvertStrategy;
|
||||
private IConvertStrategy<CircleShape, CircleShapeDTO> circleConvertStrategy;
|
||||
|
||||
public ShapeFromDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
|
||||
{
|
||||
}
|
||||
|
||||
public override IShape GetNewItem(IShape source)
|
||||
{
|
||||
ChildClass = this;
|
||||
if (source is RectangleShapeDTO rectangleShapeDTO)
|
||||
{
|
||||
rectangleConvertStrategy ??= new DictionaryConvertStrategy<RectangleShape, RectangleShapeDTO>
|
||||
(this, new RectangleShapeFromDTOConvertStrategy(this));
|
||||
NewItem = rectangleConvertStrategy.Convert(rectangleShapeDTO);
|
||||
}
|
||||
else if (source is CircleShapeDTO circleShapeDTO)
|
||||
{
|
||||
circleConvertStrategy ??= new DictionaryConvertStrategy<CircleShape, CircleShapeDTO>
|
||||
(this, new CircleShapeFromDTOConvertStrategy(this));
|
||||
NewItem = circleConvertStrategy.Convert(circleShapeDTO);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(source) + ": shape is unknown");
|
||||
}
|
||||
return NewItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class ShapeToDTOConvertStrategy : ConvertStrategy<IShape, IShape>
|
||||
{
|
||||
private IConvertStrategy<RectangleShapeDTO, IRectangleShape> rectangleConvertStrategy;
|
||||
private IConvertStrategy<CircleShapeDTO, ICircleShape> circleConvertStrategy;
|
||||
private IConvertStrategy<LinePolygonShapeDTO, ILinePolygonShape> linePolygonToDTOConvertStrategy;
|
||||
|
||||
public ShapeToDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
|
||||
{
|
||||
}
|
||||
|
||||
public override IShape GetNewItem(IShape source)
|
||||
{
|
||||
ChildClass = this;
|
||||
GetNewShape(source);
|
||||
return NewItem;
|
||||
}
|
||||
|
||||
private void GetNewShape(IShape source)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Shape converting Id = {source.Id} has been started", TraceLogStatuses.Debug);
|
||||
if (source is IRectangleShape rectangle)
|
||||
{
|
||||
ProcessRectangle(rectangle);
|
||||
}
|
||||
else if (source is ICircleShape circle)
|
||||
{
|
||||
ProcessCircle(circle);
|
||||
}
|
||||
else if (source is ILinePolygonShape linePolygon)
|
||||
{
|
||||
ProcessLinePolygon(linePolygon);
|
||||
}
|
||||
else
|
||||
{
|
||||
string errorString = ErrorStrings.ObjectTypeIsUnknownObj(source) + ": shape type";
|
||||
throw new StructureHelperException(errorString);
|
||||
}
|
||||
TraceLogger?.AddMessage($"Shape converting Id = {NewItem.Id} has been has been finished successfully", TraceLogStatuses.Debug);
|
||||
}
|
||||
|
||||
private void ProcessLinePolygon(ILinePolygonShape linePolygon)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Shape is line polygon", TraceLogStatuses.Debug);
|
||||
linePolygonToDTOConvertStrategy = new DictionaryConvertStrategy<LinePolygonShapeDTO, ILinePolygonShape>(this, new LinePolygonToDTOConvertStrategy(this));
|
||||
NewItem = linePolygonToDTOConvertStrategy.Convert(linePolygon);
|
||||
}
|
||||
|
||||
private void ProcessCircle(ICircleShape circle)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Shape is circle", TraceLogStatuses.Debug);
|
||||
circleConvertStrategy = new DictionaryConvertStrategy<CircleShapeDTO, ICircleShape>
|
||||
(this, new CircleShapeToDTOConvertStrategy(this));
|
||||
NewItem = circleConvertStrategy.Convert(circle);
|
||||
}
|
||||
|
||||
private void ProcessRectangle(IRectangleShape rectangle)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Shape is rectangle", TraceLogStatuses.Debug);
|
||||
rectangleConvertStrategy = new DictionaryConvertStrategy<RectangleShapeDTO, IRectangleShape>
|
||||
(this, new RectangleShapeToDTOConvertStrategy(this));
|
||||
NewItem = rectangleConvertStrategy.Convert(rectangle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class VertexToDTOConvertStrategy : ConvertStrategy<VertexDTO, IVertex>
|
||||
{
|
||||
private IUpdateStrategy<IVertex> updateStrategy;
|
||||
private IConvertStrategy<Point2DDTO, IPoint2D> pointConvertStrategy;
|
||||
|
||||
public VertexToDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
|
||||
{
|
||||
}
|
||||
|
||||
public override VertexDTO GetNewItem(IVertex source)
|
||||
{
|
||||
ChildClass = this;
|
||||
NewItem = new(source.Id);
|
||||
updateStrategy = new VertexUpdateStrategy() { UpdateChildren = false };
|
||||
pointConvertStrategy = new Point2DToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
|
||||
updateStrategy.Update(NewItem, source);
|
||||
NewItem.Point = pointConvertStrategy.Convert(source.Point);
|
||||
return NewItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user