Add project ConvertFromStrategy

This commit is contained in:
Evgeny Redikultsev
2024-10-20 20:01:32 +05:00
parent d3a1992f4d
commit b0c24126da
28 changed files with 457 additions and 75 deletions

View 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();
}
}
}

View File

@@ -37,7 +37,7 @@ namespace DataAccess.DTOs.Converters
} }
foreach (var item in source.VersionProcessor.Versions) foreach (var item in source.VersionProcessor.Versions)
{ {
//to do
} }
return analysis; return analysis;
} }

View File

@@ -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;
}
}
}

View File

@@ -28,7 +28,8 @@ namespace DataAccess.DTOs.Converters
this.TraceLogger = traceLogger; this.TraceLogger = traceLogger;
} }
public CrossSectionNdmAnalysisToDTOConvertStrategy() : this(new CrossSectionNdmAnalysisUpdateStrategy(), public CrossSectionNdmAnalysisToDTOConvertStrategy() : this(
new CrossSectionNdmAnalysisUpdateStrategy(),
new VersionProcessorToDTOConvertStrategy(), new VersionProcessorToDTOConvertStrategy(),
null) null)
{ {
@@ -55,9 +56,7 @@ namespace DataAccess.DTOs.Converters
private void Check() private void Check()
{ {
var checkLogic = new CheckConvertLogic<CrossSectionNdmAnalysisDTO, ICrossSectionNdmAnalysis>(); var checkLogic = new CheckConvertLogic<CrossSectionNdmAnalysisDTO, ICrossSectionNdmAnalysis>(this);
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check(); checkLogic.Check();
} }
} }

View File

@@ -33,7 +33,7 @@ namespace DataAccess.DTOs
} }
catch (Exception ex) catch (Exception ex)
{ {
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Debug); TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error); TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
throw; throw;
} }

View 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();
}
}
}

View File

@@ -2,6 +2,7 @@
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models; using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses; using StructureHelperCommon.Models.Analyses;
using StructureHelperCommon.Models.Loggers;
using StructureHelperCommon.Models.Projects; using StructureHelperCommon.Models.Projects;
using StructureHelperLogic.Models.Analyses; using StructureHelperLogic.Models.Analyses;
using System; using System;
@@ -32,13 +33,28 @@ namespace DataAccess.DTOs
public VisualAnalysisDTO Convert(IVisualAnalysis source) public VisualAnalysisDTO Convert(IVisualAnalysis source)
{ {
Check(); 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() VisualAnalysisDTO visualAnalysisDTO = new()
{ {
Id = source.Id Id = source.Id
}; };
convertStrategy.ReferenceDictionary = ReferenceDictionary; convertStrategy.ReferenceDictionary = ReferenceDictionary;
convertStrategy.TraceLogger = TraceLogger; convertStrategy.TraceLogger = TraceLogger;
var convertLogic = new DictionaryConvertStrategy<IAnalysis, IAnalysis>() var convertLogic = new DictionaryConvertStrategy<IAnalysis, IAnalysis>(this, convertStrategy)
{ {
ReferenceDictionary = ReferenceDictionary, ReferenceDictionary = ReferenceDictionary,
ConvertStrategy = convertStrategy, ConvertStrategy = convertStrategy,

View File

@@ -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();
}
}
}

View File

@@ -11,7 +11,7 @@ namespace DataAccess.DTOs.DTOEntities
public class AccuracyDTO : IAccuracy public class AccuracyDTO : IAccuracy
{ {
[JsonProperty("Id")] [JsonProperty("Id")]
public Guid Id { get; set; } public Guid Id { get; set; } = Guid.NewGuid();
[JsonProperty("IterationAccuracy")] [JsonProperty("IterationAccuracy")]
public double IterationAccuracy { get; set; } public double IterationAccuracy { get; set; }
[JsonProperty("MaxIterationCount")] [JsonProperty("MaxIterationCount")]

View File

@@ -18,6 +18,7 @@ namespace DataAccess.DTOs
{ {
const MaterialTypes materialType = MaterialTypes.Concrete; const MaterialTypes materialType = MaterialTypes.Concrete;
[JsonProperty("Id")] [JsonProperty("Id")]
public Guid Id { get; set; } public Guid Id { get; set; }
[JsonProperty("RelativeHumidity")] [JsonProperty("RelativeHumidity")]
@@ -29,7 +30,11 @@ namespace DataAccess.DTOs
[JsonProperty("MaterialEntityId")] [JsonProperty("MaterialEntityId")]
public Guid MaterialEntityId public Guid MaterialEntityId
{ {
get => MaterialEntity.Id; get
{
return MaterialEntity.Id;
}
set set
{ {
MaterialEntity = ProgramSetting.MaterialRepository.Repository.Single(x => x.Id == value); MaterialEntity = ProgramSetting.MaterialRepository.Repository.Single(x => x.Id == value);

View File

@@ -8,7 +8,7 @@ namespace DataAccess.DTOs
public class CrackCalculatorInputDataDTO : ICrackCalculatorInputData public class CrackCalculatorInputDataDTO : ICrackCalculatorInputData
{ {
[JsonProperty("Id")] [JsonProperty("Id")]
public Guid Id { get; set; } public Guid Id { get; set; } = Guid.NewGuid();
[JsonProperty("ForceActions")] [JsonProperty("ForceActions")]
public List<IForceAction> ForceActions { get; set; } = new(); public List<IForceAction> ForceActions { get; set; } = new();
[JsonProperty("ForcePrimitives")] [JsonProperty("ForcePrimitives")]

View File

@@ -1,6 +1,8 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Analyses; using StructureHelperCommon.Models.Analyses;
using StructureHelperLogic.Models.Analyses; using StructureHelperLogic.Models.Analyses;
using StructureHelperLogics.Models.Analyses;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -22,7 +24,7 @@ namespace DataAccess.DTOs
public object Clone() public object Clone()
{ {
throw new NotImplementedException(); return this;
} }
} }
} }

View File

@@ -23,5 +23,9 @@ namespace DataAccess.DTOs
{ {
Id = id; Id = id;
} }
public FileVersionDTO() : this (Guid.NewGuid())
{
}
} }
} }

View 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; }
}
}

View File

@@ -1,4 +1,5 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Analyses; using StructureHelperCommon.Models.Analyses;
using StructureHelperCommon.Models.Projects; using StructureHelperCommon.Models.Projects;
using System; using System;

View 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; }
}
}

View File

@@ -81,6 +81,7 @@ namespace DataAccess.DTOs
{ (typeof(RectangleNdmPrimitiveDTO), "RectangleNdmPrimitive") }, { (typeof(RectangleNdmPrimitiveDTO), "RectangleNdmPrimitive") },
{ (typeof(RectangleShapeDTO), "RectangleShape") }, { (typeof(RectangleShapeDTO), "RectangleShape") },
{ (typeof(ReinforcementLibMaterialDTO), "ReinforcementLibMaterial") }, { (typeof(ReinforcementLibMaterialDTO), "ReinforcementLibMaterial") },
{ (typeof(RootObjectDTO), "RootObject") },
{ (typeof(MaterialPartialFactorDTO), "MaterialPartialFactor") }, { (typeof(MaterialPartialFactorDTO), "MaterialPartialFactor") },
{ (typeof(VersionProcessorDTO), "VersionProcessor") }, { (typeof(VersionProcessorDTO), "VersionProcessor") },
{ (typeof(VisualAnalysisDTO), "VisualAnalysis") }, { (typeof(VisualAnalysisDTO), "VisualAnalysis") },

View File

@@ -11,7 +11,7 @@ namespace DataAccess.DTOs
public class UserCrackInputDataDTO : IUserCrackInputData public class UserCrackInputDataDTO : IUserCrackInputData
{ {
[JsonProperty("Id")] [JsonProperty("Id")]
public Guid Id { get; set; } public Guid Id { get; set; } = Guid.NewGuid();
[JsonProperty("LengthBetweenCracks")] [JsonProperty("LengthBetweenCracks")]
public double LengthBetweenCracks { get; set; } public double LengthBetweenCracks { get; set; }
[JsonProperty("SetLengthBetweenCracks")] [JsonProperty("SetLengthBetweenCracks")]

View File

@@ -1,4 +1,5 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Analyses; using StructureHelperCommon.Models.Analyses;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -15,10 +16,12 @@ namespace DataAccess.DTOs
public Guid Id { get; set; } public Guid Id { get; set; }
[JsonProperty("Analysis")] [JsonProperty("Analysis")]
public IAnalysis Analysis { get; set; } public IAnalysis Analysis { get; set; }
[JsonIgnore]
public Action ActionToRun { get; set; }
public object Clone() public object Clone()
{ {
throw new NotImplementedException(); return this;
} }
public void Run() public void Run()

View File

@@ -3,16 +3,19 @@ using DataAccess.JsonConverters;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using NLog; using NLog;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Infrastructures.Settings; using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Models; using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Projects; using StructureHelperCommon.Models.Projects;
using StructureHelperCommon.Services.FileServices; using StructureHelperCommon.Services.FileServices;
using System.Reflection.Emit;
namespace DataAccess.Infrastructures namespace DataAccess.Infrastructures
{ {
public class FileOpenLogic : IFileOpenLogic public class FileOpenLogic : IFileOpenLogic
{ {
private string fileName; private string fileName;
private Dictionary<(Guid id, Type type), ISaveable> refDictinary;
public IShiftTraceLogger? TraceLogger { get; set; } public IShiftTraceLogger? TraceLogger { get; set; }
@@ -50,23 +53,9 @@ namespace DataAccess.Infrastructures
TraceLogger?.AddMessage($"File {fileName} does not exists", TraceLogStatuses.Error); TraceLogger?.AddMessage($"File {fileName} does not exists", TraceLogStatuses.Error);
return result; return result;
} }
var settings = new JsonSerializerSettings string jsonData = File.ReadAllText(fileName);
{ RootObjectDTO? rootObject = GetRootObject(jsonData);
Converters = new List<JsonConverter> var fileVersion = rootObject.FileVersion;
{
new FileVersionDTOJsonConverter(TraceLogger), // Add the specific converter
// Add other converters if needed
},
Formatting = Formatting.Indented,
PreserveReferencesHandling = PreserveReferencesHandling.All,
MissingMemberHandling = MissingMemberHandling.Ignore,
TypeNameHandling = TypeNameHandling.All,
NullValueHandling = NullValueHandling.Include
};
using (StreamReader file = File.OpenText(fileName))
{
JsonSerializer serializer = new JsonSerializer();
var fileVersion = (FileVersionDTO)serializer.Deserialize(file, typeof(FileVersionDTO));
var checkLogic = new CheckFileVersionLogic() var checkLogic = new CheckFileVersionLogic()
{ {
FileVersion = fileVersion, FileVersion = fileVersion,
@@ -80,11 +69,55 @@ namespace DataAccess.Infrastructures
} }
else else
{ {
var currentVersion = ProgramSetting.GetCurrentFileVersion(); Project project = GetProject(rootObject);
TraceLogger.AddMessage($"File version is {fileVersion.VersionNumber}.{fileVersion.SubVersionNumber}, current version is {currentVersion.VersionNumber}.{currentVersion.SubVersionNumber}"); project.FullFileName = fileName;
} result.Project = project;
} }
return result; return result;
} }
private Project GetProject(RootObjectDTO? rootObject)
{
var currentVersion = ProgramSetting.GetCurrentFileVersion();
IFileVersion fileVersion = rootObject.FileVersion;
TraceLogger?.AddMessage($"File version is {fileVersion.VersionNumber}.{fileVersion.SubVersionNumber}, current version is {currentVersion.VersionNumber}.{currentVersion.SubVersionNumber}");
refDictinary = new Dictionary<(Guid id, Type type), ISaveable>();
IConvertStrategy<Project, ProjectDTO> convertStrategy = new ProjectFromDTOConvertStrategy()
{
ReferenceDictionary = refDictinary,
TraceLogger = TraceLogger
};
Project project = convertStrategy.Convert(rootObject.Project);
return project;
}
private RootObjectDTO? GetRootObject(string jsonData)
{
JsonSerializerSettings settings = GetSettings();
var rootObject = JsonConvert.DeserializeObject<RootObjectDTO>(jsonData, settings);
return rootObject;
}
private JsonSerializerSettings GetSettings()
{
List<(Type type, string name)> typesNames = TypeBinderListFactory.GetTypeNameList(TypeFileVersion.version_v1);
TypeBinder typeBinder = new(typesNames);
var settings = new JsonSerializerSettings
{
Converters = new List<JsonConverter>
{
new FileVersionDTOJsonConverter(TraceLogger), // Add the specific converter
new ProjectDTOJsonConverter(TraceLogger)
},
SerializationBinder = typeBinder,
Formatting = Formatting.Indented,
PreserveReferencesHandling = PreserveReferencesHandling.All,
MissingMemberHandling = MissingMemberHandling.Ignore,
TypeNameHandling = TypeNameHandling.All,
NullValueHandling = NullValueHandling.Include
};
return settings;
}
} }
} }

View File

@@ -1,4 +1,5 @@
using DataAccess.DTOs; using DataAccess.DTOs;
using DataAccess.DTOs.DTOEntities;
using DataAccess.JsonConverters; using DataAccess.JsonConverters;
using Newtonsoft.Json; using Newtonsoft.Json;
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
@@ -55,11 +56,11 @@ namespace DataAccess.Infrastructures
FileVersionDTO versionDTO = GetVersionDTO(); FileVersionDTO versionDTO = GetVersionDTO();
var versionString = Serialize(versionDTO, TraceLogger); var versionString = Serialize(versionDTO, TraceLogger);
File.Delete(project.FullFileName); File.Delete(project.FullFileName);
SaveStringToFile(project, versionString);
refDictinary = new Dictionary<(Guid id, Type type), ISaveable>(); refDictinary = new Dictionary<(Guid id, Type type), ISaveable>();
ProjectDTO projectDTO = GetProjectDTO(project); ProjectDTO projectDTO = GetProjectDTO(project);
var projectString = Serialize(projectDTO, TraceLogger); RootObjectDTO rootObject = new() { FileVersion = versionDTO, Project = projectDTO };
SaveStringToFile(project, projectString); var rootString = Serialize(rootObject, TraceLogger);
SaveStringToFile(project, rootString);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -72,7 +73,7 @@ namespace DataAccess.Infrastructures
{ {
try try
{ {
File.AppendAllText(project.FullFileName, versionString); File.WriteAllText(project.FullFileName, versionString);
TraceLogger?.AddMessage($"File {project.FullFileName} was saved successfully", TraceLogStatuses.Service); TraceLogger?.AddMessage($"File {project.FullFileName} was saved successfully", TraceLogStatuses.Service);
} }
catch (Exception ex) catch (Exception ex)

View File

@@ -1,8 +1,10 @@
using StructureHelper.Infrastructure; using StructureHelper.Infrastructure;
using StructureHelper.Windows.MainWindow.Analyses; using StructureHelper.Windows.MainWindow.Analyses;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Settings; using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Models.Analyses; using StructureHelperCommon.Models.Analyses;
using StructureHelperLogic.Models.Analyses; using StructureHelperLogic.Models.Analyses;
using StructureHelperLogics.Models.CrossSections;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@@ -114,6 +116,8 @@ namespace StructureHelper.Windows.MainWindow
} }
private void RunAnalysis() private void RunAnalysis()
{ {
if (SelectedAnalysis is null) { return; }
SelectedAnalysis.ActionToRun = ActionToRun;
SelectedAnalysis?.Run(); SelectedAnalysis?.Run();
} }
private void AddCrossSectionNdmAnalysis() private void AddCrossSectionNdmAnalysis()
@@ -124,5 +128,29 @@ namespace StructureHelper.Windows.MainWindow
var visualAnalysis = new VisualAnalysis(analysis); var visualAnalysis = new VisualAnalysis(analysis);
ProgramSetting.CurrentProject.VisualAnalyses.Add(visualAnalysis); ProgramSetting.CurrentProject.VisualAnalyses.Add(visualAnalysis);
} }
private void ActionToRun()
{
if (SelectedAnalysis is null) { return; }
var version = SelectedAnalysis.Analysis.VersionProcessor.GetCurrentVersion();
if (version is null)
{
throw new StructureHelperException(ErrorStrings.NullReference);
}
if (version.AnalysisVersion is ICrossSection crossSection)
{
ProcessCrossSection(crossSection);
}
else
{
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(version));
}
}
private void ProcessCrossSection(ICrossSection crossSection)
{
var window = new CrossSectionView(crossSection);
window.ShowDialog();
}
} }
} }

View File

@@ -1,9 +1,12 @@
using DataAccess.Infrastructures; using DataAccess.Infrastructures;
using StructureHelper.Infrastructure; using StructureHelper.Infrastructure;
using StructureHelper.Windows.CalculationWindows.ProgressViews; using StructureHelper.Windows.CalculationWindows.ProgressViews;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Settings; using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Models; using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses;
using StructureHelperCommon.Models.Projects; using StructureHelperCommon.Models.Projects;
using StructureHelperLogics.Models.CrossSections;
using System; using System;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
@@ -22,6 +25,8 @@ namespace StructureHelper.Windows.MainWindow
private IProjectAccessLogic projectAccessLogic; private IProjectAccessLogic projectAccessLogic;
private RelayCommand fileSaveAs; private RelayCommand fileSaveAs;
public AnalysesManagerViewModel ParentVM { get; set; }
public FileLogic(IProjectAccessLogic projectAccessLogic) public FileLogic(IProjectAccessLogic projectAccessLogic)
{ {
this.projectAccessLogic = projectAccessLogic; this.projectAccessLogic = projectAccessLogic;
@@ -123,16 +128,27 @@ namespace StructureHelper.Windows.MainWindow
} }
traceLogger = new ShiftTraceLogger(); traceLogger = new ShiftTraceLogger();
projectAccessLogic.TraceLogger = traceLogger; projectAccessLogic.TraceLogger = traceLogger;
try
{
var result = projectAccessLogic.OpenProject(); var result = projectAccessLogic.OpenProject();
if (result.IsValid == true) if (result.IsValid == true)
{ {
result.Project.IsActual = true;
result.Project.IsNewFile = false;
ProgramSetting.Projects.Clear();
ProgramSetting.Projects.Add(result.Project); ProgramSetting.Projects.Add(result.Project);
} }
else else
{ {
ProgramSetting.Projects.Add(currentProject); ProgramSetting.Projects.Add(currentProject);
} }
}
catch (Exception ex)
{
traceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
}
ShowEntries(); ShowEntries();
ParentVM.AnalysesLogic.Refresh();
} }
private void ShowEntries() private void ShowEntries()
{ {

View File

@@ -15,7 +15,7 @@ namespace StructureHelper.Windows.MainWindow
public AnalysesManagerViewModel() public AnalysesManagerViewModel()
{ {
FileLogic = new(); FileLogic = new() { ParentVM = this };
FileLogic.CreateNewFile(); FileLogic.CreateNewFile();
DiagramLogic = new(); DiagramLogic = new();
AnalysesLogic = new(); AnalysesLogic = new();

View File

@@ -28,11 +28,11 @@ namespace StructureHelperCommon.Infrastructures.Settings
set set
{ {
natSystem = value; natSystem = value;
codesList = CodeFactory codesList ??= CodeFactory
.GetCodeEntities() .GetCodeEntities()
.Where(x => x.NatSystem == natSystem) .Where(x => x.NatSystem == natSystem)
.ToList(); .ToList();
materialRepository = new MaterialRepository(codesList); materialRepository ??= new MaterialRepository(codesList);
} }
} }
public static GeometryNames GeometryNames => geometryNames ??= new GeometryNames(); public static GeometryNames GeometryNames => geometryNames ??= new GeometryNames();
@@ -53,6 +53,10 @@ namespace StructureHelperCommon.Infrastructures.Settings
{ {
get get
{ {
codesList ??= CodeFactory
.GetCodeEntities()
.Where(x => x.NatSystem == NatSystem)
.ToList();
materialRepository ??= new MaterialRepository(codesList); materialRepository ??= new MaterialRepository(codesList);
return materialRepository; return materialRepository;
} }

View File

@@ -11,6 +11,7 @@ namespace StructureHelperCommon.Models.Analyses
public interface IVisualAnalysis : ISaveable, ICloneable public interface IVisualAnalysis : ISaveable, ICloneable
{ {
IAnalysis Analysis { get; set; } IAnalysis Analysis { get; set; }
Action ActionToRun { get; set; }
void Run(); void Run();
} }
} }

View File

@@ -1,17 +1,16 @@
using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Analyses; using StructureHelperCommon.Models.Analyses;
using StructureHelperLogics.Models.CrossSections;
using System; using System;
namespace StructureHelper.Windows.MainWindow.Analyses namespace StructureHelperCommon.Models.Analyses
{ {
public class VisualAnalysis : IVisualAnalysis public class VisualAnalysis : IVisualAnalysis
{ {
private IUpdateStrategy<IVisualAnalysis> updateStrategy = new VisualAnalysisUpdateStrategy(); private IUpdateStrategy<IVisualAnalysis> updateStrategy = new VisualAnalysisUpdateStrategy();
public Guid Id { get; } public Guid Id { get; }
public IAnalysis Analysis { get; set; } public IAnalysis Analysis { get; set; }
public Action ActionToRun { get; set; }
public VisualAnalysis(Guid id, IAnalysis analysis) public VisualAnalysis(Guid id, IAnalysis analysis)
{ {
@@ -26,25 +25,7 @@ namespace StructureHelper.Windows.MainWindow.Analyses
public void Run() public void Run()
{ {
var version = Analysis.VersionProcessor.GetCurrentVersion(); ActionToRun?.Invoke();
if (version is null)
{
throw new StructureHelperException(ErrorStrings.NullReference);
}
if (version.AnalysisVersion is ICrossSection crossSection)
{
ProcessCrossSection(crossSection);
}
else
{
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(version));
}
}
private void ProcessCrossSection(ICrossSection crossSection)
{
var window = new CrossSectionView(crossSection);
window.ShowDialog();
} }
public object Clone() public object Clone()

View File

@@ -12,12 +12,17 @@ namespace StructureHelperLogic.Models.Analyses
public string Tags { get; set; } public string Tags { get; set; }
public IVersionProcessor VersionProcessor { get; private set; } public IVersionProcessor VersionProcessor { get; private set; }
public CrossSectionNdmAnalysis(Guid Id, IVersionProcessor versionProcessor) public CrossSectionNdmAnalysis(Guid id, IVersionProcessor versionProcessor)
{ {
this.Id = Id; Id = id;
VersionProcessor = versionProcessor; VersionProcessor = versionProcessor;
} }
public CrossSectionNdmAnalysis(Guid id) : this (id, new VersionProcessor())
{
}
public CrossSectionNdmAnalysis() : this(Guid.NewGuid(), new VersionProcessor()) public CrossSectionNdmAnalysis() : this(Guid.NewGuid(), new VersionProcessor())
{ {
CrossSection crossSection = new CrossSection(); CrossSection crossSection = new CrossSection();