Add project ConvertFromStrategy
This commit is contained in:
79
DataAccess/DTOs/Converters/AnalysisFromDTOConvertStrategy.cs
Normal file
79
DataAccess/DTOs/Converters/AnalysisFromDTOConvertStrategy.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Analyses;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperLogic.Models.Analyses;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces.LimitCurve;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DataAccess.DTOs.Converters
|
||||
{
|
||||
public class AnalysisFromDTOConvertStrategy : IConvertStrategy<IAnalysis, IAnalysis>
|
||||
{
|
||||
private const string Message = "Analysis type is";
|
||||
private IConvertStrategy<ICrossSectionNdmAnalysis, ICrossSectionNdmAnalysis> convertCrossSectionNdmAnalysisStrategy = new CrossSectionNdmAnalysisFromDTOConvertStrategy();
|
||||
|
||||
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
||||
public IShiftTraceLogger TraceLogger { get; set; }
|
||||
|
||||
public IAnalysis Convert(IAnalysis source)
|
||||
{
|
||||
Check();
|
||||
try
|
||||
{
|
||||
IAnalysis analysis = GetAnalysis(source);
|
||||
return analysis;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
|
||||
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private IAnalysis GetAnalysis(IAnalysis source)
|
||||
{
|
||||
IAnalysis analysis;
|
||||
if (source is ICrossSectionNdmAnalysis crossSectionNdmAnalysis)
|
||||
{
|
||||
analysis = GetCrossSectionNdmAnalysis(crossSectionNdmAnalysis);
|
||||
}
|
||||
else
|
||||
{
|
||||
string errorString = ErrorStrings.ObjectTypeIsUnknownObj(source);
|
||||
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
|
||||
throw new StructureHelperException(errorString);
|
||||
}
|
||||
foreach (var item in source.VersionProcessor.Versions)
|
||||
{
|
||||
//to do
|
||||
}
|
||||
|
||||
return analysis;
|
||||
}
|
||||
|
||||
private ICrossSectionNdmAnalysis GetCrossSectionNdmAnalysis(ICrossSectionNdmAnalysis source)
|
||||
{
|
||||
TraceLogger?.AddMessage(Message + " Cross-Section Ndm Analysis", TraceLogStatuses.Debug);
|
||||
convertCrossSectionNdmAnalysisStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||
convertCrossSectionNdmAnalysisStrategy.TraceLogger = TraceLogger;
|
||||
var convertLogic = new DictionaryConvertStrategy<ICrossSectionNdmAnalysis, ICrossSectionNdmAnalysis>(this, convertCrossSectionNdmAnalysisStrategy);
|
||||
ICrossSectionNdmAnalysis crossSectionNdmAnalysis = convertLogic.Convert(source);
|
||||
return crossSectionNdmAnalysis;
|
||||
}
|
||||
|
||||
private void Check()
|
||||
{
|
||||
var checkLogic = new CheckConvertLogic<IAnalysis, IAnalysis>(this);
|
||||
checkLogic.Check();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ namespace DataAccess.DTOs.Converters
|
||||
}
|
||||
foreach (var item in source.VersionProcessor.Versions)
|
||||
{
|
||||
|
||||
//to do
|
||||
}
|
||||
return analysis;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperLogic.Models.Analyses;
|
||||
using StructureHelperLogics.Models.Analyses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs.Converters
|
||||
{
|
||||
public class CrossSectionNdmAnalysisFromDTOConvertStrategy : IConvertStrategy<ICrossSectionNdmAnalysis, ICrossSectionNdmAnalysis>
|
||||
{
|
||||
private IUpdateStrategy<ICrossSectionNdmAnalysis> updateStrategy = new CrossSectionNdmAnalysisUpdateStrategy();
|
||||
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
||||
public IShiftTraceLogger TraceLogger { get; set; }
|
||||
|
||||
public ICrossSectionNdmAnalysis Convert(ICrossSectionNdmAnalysis source)
|
||||
{
|
||||
try
|
||||
{
|
||||
CrossSectionNdmAnalysis newItem = GetCrossSectinNDMAnalysis(source);
|
||||
return newItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
|
||||
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private CrossSectionNdmAnalysis GetCrossSectinNDMAnalysis(ICrossSectionNdmAnalysis source)
|
||||
{
|
||||
CrossSectionNdmAnalysis newItem = new(source.Id);
|
||||
updateStrategy.Update(newItem, source);
|
||||
return newItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,8 @@ namespace DataAccess.DTOs.Converters
|
||||
this.TraceLogger = traceLogger;
|
||||
}
|
||||
|
||||
public CrossSectionNdmAnalysisToDTOConvertStrategy() : this(new CrossSectionNdmAnalysisUpdateStrategy(),
|
||||
public CrossSectionNdmAnalysisToDTOConvertStrategy() : this(
|
||||
new CrossSectionNdmAnalysisUpdateStrategy(),
|
||||
new VersionProcessorToDTOConvertStrategy(),
|
||||
null)
|
||||
{
|
||||
@@ -55,9 +56,7 @@ namespace DataAccess.DTOs.Converters
|
||||
|
||||
private void Check()
|
||||
{
|
||||
var checkLogic = new CheckConvertLogic<CrossSectionNdmAnalysisDTO, ICrossSectionNdmAnalysis>();
|
||||
checkLogic.ConvertStrategy = this;
|
||||
checkLogic.TraceLogger = TraceLogger;
|
||||
var checkLogic = new CheckConvertLogic<CrossSectionNdmAnalysisDTO, ICrossSectionNdmAnalysis>(this);
|
||||
checkLogic.Check();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace DataAccess.DTOs
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Debug);
|
||||
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
|
||||
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
|
||||
throw;
|
||||
}
|
||||
|
||||
72
DataAccess/DTOs/Converters/ProjectFromDTOConvertStrategy.cs
Normal file
72
DataAccess/DTOs/Converters/ProjectFromDTOConvertStrategy.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Analyses;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Projects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class ProjectFromDTOConvertStrategy : IConvertStrategy<Project, ProjectDTO>
|
||||
{
|
||||
private IUpdateStrategy<IProject> updateStrategy;
|
||||
private IConvertStrategy<IVisualAnalysis, IVisualAnalysis> visualAnalysisConvertStrategy = new VisualAnaysisFromDTOConvertStrategy();
|
||||
|
||||
public ProjectFromDTOConvertStrategy(IUpdateStrategy<IProject> updateStrategy)
|
||||
{
|
||||
this.updateStrategy = updateStrategy;
|
||||
}
|
||||
|
||||
public ProjectFromDTOConvertStrategy() : this (new ProjectUpdateStrategy())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
||||
public IShiftTraceLogger TraceLogger { get; set; }
|
||||
|
||||
public Project Convert(ProjectDTO source)
|
||||
{
|
||||
Check();
|
||||
TraceLogger?.AddMessage("Converting project is started", TraceLogStatuses.Info);
|
||||
try
|
||||
{
|
||||
Project newItem = GetProject(source);
|
||||
return newItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
|
||||
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private Project GetProject(ProjectDTO source)
|
||||
{
|
||||
Project newItem = new();
|
||||
updateStrategy.Update(newItem, source);
|
||||
visualAnalysisConvertStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||
visualAnalysisConvertStrategy.TraceLogger = TraceLogger;
|
||||
var convertLogic = new DictionaryConvertStrategy<IVisualAnalysis, IVisualAnalysis>(this, visualAnalysisConvertStrategy);
|
||||
newItem.VisualAnalyses.Clear();
|
||||
foreach (var item in source.VisualAnalyses)
|
||||
{
|
||||
var visualAnalysis = convertLogic.Convert(item);
|
||||
newItem.VisualAnalyses.Add(visualAnalysis);
|
||||
}
|
||||
TraceLogger?.AddMessage("Converting project has completed succesfully", TraceLogStatuses.Info);
|
||||
return newItem;
|
||||
}
|
||||
|
||||
private void Check()
|
||||
{
|
||||
var checkLogic = new CheckConvertLogic<Project, ProjectDTO>(this);
|
||||
checkLogic.Check();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Analyses;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Projects;
|
||||
using StructureHelperLogic.Models.Analyses;
|
||||
using System;
|
||||
@@ -32,13 +33,28 @@ namespace DataAccess.DTOs
|
||||
public VisualAnalysisDTO Convert(IVisualAnalysis source)
|
||||
{
|
||||
Check();
|
||||
try
|
||||
{
|
||||
VisualAnalysisDTO visualAnalysisDTO = GetNewAnalysis(source);
|
||||
return visualAnalysisDTO;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
|
||||
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private VisualAnalysisDTO GetNewAnalysis(IVisualAnalysis source)
|
||||
{
|
||||
VisualAnalysisDTO visualAnalysisDTO = new()
|
||||
{
|
||||
Id = source.Id
|
||||
};
|
||||
convertStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||
convertStrategy.TraceLogger = TraceLogger;
|
||||
var convertLogic = new DictionaryConvertStrategy<IAnalysis, IAnalysis>()
|
||||
var convertLogic = new DictionaryConvertStrategy<IAnalysis, IAnalysis>(this, convertStrategy)
|
||||
{
|
||||
ReferenceDictionary = ReferenceDictionary,
|
||||
ConvertStrategy = convertStrategy,
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
using DataAccess.DTOs.Converters;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Analyses;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperLogic.Models.Analyses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class VisualAnaysisFromDTOConvertStrategy : IConvertStrategy<IVisualAnalysis, IVisualAnalysis>
|
||||
{
|
||||
private IConvertStrategy<IAnalysis, IAnalysis> analysisConvertStrategy = new AnalysisFromDTOConvertStrategy();
|
||||
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
||||
public IShiftTraceLogger TraceLogger { get; set; }
|
||||
|
||||
public IVisualAnalysis Convert(IVisualAnalysis source)
|
||||
{
|
||||
Check();
|
||||
try
|
||||
{
|
||||
VisualAnalysis newItem = GetAnalysis(source);
|
||||
return newItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
|
||||
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private VisualAnalysis GetAnalysis(IVisualAnalysis source)
|
||||
{
|
||||
analysisConvertStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||
analysisConvertStrategy.TraceLogger = TraceLogger;
|
||||
IAnalysis analysis = analysisConvertStrategy.Convert(source.Analysis);
|
||||
VisualAnalysis newItem = new(source.Id, analysis);
|
||||
TraceLogger?.AddMessage($"Visual Analysis was obtained succesfully", TraceLogStatuses.Debug);
|
||||
return newItem;
|
||||
}
|
||||
|
||||
private void Check()
|
||||
{
|
||||
var checkLogic = new CheckConvertLogic<IVisualAnalysis, IVisualAnalysis>(this);
|
||||
checkLogic.Check();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace DataAccess.DTOs.DTOEntities
|
||||
public class AccuracyDTO : IAccuracy
|
||||
{
|
||||
[JsonProperty("Id")]
|
||||
public Guid Id { get; set; }
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
[JsonProperty("IterationAccuracy")]
|
||||
public double IterationAccuracy { get; set; }
|
||||
[JsonProperty("MaxIterationCount")]
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace DataAccess.DTOs
|
||||
{
|
||||
const MaterialTypes materialType = MaterialTypes.Concrete;
|
||||
|
||||
|
||||
[JsonProperty("Id")]
|
||||
public Guid Id { get; set; }
|
||||
[JsonProperty("RelativeHumidity")]
|
||||
@@ -29,7 +30,11 @@ namespace DataAccess.DTOs
|
||||
[JsonProperty("MaterialEntityId")]
|
||||
public Guid MaterialEntityId
|
||||
{
|
||||
get => MaterialEntity.Id;
|
||||
get
|
||||
{
|
||||
return MaterialEntity.Id;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
MaterialEntity = ProgramSetting.MaterialRepository.Repository.Single(x => x.Id == value);
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace DataAccess.DTOs
|
||||
public class CrackCalculatorInputDataDTO : ICrackCalculatorInputData
|
||||
{
|
||||
[JsonProperty("Id")]
|
||||
public Guid Id { get; set; }
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
[JsonProperty("ForceActions")]
|
||||
public List<IForceAction> ForceActions { get; set; } = new();
|
||||
[JsonProperty("ForcePrimitives")]
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Newtonsoft.Json;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Analyses;
|
||||
using StructureHelperLogic.Models.Analyses;
|
||||
using StructureHelperLogics.Models.Analyses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -22,7 +24,7 @@ namespace DataAccess.DTOs
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,5 +23,9 @@ namespace DataAccess.DTOs
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
public FileVersionDTO() : this (Guid.NewGuid())
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
DataAccess/DTOs/DTOEntities/IRootObjectDTO.cs
Normal file
16
DataAccess/DTOs/DTOEntities/IRootObjectDTO.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Projects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public interface IRootObjectDTO
|
||||
{
|
||||
FileVersionDTO FileVersion { get; set; }
|
||||
ProjectDTO Project { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Analyses;
|
||||
using StructureHelperCommon.Models.Projects;
|
||||
using System;
|
||||
|
||||
19
DataAccess/DTOs/DTOEntities/RootObjectDTO.cs
Normal file
19
DataAccess/DTOs/DTOEntities/RootObjectDTO.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Newtonsoft.Json;
|
||||
using StructureHelperCommon.Models.Projects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
public class RootObjectDTO : IRootObjectDTO
|
||||
{
|
||||
[JsonProperty("FileVersion")]
|
||||
public FileVersionDTO FileVersion { get; set; }
|
||||
[JsonProperty("Project")]
|
||||
public ProjectDTO Project { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -81,6 +81,7 @@ namespace DataAccess.DTOs
|
||||
{ (typeof(RectangleNdmPrimitiveDTO), "RectangleNdmPrimitive") },
|
||||
{ (typeof(RectangleShapeDTO), "RectangleShape") },
|
||||
{ (typeof(ReinforcementLibMaterialDTO), "ReinforcementLibMaterial") },
|
||||
{ (typeof(RootObjectDTO), "RootObject") },
|
||||
{ (typeof(MaterialPartialFactorDTO), "MaterialPartialFactor") },
|
||||
{ (typeof(VersionProcessorDTO), "VersionProcessor") },
|
||||
{ (typeof(VisualAnalysisDTO), "VisualAnalysis") },
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace DataAccess.DTOs
|
||||
public class UserCrackInputDataDTO : IUserCrackInputData
|
||||
{
|
||||
[JsonProperty("Id")]
|
||||
public Guid Id { get; set; }
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
[JsonProperty("LengthBetweenCracks")]
|
||||
public double LengthBetweenCracks { get; set; }
|
||||
[JsonProperty("SetLengthBetweenCracks")]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Analyses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -10,15 +11,17 @@ namespace DataAccess.DTOs
|
||||
{
|
||||
public class VisualAnalysisDTO : IVisualAnalysis
|
||||
{
|
||||
|
||||
|
||||
[JsonProperty("Id")]
|
||||
public Guid Id { get; set; }
|
||||
[JsonProperty("Analysis")]
|
||||
public IAnalysis Analysis { get; set; }
|
||||
[JsonIgnore]
|
||||
public Action ActionToRun { get; set; }
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
|
||||
Reference in New Issue
Block a user