Add work plane property saving
This commit is contained in:
@@ -66,7 +66,7 @@ namespace DataAccess.DTOs
|
||||
TraceLogger?.AddMessage($"Current version of StructureHelper does not suppurt saving interaction diagram calculator, {limitCalculator.Name} was ignored");
|
||||
}
|
||||
string errorString = ErrorStrings.ObjectTypeIsUnknownObj(source);
|
||||
TraceLogger.AddMessage(errorString, TraceLogStatuses.Error);
|
||||
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
|
||||
throw new StructureHelperException(errorString);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using DataAccess.DTOs.Converters;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.WorkPlanes;
|
||||
using StructureHelperLogics.Models.CrossSections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -12,23 +15,24 @@ namespace DataAccess.DTOs
|
||||
{
|
||||
public class CrossSectionFromDTOConvertStrategy : IConvertStrategy<ICrossSection, ICrossSection>
|
||||
{
|
||||
private readonly IConvertStrategy<ICrossSectionRepository, ICrossSectionRepository> convertStrategy;
|
||||
private IConvertStrategy<ICrossSectionRepository, ICrossSectionRepository> repositoryConvertStrategy;
|
||||
private IConvertStrategy<WorkPlaneProperty, WorkPlanePropertyDTO> workPlaneConvertStrategy;
|
||||
|
||||
public CrossSectionFromDTOConvertStrategy(IConvertStrategy<ICrossSectionRepository, ICrossSectionRepository> convertStrategy)
|
||||
public CrossSectionFromDTOConvertStrategy(IConvertStrategy<ICrossSectionRepository, ICrossSectionRepository> repositoryConvertStrategy,
|
||||
IConvertStrategy<WorkPlaneProperty, WorkPlanePropertyDTO> workPlaneConvertStrategy)
|
||||
{
|
||||
this.convertStrategy = convertStrategy;
|
||||
this.repositoryConvertStrategy = repositoryConvertStrategy;
|
||||
this.workPlaneConvertStrategy = workPlaneConvertStrategy;
|
||||
}
|
||||
|
||||
public CrossSectionFromDTOConvertStrategy() : this (new CrossSectionRepositoryFromDTOConvertStrategy())
|
||||
{
|
||||
|
||||
}
|
||||
public CrossSectionFromDTOConvertStrategy() { }
|
||||
|
||||
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
||||
public IShiftTraceLogger TraceLogger { get; set; }
|
||||
|
||||
public ICrossSection Convert(ICrossSection source)
|
||||
{
|
||||
InitializeStrategies();
|
||||
try
|
||||
{
|
||||
Check();
|
||||
@@ -42,20 +46,38 @@ namespace DataAccess.DTOs
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
repositoryConvertStrategy ??= new CrossSectionRepositoryFromDTOConvertStrategy(ReferenceDictionary, TraceLogger);
|
||||
workPlaneConvertStrategy ??= new WorkPlanePropertyFromDTOConvertStrategy(ReferenceDictionary,TraceLogger);
|
||||
}
|
||||
|
||||
private ICrossSection GetNewCrossSection(ICrossSection source)
|
||||
{
|
||||
TraceLogger?.AddMessage("Cross-Section converting is started", TraceLogStatuses.Service);
|
||||
CrossSection newItem = new(source.Id);
|
||||
convertStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||
convertStrategy.TraceLogger = TraceLogger;
|
||||
newItem.SectionRepository = GetNewCrossSectionRepository(source.SectionRepository);
|
||||
TraceLogger?.AddMessage("Cross-Section converting has been finished successfully", TraceLogStatuses.Service);
|
||||
if (source.WorkPlaneProperty is null)
|
||||
{
|
||||
TraceLogger?.AddMessage("Work plane properties is not found", TraceLogStatuses.Warning);
|
||||
newItem.WorkPlaneProperty = new WorkPlaneProperty(Guid.NewGuid());
|
||||
TraceLogger?.AddMessage("New work plane properties were generated", TraceLogStatuses.Debug);
|
||||
}
|
||||
else if (source.WorkPlaneProperty is WorkPlanePropertyDTO dto)
|
||||
{
|
||||
newItem.WorkPlaneProperty = workPlaneConvertStrategy.Convert(dto);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(source.WorkPlaneProperty));
|
||||
}
|
||||
return newItem;
|
||||
}
|
||||
|
||||
private ICrossSectionRepository GetNewCrossSectionRepository(ICrossSectionRepository source)
|
||||
{
|
||||
ICrossSectionRepository newItem = convertStrategy.Convert(source);
|
||||
ICrossSectionRepository newItem = repositoryConvertStrategy.Convert(source);
|
||||
TraceLogger?.AddMessage($"Object of type <<{newItem.GetType()}>> was obtained", TraceLogStatuses.Service);
|
||||
return newItem;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace DataAccess.DTOs.Converters
|
||||
try
|
||||
{
|
||||
Check();
|
||||
ICrossSectionNdmAnalysis newItem = GetCrossSectinNDMAnalysis(source);
|
||||
ICrossSectionNdmAnalysis newItem = GetCrossSectionNDMAnalysis(source);
|
||||
return newItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -46,7 +46,7 @@ namespace DataAccess.DTOs.Converters
|
||||
|
||||
}
|
||||
|
||||
private ICrossSectionNdmAnalysis GetCrossSectinNDMAnalysis(ICrossSectionNdmAnalysis source)
|
||||
private ICrossSectionNdmAnalysis GetCrossSectionNDMAnalysis(ICrossSectionNdmAnalysis source)
|
||||
{
|
||||
TraceLogger?.AddMessage("Cross-section sonverting is started");
|
||||
CrossSectionNdmAnalysis newItem = new(source.Id);
|
||||
|
||||
@@ -26,6 +26,10 @@ namespace DataAccess.DTOs
|
||||
private IHasPrimitivesProcessLogic primitivesProcessLogic = new HasPrimitivesProcessLogic(ConvertDirection.FromDTO);
|
||||
private IHasForceActionsProcessLogic actionsProcessLogic = new HasForceActionsProcessLogic(ConvertDirection.FromDTO);
|
||||
|
||||
public CrossSectionRepositoryFromDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger) : base(referenceDictionary, traceLogger)
|
||||
{
|
||||
}
|
||||
|
||||
public override CrossSectionRepository GetNewItem(ICrossSectionRepository source)
|
||||
{
|
||||
TraceLogger?.AddMessage("Cross-Section repository" + convertStarted);
|
||||
|
||||
@@ -19,10 +19,10 @@ namespace DataAccess.DTOs
|
||||
this.materialConvertStrategy = materialConvertStrategy;
|
||||
}
|
||||
|
||||
public CrossSectionRepositoryToDTOConvertStrategy() : this(
|
||||
new HeadMaterialToDTOConvertStrategy())
|
||||
public CrossSectionRepositoryToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger)
|
||||
{
|
||||
|
||||
ReferenceDictionary = referenceDictionary;
|
||||
TraceLogger = traceLogger;
|
||||
}
|
||||
|
||||
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
||||
@@ -31,6 +31,7 @@ namespace DataAccess.DTOs
|
||||
public CrossSectionRepositoryDTO Convert(ICrossSectionRepository source)
|
||||
{
|
||||
Check();
|
||||
InitializeStrategies();
|
||||
try
|
||||
{
|
||||
CrossSectionRepositoryDTO newItem = GetNewRepository(source);
|
||||
@@ -44,6 +45,11 @@ namespace DataAccess.DTOs
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
materialConvertStrategy ??= new HeadMaterialToDTOConvertStrategy();
|
||||
}
|
||||
|
||||
private CrossSectionRepositoryDTO GetNewRepository(ICrossSectionRepository source)
|
||||
{
|
||||
CrossSectionRepositoryDTO newItem = new()
|
||||
|
||||
@@ -1,49 +1,32 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using DataAccess.DTOs.Converters;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.WorkPlanes;
|
||||
using StructureHelperLogics.Models.CrossSections;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class CrossSectionToDTOConvertStrategy : IConvertStrategy<CrossSectionDTO, ICrossSection>
|
||||
public class CrossSectionToDTOConvertStrategy : ConvertStrategy<CrossSectionDTO, ICrossSection>
|
||||
{
|
||||
private IUpdateStrategy<ICrossSection> updateStrategy; //don't use since CrossSection does not have any properties
|
||||
private IConvertStrategy<CrossSectionRepositoryDTO, ICrossSectionRepository> convertRepositoryStrategy;
|
||||
private DictionaryConvertStrategy<CrossSectionRepositoryDTO, ICrossSectionRepository> convertLogic;
|
||||
private ICheckConvertLogic<CrossSectionDTO, ICrossSection> checkLogic;
|
||||
|
||||
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
||||
public IShiftTraceLogger TraceLogger { get; set; }
|
||||
private IConvertStrategy<WorkPlanePropertyDTO, IWorkPlaneProperty> workPlanePropertyConvertStrategy;
|
||||
|
||||
public CrossSectionToDTOConvertStrategy(IUpdateStrategy<ICrossSection> updateStrategy,
|
||||
IConvertStrategy<CrossSectionRepositoryDTO, ICrossSectionRepository> convertRepositoryStrategy,
|
||||
ICheckConvertLogic<CrossSectionDTO, ICrossSection> checkLogic)
|
||||
ICheckConvertLogic<CrossSectionDTO, ICrossSection> checkLogic,
|
||||
IConvertStrategy<WorkPlanePropertyDTO, IWorkPlaneProperty> workPlanePropertyConvertStrategy)
|
||||
{
|
||||
this.updateStrategy = updateStrategy;
|
||||
this.convertRepositoryStrategy = convertRepositoryStrategy;
|
||||
this.checkLogic = checkLogic;
|
||||
this.workPlanePropertyConvertStrategy = workPlanePropertyConvertStrategy;
|
||||
}
|
||||
|
||||
public CrossSectionToDTOConvertStrategy() : this(
|
||||
new CrossSectionUpdateStrategy(),
|
||||
new CrossSectionRepositoryToDTOConvertStrategy(),
|
||||
new CheckConvertLogic<CrossSectionDTO, ICrossSection>())
|
||||
{
|
||||
|
||||
}
|
||||
public CrossSectionToDTOConvertStrategy() { }
|
||||
|
||||
public CrossSectionDTO Convert(ICrossSection source)
|
||||
{
|
||||
Check();
|
||||
CrossSectionDTO newItem = new()
|
||||
{
|
||||
Id = source.Id
|
||||
};
|
||||
convertRepositoryStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||
convertRepositoryStrategy.TraceLogger = TraceLogger;
|
||||
convertLogic = new DictionaryConvertStrategy<CrossSectionRepositoryDTO, ICrossSectionRepository>(this, convertRepositoryStrategy);
|
||||
newItem.SectionRepository = convertLogic.Convert(source.SectionRepository);
|
||||
return newItem;
|
||||
}
|
||||
|
||||
private void Check()
|
||||
{
|
||||
@@ -51,5 +34,40 @@ namespace DataAccess.DTOs
|
||||
checkLogic.TraceLogger = TraceLogger;
|
||||
checkLogic.Check();
|
||||
}
|
||||
|
||||
public override CrossSectionDTO GetNewItem(ICrossSection source)
|
||||
{
|
||||
InitializeStrategies();
|
||||
try
|
||||
{
|
||||
GetNewItemBySource(source);
|
||||
return NewItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceErrorByEntity(this, ex.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
updateStrategy ??= new CrossSectionUpdateStrategy();
|
||||
convertRepositoryStrategy ??= new CrossSectionRepositoryToDTOConvertStrategy(ReferenceDictionary, TraceLogger);
|
||||
checkLogic ??= new CheckConvertLogic<CrossSectionDTO, ICrossSection>();
|
||||
workPlanePropertyConvertStrategy ??= new WorkPlanePropertyToDTOConvertStrategy(ReferenceDictionary, TraceLogger);
|
||||
}
|
||||
|
||||
private void GetNewItemBySource(ICrossSection source)
|
||||
{
|
||||
Check();
|
||||
NewItem = new()
|
||||
{
|
||||
Id = source.Id
|
||||
};
|
||||
convertLogic = new DictionaryConvertStrategy<CrossSectionRepositoryDTO, ICrossSectionRepository>(this, convertRepositoryStrategy);
|
||||
NewItem.SectionRepository = convertLogic.Convert(source.SectionRepository);
|
||||
NewItem.WorkPlaneProperty = workPlanePropertyConvertStrategy.Convert(source.WorkPlaneProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,10 @@ namespace DataAccess.DTOs
|
||||
public override FactoredCombinationPropertyDTO GetNewItem(IFactoredCombinationProperty source)
|
||||
{
|
||||
InitializeStrategies();
|
||||
TraceLogger.AddMessage($"Force factored combination property Id={source.Id} converting has been started");
|
||||
TraceLogger?.AddMessage($"Force factored combination property Id={source.Id} converting has been started");
|
||||
FactoredCombinationPropertyDTO newItem = new(source.Id);
|
||||
updateStrategy.Update(newItem, source);
|
||||
TraceLogger.AddMessage($"Force factored combination property Id={newItem.Id} converting has been finished");
|
||||
TraceLogger?.AddMessage($"Force factored combination property Id={newItem.Id} converting has been finished");
|
||||
return newItem;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace DataAccess.DTOs
|
||||
else
|
||||
{
|
||||
string errorString = ErrorStrings.ObjectTypeIsUnknownObj(source);
|
||||
TraceLogger.AddMessage(errorString, TraceLogStatuses.Error);
|
||||
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
|
||||
throw new StructureHelperException(errorString);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.WorkPlanes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs.Converters
|
||||
{
|
||||
public class WorkPlanePropertyFromDTOConvertStrategy : ConvertStrategy<WorkPlaneProperty, WorkPlanePropertyDTO>
|
||||
{
|
||||
private IUpdateStrategy<IWorkPlaneProperty> updateStrategy;
|
||||
public WorkPlanePropertyFromDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary,
|
||||
IShiftTraceLogger traceLogger)
|
||||
: base(referenceDictionary, traceLogger)
|
||||
{ }
|
||||
|
||||
public override WorkPlaneProperty GetNewItem(WorkPlanePropertyDTO source)
|
||||
{
|
||||
InitializeStrategies();
|
||||
try
|
||||
{
|
||||
GetNewItemBySource(source);
|
||||
return NewItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceErrorByEntity(this, ex.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void GetNewItemBySource(IWorkPlaneProperty source)
|
||||
{
|
||||
NewItem = new(source.Id);
|
||||
updateStrategy.Update(NewItem, source);
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
updateStrategy ??= new WorkPlanePropertyUpdateStrategy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.WorkPlanes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs.Converters
|
||||
{
|
||||
public class WorkPlanePropertyToDTOConvertStrategy : ConvertStrategy<WorkPlanePropertyDTO, IWorkPlaneProperty>
|
||||
{
|
||||
private IUpdateStrategy<IWorkPlaneProperty> updateStrategy;
|
||||
public WorkPlanePropertyToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary,
|
||||
IShiftTraceLogger traceLogger)
|
||||
{
|
||||
ReferenceDictionary = referenceDictionary;
|
||||
TraceLogger = traceLogger;
|
||||
}
|
||||
public override WorkPlanePropertyDTO GetNewItem(IWorkPlaneProperty source)
|
||||
{
|
||||
InitializeStrategies();
|
||||
try
|
||||
{
|
||||
GetNewItemBySource(source);
|
||||
return NewItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceErrorByEntity(this, ex.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void GetNewItemBySource(IWorkPlaneProperty source)
|
||||
{
|
||||
NewItem = new(source.Id);
|
||||
updateStrategy.Update(NewItem, source);
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
updateStrategy ??= new WorkPlanePropertyUpdateStrategy();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user