Add materials converting from DTOs
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperLogics.Models.CrossSections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -13,7 +14,7 @@ namespace DataAccess.DTOs
|
||||
{
|
||||
public class VersionItemToDTOConvertStrategy : IConvertStrategy<ISaveable, ISaveable>
|
||||
{
|
||||
private const string Message = "Analysis type is";
|
||||
private const string AnalysisIs = "Analysis type is";
|
||||
private IConvertStrategy<CrossSectionDTO, ICrossSection> crossSectionConvertStrategy = new CrossSectionToDTOConvertStrategy();
|
||||
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
||||
public IShiftTraceLogger TraceLogger { get; set; }
|
||||
@@ -21,11 +22,25 @@ namespace DataAccess.DTOs
|
||||
|
||||
public ISaveable Convert(ISaveable source)
|
||||
{
|
||||
Check();
|
||||
ISaveable saveable;
|
||||
try
|
||||
{
|
||||
Check();
|
||||
return GetNewAnalysis(source);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
|
||||
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private ISaveable GetNewAnalysis(ISaveable source)
|
||||
{
|
||||
ISaveable newItem;
|
||||
if (source is ICrossSection crossSection)
|
||||
{
|
||||
saveable = ProcessCrossSection(crossSection);
|
||||
newItem = ProcessCrossSection(crossSection);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -33,12 +48,12 @@ namespace DataAccess.DTOs
|
||||
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
|
||||
throw new StructureHelperException(errorString);
|
||||
}
|
||||
return saveable;
|
||||
return newItem;
|
||||
}
|
||||
|
||||
private ISaveable ProcessCrossSection(ICrossSection crossSection)
|
||||
{
|
||||
TraceLogger?.AddMessage(Message + " Cross-Section Ndm Analysis", TraceLogStatuses.Debug);
|
||||
TraceLogger?.AddMessage(AnalysisIs + " Cross-Section Ndm Analysis", TraceLogStatuses.Debug);
|
||||
ISaveable saveable;
|
||||
crossSectionConvertStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||
crossSectionConvertStrategy.TraceLogger = TraceLogger;
|
||||
@@ -54,9 +69,7 @@ namespace DataAccess.DTOs
|
||||
|
||||
private void Check()
|
||||
{
|
||||
var checkLogic = new CheckConvertLogic<ISaveable, ISaveable>();
|
||||
checkLogic.ConvertStrategy = this;
|
||||
checkLogic.TraceLogger = TraceLogger;
|
||||
var checkLogic = new CheckConvertLogic<ISaveable, ISaveable>(this);
|
||||
checkLogic.Check();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user