Add cross-section convert strategies

This commit is contained in:
Evgeny Redikultsev
2024-09-28 20:46:42 +05:00
parent c10d6eb94e
commit 58b6e0eb8b
89 changed files with 1204 additions and 174 deletions

View File

@@ -0,0 +1,59 @@
using LoaderCalculator.Data.Materials;
using Newtonsoft.Json;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Models.Materials;
using StructureHelperCommon.Models.Materials.Libraries;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class ConcreteLibMaterialDTO : IConcreteLibMaterial
{
[JsonProperty("Id")]
public Guid Id { get; set; }
[JsonProperty("RelativeHumidity")]
public double RelativeHumidity { get; set; }
[JsonProperty("MinAge")]
public double MinAge { get; set; }
[JsonProperty("MaxAge")]
public double MaxAge { get; set; }
[JsonProperty("MaterialEntity")]
public ILibMaterialEntity MaterialEntity { get; set; }
[JsonProperty("SafetyFactors")]
public List<IMaterialSafetyFactor> SafetyFactors { get; set; }
[JsonProperty("TensionForULS")]
public bool TensionForULS { get; set; }
[JsonProperty("TensionForSLS")]
public bool TensionForSLS { get; set; }
public IMaterialLogic MaterialLogic { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public List<IMaterialLogic> MaterialLogics => throw new NotImplementedException();
public object Clone()
{
throw new NotImplementedException();
}
public IMaterial GetCrackedLoaderMaterial(LimitStates limitState, CalcTerms calcTerm)
{
throw new NotImplementedException();
}
public IMaterial GetLoaderMaterial(LimitStates limitState, CalcTerms calcTerm)
{
throw new NotImplementedException();
}
public (double Compressive, double Tensile) GetStrength(LimitStates limitState, CalcTerms calcTerm)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,66 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses;
using StructureHelperLogic.Models.Analyses;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip;
namespace DataAccess.DTOs.Converters
{
public class AnalysisToDTOConvertStrategy : IConvertStrategy<IAnalysis, IAnalysis>
{
private const string Message = "Analysis type is";
private IConvertStrategy<CrossSectionNdmAnalysisDTO, ICrossSectionNdmAnalysis> convertCrossSectionNdmAnalysisStrategy = new CrossSectionNdmAnalysisToDTOConvertStrategy();
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public IAnalysis Convert(IAnalysis source)
{
Check();
IAnalysis analysis;
if (source is ICrossSectionNdmAnalysis crossSectionNdmAnalysis)
{
analysis = GetCrossSectionNdmAnalysisDTO(crossSectionNdmAnalysis);
}
else
{
string errorString = ErrorStrings.ObjectTypeIsUnknownObj(source);
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
throw new StructureHelperException(errorString);
}
foreach (var item in source.VersionProcessor.Versions)
{
}
return analysis;
}
private CrossSectionNdmAnalysisDTO GetCrossSectionNdmAnalysisDTO(ICrossSectionNdmAnalysis crossSectionNdmAnalysis)
{
TraceLogger?.AddMessage(Message + " Cross-Section Ndm Analysis", TraceLogStatuses.Debug);
convertCrossSectionNdmAnalysisStrategy.ReferenceDictionary = ReferenceDictionary;
convertCrossSectionNdmAnalysisStrategy.TraceLogger = TraceLogger;
var convertLogic = new DictionaryConvertStrategy<CrossSectionNdmAnalysisDTO, ICrossSectionNdmAnalysis>()
{
ReferenceDictionary = ReferenceDictionary,
ConvertStrategy = convertCrossSectionNdmAnalysisStrategy,
TraceLogger = TraceLogger
};
CrossSectionNdmAnalysisDTO crossSectionNdmAnalysisDTO = convertLogic.Convert(crossSectionNdmAnalysis);
return crossSectionNdmAnalysisDTO;
}
private void Check()
{
var checkLogic = new CheckConvertLogic<IAnalysis, IAnalysis>();
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check();
}
}
}

View File

@@ -0,0 +1,33 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs.Converters
{
public class ConcreteLibMaterialToDTOConvertStrategy : IConvertStrategy<ConcreteLibMaterialDTO, IConcreteLibMaterial>
{
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public ConcreteLibMaterialDTO Convert(IConcreteLibMaterial source)
{
Check();
}
private void Check()
{
var checkLogic = new CheckConvertLogic<ConcreteLibMaterialDTO, IConcreteLibMaterial>();
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check();
}
}
}

View File

@@ -0,0 +1,64 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses;
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
{
internal class CrossSectionNdmAnalysisToDTOConvertStrategy : IConvertStrategy<CrossSectionNdmAnalysisDTO, ICrossSectionNdmAnalysis>
{
private IUpdateStrategy<ICrossSectionNdmAnalysis> updateStrategy;
private IConvertStrategy<VersionProcessorDTO, IVersionProcessor> convertStrategy;
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public CrossSectionNdmAnalysisToDTOConvertStrategy(
IUpdateStrategy<ICrossSectionNdmAnalysis> updateStrategy,
IConvertStrategy<VersionProcessorDTO, IVersionProcessor> convertStrategy,
IShiftTraceLogger traceLogger)
{
this.updateStrategy = updateStrategy;
this.convertStrategy = convertStrategy;
this.TraceLogger = traceLogger;
}
public CrossSectionNdmAnalysisToDTOConvertStrategy() : this(new CrossSectionNdmAnalysisUpdateStrategy(),
new VersionProcessorToDTOConvertStrategy(),
null)
{
}
public CrossSectionNdmAnalysisDTO Convert(ICrossSectionNdmAnalysis source)
{
Check();
CrossSectionNdmAnalysisDTO newItem = new();
newItem.Id = source.Id;
updateStrategy.Update(newItem, source);
convertStrategy.ReferenceDictionary = ReferenceDictionary;
convertStrategy.TraceLogger = TraceLogger;
var convertLogic = new DictionaryConvertStrategy<VersionProcessorDTO, IVersionProcessor>()
{
ReferenceDictionary = ReferenceDictionary,
ConvertStrategy = convertStrategy,
TraceLogger = TraceLogger
};
newItem.VersionProcessor = convertLogic.Convert(source.VersionProcessor);
return newItem;
}
private void Check()
{
var checkLogic = new CheckConvertLogic<CrossSectionNdmAnalysisDTO, ICrossSectionNdmAnalysis>();
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check();
}
}
}

View File

@@ -0,0 +1,73 @@
using DataAccess.DTOs.Converters;
using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class CrossSectionRepositoryToDTOConvertStrategy : IConvertStrategy<CrossSectionRepositoryDTO, ICrossSectionRepository>
{
private IConvertStrategy<HeadMaterialDTO, IHeadMaterial> materialConvertStrategy;
public CrossSectionRepositoryToDTOConvertStrategy(IConvertStrategy<HeadMaterialDTO, IHeadMaterial> materialConvertStrategy)
{
this.materialConvertStrategy = materialConvertStrategy;
}
public CrossSectionRepositoryToDTOConvertStrategy() : this(
new HeadMaterialToDTOConvertStrategy())
{
}
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public CrossSectionRepositoryDTO Convert(ICrossSectionRepository source)
{
Check();
CrossSectionRepositoryDTO newItem = new()
{
Id = source.Id
};
List<HeadMaterialDTO> materials = ProcessMaterials(source);
newItem.HeadMaterials.AddRange(materials);
return newItem;
}
private List<HeadMaterialDTO> ProcessMaterials(ICrossSectionRepository source)
{
materialConvertStrategy.ReferenceDictionary = ReferenceDictionary;
materialConvertStrategy.TraceLogger = TraceLogger;
var convertLogic = new DictionaryConvertStrategy<HeadMaterialDTO, IHeadMaterial>()
{
ReferenceDictionary = ReferenceDictionary,
ConvertStrategy = materialConvertStrategy,
TraceLogger = TraceLogger
};
List<HeadMaterialDTO> materials = new();
foreach (var item in source.HeadMaterials)
{
materials.Add(convertLogic.Convert(item));
}
return materials;
}
private void Check()
{
var checkLogic = new CheckConvertLogic<CrossSectionRepositoryDTO, ICrossSectionRepository>();
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check();
}
}
}

View File

@@ -0,0 +1,61 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses;
using StructureHelperLogics.Models.CrossSections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs.Converters
{
public class CrossSectionToDTOConvertStrategy : IConvertStrategy<CrossSectionDTO, ICrossSection>
{
private IUpdateStrategy<ICrossSection> updateStrategy;
private IConvertStrategy<CrossSectionRepositoryDTO, ICrossSectionRepository> convertStrategy;
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public CrossSectionToDTOConvertStrategy(IUpdateStrategy<ICrossSection> updateStrategy,
IConvertStrategy<CrossSectionRepositoryDTO, ICrossSectionRepository> convertStrategy)
{
this.updateStrategy = updateStrategy;
this.convertStrategy = convertStrategy;
}
public CrossSectionToDTOConvertStrategy() : this(
new CrossSectionUpdateStrategy(),
new CrossSectionRepositoryToDTOConvertStrategy())
{
}
public CrossSectionDTO Convert(ICrossSection source)
{
Check();
CrossSectionDTO newItem = new()
{
Id = source.Id
};
convertStrategy.ReferenceDictionary = ReferenceDictionary;
convertStrategy.TraceLogger = TraceLogger;
var convertLogic = new DictionaryConvertStrategy<CrossSectionRepositoryDTO, ICrossSectionRepository>()
{
ReferenceDictionary = ReferenceDictionary,
ConvertStrategy = convertStrategy,
TraceLogger = TraceLogger
};
newItem.SectionRepository = convertLogic.Convert(source.SectionRepository);
return newItem;
}
private void Check()
{
var checkLogic = new CheckConvertLogic<CrossSectionDTO, ICrossSection>();
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check();
}
}
}

View File

@@ -0,0 +1,65 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses;
using StructureHelperLogic.Models.Analyses;
using StructureHelperLogics.Models.CrossSections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs.Converters
{
public class DateVersionToDTOConvertStrategy : IConvertStrategy<DateVersionDTO, IDateVersion>
{
private IUpdateStrategy<IDateVersion> updateStrategy;
private IConvertStrategy<ISaveable, ISaveable> convertStrategy;
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public DateVersionToDTOConvertStrategy(
IUpdateStrategy<IDateVersion> updateStrategy,
IConvertStrategy<ISaveable, ISaveable> convertStrategy)
{
this.updateStrategy = updateStrategy;
this.convertStrategy = convertStrategy;
}
public DateVersionToDTOConvertStrategy() : this (
new DateVersionUpdateStrategy(),
new VersionItemToDTOConvertStrategy())
{
}
public DateVersionDTO Convert(IDateVersion source)
{
Check();
DateVersionDTO newItem = new()
{
Id = source.Id
};
updateStrategy.Update(newItem, source);
convertStrategy.ReferenceDictionary = ReferenceDictionary;
convertStrategy.TraceLogger = TraceLogger;
var convertLogic = new DictionaryConvertStrategy<ISaveable, ISaveable>()
{
ReferenceDictionary = ReferenceDictionary,
ConvertStrategy = convertStrategy,
TraceLogger = TraceLogger
};
newItem.AnalysisVersion = convertLogic.Convert(source.AnalysisVersion);
return newItem;
}
private void Check()
{
var checkLogic = new CheckConvertLogic<DateVersionDTO, IDateVersion>();
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check();
}
}
}

View File

@@ -0,0 +1,37 @@
using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs.Converters
{
public class HeadMaterialToDTOConvertStrategy : IConvertStrategy<HeadMaterialDTO, IHeadMaterial>
{
private IUpdateStrategy<IHeadMaterial> updateStrategy;
public HeadMaterialToDTOConvertStrategy(IUpdateStrategy<IHeadMaterial> updateStrategy)
{
this.updateStrategy = updateStrategy;
}
public HeadMaterialToDTOConvertStrategy() : this (new HeadMaterialUpdateStrategy())
{
}
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public HeadMaterialDTO Convert(IHeadMaterial source)
{
HeadMaterialDTO newItem = new() { Id = source.Id};
updateStrategy.Update(newItem, source);
return newItem;
}
}
}

View File

@@ -0,0 +1,31 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs.Converters
{
internal class HelperMaterialToDTOConvertStrategy : IConvertStrategy<IHelperMaterial, IHelperMaterial>
{
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public IHelperMaterial Convert(IHelperMaterial source)
{
Check();
}
private void Check()
{
var checkLogic = new CheckConvertLogic<IHelperMaterial, IHelperMaterial>();
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check();
}
}
}

View File

@@ -31,21 +31,35 @@ namespace DataAccess.DTOs
public ProjectDTO Convert(IProject source)
{
ProjectDTO projectDTO = new(source.Id);
updateStrategy.Update(projectDTO, source);
Check();
ProjectDTO newItem = new()
{
Id = source.Id
};
updateStrategy.Update(newItem, source);
convertStrategy.ReferenceDictionary = ReferenceDictionary;
convertStrategy.TraceLogger = TraceLogger;
var convertLogic = new DictionaryConvertStrategy<VisualAnalysisDTO, IVisualAnalysis>()
{
ReferenceDictionary = ReferenceDictionary,
ConvertStrategy = convertStrategy,
TraceLogger = TraceLogger
};
newItem.VisualAnalyses.Clear();
foreach (var item in source.VisualAnalyses)
{
var newVisualAnalysis = convertLogic.Convert(item);
projectDTO.VisualAnalyses.Add(newVisualAnalysis);
newItem.VisualAnalyses.Add(newVisualAnalysis);
}
return projectDTO;
return newItem;
}
private void Check()
{
var checkLogic = new CheckConvertLogic<ProjectDTO, IProject>();
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check();
}
}
}

View File

@@ -0,0 +1,63 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.CrossSections;
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 VersionItemToDTOConvertStrategy : IConvertStrategy<ISaveable, ISaveable>
{
private const string Message = "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; }
public ISaveable Convert(ISaveable source)
{
Check();
ISaveable saveable;
if (source is ICrossSection crossSection)
{
saveable = ProcessCrossSection(crossSection);
}
else
{
string errorString = ErrorStrings.ObjectTypeIsUnknownObj(source);
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
throw new StructureHelperException(errorString);
}
return saveable;
}
private ISaveable ProcessCrossSection(ICrossSection crossSection)
{
TraceLogger?.AddMessage(Message + " Cross-Section Ndm Analysis", TraceLogStatuses.Debug);
ISaveable saveable;
crossSectionConvertStrategy.ReferenceDictionary = ReferenceDictionary;
crossSectionConvertStrategy.TraceLogger = TraceLogger;
var convertLogic = new DictionaryConvertStrategy<CrossSectionDTO, ICrossSection>()
{
ReferenceDictionary = ReferenceDictionary,
ConvertStrategy = crossSectionConvertStrategy,
TraceLogger = TraceLogger
};
saveable = convertLogic.Convert(crossSection);
return saveable;
}
private void Check()
{
var checkLogic = new CheckConvertLogic<ISaveable, ISaveable>();
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check();
}
}
}

View File

@@ -0,0 +1,48 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses;
using StructureHelperLogics.Models.CrossSections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs.Converters
{
public class VersionProcessorToDTOConvertStrategy : IConvertStrategy<VersionProcessorDTO, IVersionProcessor>
{
private IConvertStrategy<DateVersionDTO, IDateVersion> convertStrategy = new DateVersionToDTOConvertStrategy();
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public VersionProcessorDTO Convert(IVersionProcessor source)
{
Check();
VersionProcessorDTO newItem = new()
{
Id = source.Id
};
convertStrategy.ReferenceDictionary = ReferenceDictionary;
convertStrategy.TraceLogger = TraceLogger;
foreach (var item in source.Versions)
{
var convertLogic = new DictionaryConvertStrategy<DateVersionDTO, IDateVersion>()
{
ReferenceDictionary = ReferenceDictionary,
ConvertStrategy = convertStrategy,
TraceLogger = TraceLogger
};
newItem.Versions.Add(convertLogic.Convert(item));
}
return newItem;
}
private void Check()
{
var checkLogic = new CheckConvertLogic<VersionProcessorDTO, IVersionProcessor>();
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check();
}
}
}

View File

@@ -1,9 +1,13 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using DataAccess.DTOs.Converters;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses;
using StructureHelperCommon.Models.Projects;
using StructureHelperLogic.Models.Analyses;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
@@ -11,16 +15,45 @@ namespace DataAccess.DTOs
{
internal class VisualAnalysisToDTOConvertStrategy : IConvertStrategy<VisualAnalysisDTO, IVisualAnalysis>
{
private IConvertStrategy<IAnalysis, IAnalysis> convertStrategy;
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public VisualAnalysisToDTOConvertStrategy(IConvertStrategy<IAnalysis, IAnalysis> convertStrategy)
{
this.convertStrategy = convertStrategy;
}
public VisualAnalysisToDTOConvertStrategy() : this(new AnalysisToDTOConvertStrategy())
{
}
public VisualAnalysisDTO Convert(IVisualAnalysis source)
{
Check();
VisualAnalysisDTO visualAnalysisDTO = new()
{
Id = source.Id
};
convertStrategy.ReferenceDictionary = ReferenceDictionary;
convertStrategy.TraceLogger = TraceLogger;
var convertLogic = new DictionaryConvertStrategy<IAnalysis, IAnalysis>()
{
ReferenceDictionary = ReferenceDictionary,
ConvertStrategy = convertStrategy,
TraceLogger = TraceLogger
};
visualAnalysisDTO.Analysis = convertLogic.Convert(source.Analysis);
return visualAnalysisDTO;
}
private void Check()
{
var checkLogic = new CheckConvertLogic<VisualAnalysisDTO, IVisualAnalysis>();
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check();
}
}
}

View File

@@ -1,4 +1,5 @@
using StructureHelperLogics.Models.CrossSections;
using Newtonsoft.Json;
using StructureHelperLogics.Models.CrossSections;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -9,9 +10,11 @@ namespace DataAccess.DTOs
{
public class CrossSectionDTO : ICrossSection
{
public ICrossSectionRepository SectionRepository { get; }
[JsonProperty("Id")]
public Guid Id { get; set; }
[JsonProperty("SectionRepository")]
public ICrossSectionRepository SectionRepository { get; set; }
public object Clone()
{

View File

@@ -0,0 +1,28 @@
using Newtonsoft.Json;
using StructureHelperCommon.Models.Analyses;
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 CrossSectionNdmAnalysisDTO : ICrossSectionNdmAnalysis
{
[JsonProperty("Id")]
public Guid Id { get; set; }
[JsonProperty("Name")]
public string Name { get; set; }
[JsonProperty("Tags")]
public string Tags { get; set; }
[JsonProperty("VersionProcessor")]
public IVersionProcessor VersionProcessor { get; set; } = new VersionProcessorDTO();
public object Clone()
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,29 @@
using Newtonsoft.Json;
using StructureHelper.Models.Materials;
using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Models.Forces;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.NdmCalculations.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class CrossSectionRepositoryDTO : ICrossSectionRepository
{
[JsonProperty("Id")]
public Guid Id { get; set; }
[JsonProperty("HeadMaterials")]
public List<IHeadMaterial> HeadMaterials { get; } = new();
[JsonProperty("ForceActions")]
public List<IForceAction> ForceActions { get; } = new();
[JsonProperty("Primitives")]
public List<INdmPrimitive> Primitives { get; } = new();
[JsonProperty("Calculators")]
public List<ICalculator> Calculators { get; } = new();
}
}

View File

@@ -0,0 +1,22 @@
using Newtonsoft.Json;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Analyses;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class DateVersionDTO : IDateVersion
{
[JsonProperty("Id")]
public Guid Id { get; set; }
[JsonProperty("DateTime")]
public DateTime DateTime { get; set; }
[JsonProperty("AnalysisVersion")]
public ISaveable AnalysisVersion { get; set; }
}
}

View File

@@ -0,0 +1,44 @@
using LoaderCalculator.Data.Materials;
using Newtonsoft.Json;
using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace DataAccess.DTOs
{
public class HeadMaterialDTO : IHeadMaterial
{
[JsonProperty("Id")]
public Guid Id { get; set; }
[JsonProperty("Name")]
public string Name { get; set; }
[JsonProperty("Color")]
public Color Color { get; set; }
[JsonProperty("HelperMaterial")]
public IHelperMaterial HelperMaterial { get; set; }
public object Clone()
{
throw new NotImplementedException();
}
public IMaterial GetCrackedLoaderMaterial(LimitStates limitState, CalcTerms calcTerm)
{
throw new NotImplementedException();
}
public IMaterial GetLoaderMaterial(LimitStates limitState, CalcTerms calcTerm)
{
throw new NotImplementedException();
}
}
}

View File

@@ -25,16 +25,5 @@ namespace DataAccess.DTOs
[JsonIgnore]
public string FileName { get; set; }
public ProjectDTO(Guid id)
{
Id = id;
}
public ProjectDTO() : this (Guid.NewGuid())
{
}
}
}

View File

@@ -0,0 +1,42 @@
using Newtonsoft.Json.Serialization;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.CrossSections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class TypeBinder : ISerializationBinder
{
private List<(Type type, string name)> typesNames;
public static IShiftTraceLogger TraceLogger;
public TypeBinder(List<(Type type, string name)> typesNames, IShiftTraceLogger traceLogger = null)
{
this.typesNames = typesNames;
TraceLogger = traceLogger;
}
public void BindToName(Type serializedType, out string? assemblyName, out string? typeName)
{
assemblyName = null;
if (typesNames.Any(x => x.type == serializedType))
{
typeName = typesNames.Single(x => x.type == serializedType).name;
}
else
{
typeName = serializedType.FullName;
}
}
public Type BindToType(string? assemblyName, string typeName)
{
return typesNames.SingleOrDefault(x => x.name == typeName).type;
}
}
}

View File

@@ -0,0 +1,60 @@
using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Models.Analyses;
using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Models.Forces;
using StructureHelperLogics.NdmCalculations.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
internal enum TypeFileVersion
{
version_v1
}
internal static class TypeBinderListFactory
{
public static List<(Type type, string name)> GetTypeNameList(TypeFileVersion fileVersion)
{
if (fileVersion == TypeFileVersion.version_v1)
{
List<(Type type, string name)> typesNames = GetVersionV1();
return typesNames;
}
else
{
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(fileVersion));
}
}
private static List<(Type type, string name)> GetVersionV1()
{
return new List<(Type type, string name)>
{
{ (typeof(CirclePrimitiveDTO), "CircleNdmPrimitive") },
{ (typeof(ConcreteLibMaterialDTO), "ConcreteLibMaterial") },
{ (typeof(CrossSectionDTO), "CrossSection") },
{ (typeof(CrossSectionNdmAnalysisDTO), "CrossSectionNdmAnalysis") },
{ (typeof(CrossSectionRepositoryDTO), "CrossSectionRepository") },
{ (typeof(DateVersionDTO), "DateVersion") },
{ (typeof(FileVersionDTO), "FileVersion") },
{ (typeof(HeadMaterialDTO), "HeadMaterial") },
{ (typeof(NdmPrimitiveDTO), "NdmPrimitive") },
{ (typeof(IVisualAnalysis), "IVisualAnalysis") },
{ (typeof(List<ICalculator>), "ListOfICalculator") },
{ (typeof(List<IDateVersion>), "ListOfIDateVersion") },
{ (typeof(List<IForceAction>), "ListOfIForceAction") },
{ (typeof(List<IHeadMaterial>), "ListOfIHeadMaterial") },
{ (typeof(List<INdmPrimitive>), "ListOfINdmPrimitive") },
{ (typeof(List<IVisualAnalysis>), "ListOfIVisualAnalysis") },
{ (typeof(ProjectDTO), "Project") },
{ (typeof(VersionProcessorDTO), "VersionProcessor") },
{ (typeof(VisualAnalysisDTO), "VisualAnalysis") },
};
}
}
}

View File

@@ -0,0 +1,30 @@
using Newtonsoft.Json;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Analyses;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class VersionProcessorDTO : IVersionProcessor
{
[JsonProperty("Id")]
public Guid Id { get; set; }
[JsonProperty("Versions")]
public List<IDateVersion> Versions { get; } = new();
public void AddVersion(ISaveable newItem)
{
throw new NotImplementedException();
}
public IDateVersion GetCurrentVersion()
{
throw new NotImplementedException();
}
}
}

View File

@@ -19,4 +19,10 @@
<Folder Include="NewFolder\" />
</ItemGroup>
<ItemGroup>
<Reference Include="LoaderCalculator">
<HintPath>..\StructureHelper\Libraries\LoaderCalculator.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

View File

@@ -48,22 +48,31 @@ namespace DataAccess.Infrastructures
private void SaveToFile(IProject project)
{
version = ProgramSetting.GetCurrentFileVersion();
refDictinary = new Dictionary<(Guid id, Type type), ISaveable>();
FileVersionDTO versionDTO = GetVersionDTO();
var versionString = Serialize(versionDTO, TraceLogger);
SaveStringToFile(project, versionString);
refDictinary = new Dictionary<(Guid id, Type type), ISaveable>();
ProjectDTO projectDTO = GetProjectDTO(project);
var projectString = Serialize(projectDTO, TraceLogger);
SaveStringToFile(project, projectString);
try
{
version = ProgramSetting.GetCurrentFileVersion();
refDictinary = new Dictionary<(Guid id, Type type), ISaveable>();
FileVersionDTO versionDTO = GetVersionDTO();
var versionString = Serialize(versionDTO, TraceLogger);
File.Delete(project.FullFileName);
SaveStringToFile(project, versionString);
refDictinary = new Dictionary<(Guid id, Type type), ISaveable>();
ProjectDTO projectDTO = GetProjectDTO(project);
var projectString = Serialize(projectDTO, TraceLogger);
SaveStringToFile(project, projectString);
}
catch (Exception ex)
{
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
}
}
private void SaveStringToFile(IProject project, string versionString)
{
try
{
File.WriteAllText(project.FullFileName, versionString);
File.AppendAllText(project.FullFileName, versionString);
TraceLogger?.AddMessage($"File {project.FullFileName} was saved successfully", TraceLogStatuses.Service);
}
catch (Exception ex)
@@ -107,14 +116,17 @@ namespace DataAccess.Infrastructures
private static string Serialize(object obj, IShiftTraceLogger logger)
{
List<(Type type, string name)> typesNames = TypeBinderListFactory.GetTypeNameList(TypeFileVersion.version_v1);
TypeBinder typeBinder = new(typesNames);
var settings = new JsonSerializerSettings
{
{
Converters = new List<JsonConverter>
{
// Add other converters if needed
new FileVersionDTOJsonConverter(logger), // Add the specific converter
new ProjectDTOJsonConverter(logger)
},
{
// Add other converters if needed
new FileVersionDTOJsonConverter(logger), // Add the specific converter
new ProjectDTOJsonConverter(logger)
},
SerializationBinder = typeBinder,
Formatting = Formatting.Indented,
PreserveReferencesHandling = PreserveReferencesHandling.All,
MissingMemberHandling = MissingMemberHandling.Ignore,