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)
{
//to do
}
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;
}
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();
}
}

View File

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

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.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,

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
{
[JsonProperty("Id")]
public Guid Id { get; set; }
public Guid Id { get; set; } = Guid.NewGuid();
[JsonProperty("IterationAccuracy")]
public double IterationAccuracy { get; set; }
[JsonProperty("MaxIterationCount")]

View File

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

View File

@@ -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")]

View File

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

View File

@@ -23,5 +23,9 @@ namespace DataAccess.DTOs
{
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 StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Analyses;
using StructureHelperCommon.Models.Projects;
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(RectangleShapeDTO), "RectangleShape") },
{ (typeof(ReinforcementLibMaterialDTO), "ReinforcementLibMaterial") },
{ (typeof(RootObjectDTO), "RootObject") },
{ (typeof(MaterialPartialFactorDTO), "MaterialPartialFactor") },
{ (typeof(VersionProcessorDTO), "VersionProcessor") },
{ (typeof(VisualAnalysisDTO), "VisualAnalysis") },

View File

@@ -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")]

View File

@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Analyses;
using System;
using System.Collections.Generic;
@@ -15,10 +16,12 @@ namespace DataAccess.DTOs
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()

View File

@@ -3,16 +3,19 @@ using DataAccess.JsonConverters;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Projects;
using StructureHelperCommon.Services.FileServices;
using System.Reflection.Emit;
namespace DataAccess.Infrastructures
{
public class FileOpenLogic : IFileOpenLogic
{
private string fileName;
private Dictionary<(Guid id, Type type), ISaveable> refDictinary;
public IShiftTraceLogger? TraceLogger { get; set; }
@@ -44,47 +47,77 @@ namespace DataAccess.Infrastructures
result.IsValid = false;
return result;
}
if (! File.Exists(fileName))
if (!File.Exists(fileName))
{
result.IsValid = false;
TraceLogger?.AddMessage($"File {fileName} does not exists", TraceLogStatuses.Error);
return result;
}
string jsonData = File.ReadAllText(fileName);
RootObjectDTO? rootObject = GetRootObject(jsonData);
var fileVersion = rootObject.FileVersion;
var checkLogic = new CheckFileVersionLogic()
{
FileVersion = fileVersion,
TraceLogger = TraceLogger
};
var checkResult = checkLogic.Check();
if (checkResult == false)
{
result.IsValid = false;
result.Description += checkLogic.CheckResult;
}
else
{
Project project = GetProject(rootObject);
project.FullFileName = fileName;
result.Project = project;
}
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
// Add other converters if needed
new ProjectDTOJsonConverter(TraceLogger)
},
SerializationBinder = typeBinder,
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()
{
FileVersion = fileVersion,
TraceLogger = TraceLogger
};
var checkResult = checkLogic.Check();
if (checkResult == false)
{
result.IsValid = false;
result.Description += checkLogic.CheckResult;
}
else
{
var currentVersion = ProgramSetting.GetCurrentFileVersion();
TraceLogger.AddMessage($"File version is {fileVersion.VersionNumber}.{fileVersion.SubVersionNumber}, current version is {currentVersion.VersionNumber}.{currentVersion.SubVersionNumber}");
}
}
return result;
return settings;
}
}
}

View File

@@ -1,4 +1,5 @@
using DataAccess.DTOs;
using DataAccess.DTOs.DTOEntities;
using DataAccess.JsonConverters;
using Newtonsoft.Json;
using StructureHelperCommon.Infrastructures.Interfaces;
@@ -55,11 +56,11 @@ namespace DataAccess.Infrastructures
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);
RootObjectDTO rootObject = new() { FileVersion = versionDTO, Project = projectDTO };
var rootString = Serialize(rootObject, TraceLogger);
SaveStringToFile(project, rootString);
}
catch (Exception ex)
{
@@ -72,7 +73,7 @@ namespace DataAccess.Infrastructures
{
try
{
File.AppendAllText(project.FullFileName, versionString);
File.WriteAllText(project.FullFileName, versionString);
TraceLogger?.AddMessage($"File {project.FullFileName} was saved successfully", TraceLogStatuses.Service);
}
catch (Exception ex)

View File

@@ -1,8 +1,10 @@
using StructureHelper.Infrastructure;
using StructureHelper.Windows.MainWindow.Analyses;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Models.Analyses;
using StructureHelperLogic.Models.Analyses;
using StructureHelperLogics.Models.CrossSections;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -114,6 +116,8 @@ namespace StructureHelper.Windows.MainWindow
}
private void RunAnalysis()
{
if (SelectedAnalysis is null) { return; }
SelectedAnalysis.ActionToRun = ActionToRun;
SelectedAnalysis?.Run();
}
private void AddCrossSectionNdmAnalysis()
@@ -124,5 +128,29 @@ namespace StructureHelper.Windows.MainWindow
var visualAnalysis = new VisualAnalysis(analysis);
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 StructureHelper.Infrastructure;
using StructureHelper.Windows.CalculationWindows.ProgressViews;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses;
using StructureHelperCommon.Models.Projects;
using StructureHelperLogics.Models.CrossSections;
using System;
using System.Linq;
using System.Windows.Forms;
@@ -22,6 +25,8 @@ namespace StructureHelper.Windows.MainWindow
private IProjectAccessLogic projectAccessLogic;
private RelayCommand fileSaveAs;
public AnalysesManagerViewModel ParentVM { get; set; }
public FileLogic(IProjectAccessLogic projectAccessLogic)
{
this.projectAccessLogic = projectAccessLogic;
@@ -123,16 +128,27 @@ namespace StructureHelper.Windows.MainWindow
}
traceLogger = new ShiftTraceLogger();
projectAccessLogic.TraceLogger = traceLogger;
var result = projectAccessLogic.OpenProject();
if (result.IsValid == true)
try
{
ProgramSetting.Projects.Add(result.Project);
var result = projectAccessLogic.OpenProject();
if (result.IsValid == true)
{
result.Project.IsActual = true;
result.Project.IsNewFile = false;
ProgramSetting.Projects.Clear();
ProgramSetting.Projects.Add(result.Project);
}
else
{
ProgramSetting.Projects.Add(currentProject);
}
}
else
catch (Exception ex)
{
ProgramSetting.Projects.Add(currentProject);
traceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
}
ShowEntries();
ParentVM.AnalysesLogic.Refresh();
}
private void ShowEntries()
{

View File

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

View File

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

View File

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

View File

@@ -1,17 +1,16 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Analyses;
using StructureHelperLogics.Models.CrossSections;
using System;
namespace StructureHelper.Windows.MainWindow.Analyses
namespace StructureHelperCommon.Models.Analyses
{
public class VisualAnalysis : IVisualAnalysis
{
private IUpdateStrategy<IVisualAnalysis> updateStrategy = new VisualAnalysisUpdateStrategy();
public Guid Id { get; }
public IAnalysis Analysis { get; set; }
public Action ActionToRun { get; set; }
public VisualAnalysis(Guid id, IAnalysis analysis)
{
@@ -26,25 +25,7 @@ namespace StructureHelper.Windows.MainWindow.Analyses
public void Run()
{
var version = 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();
ActionToRun?.Invoke();
}
public object Clone()

View File

@@ -12,12 +12,17 @@ namespace StructureHelperLogic.Models.Analyses
public string Tags { get; 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;
}
public CrossSectionNdmAnalysis(Guid id) : this (id, new VersionProcessor())
{
}
public CrossSectionNdmAnalysis() : this(Guid.NewGuid(), new VersionProcessor())
{
CrossSection crossSection = new CrossSection();