Change open and save file logic
This commit is contained in:
@@ -77,7 +77,7 @@ namespace DataAccess.DTOs.Converters
|
|||||||
versionProcessorConvertStrategy.ReferenceDictionary = ReferenceDictionary;
|
versionProcessorConvertStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||||
versionProcessorConvertStrategy.TraceLogger = TraceLogger;
|
versionProcessorConvertStrategy.TraceLogger = TraceLogger;
|
||||||
IVersionProcessor versionProcessor = versionProcessorConvertStrategy.Convert(source);
|
IVersionProcessor versionProcessor = versionProcessorConvertStrategy.Convert(source);
|
||||||
TraceLogger?.AddMessage("Version processor converting has been finished succesfully", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage("Version processor converting has been finished successfully", TraceLogStatuses.Service);
|
||||||
return versionProcessor;
|
return versionProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ namespace DataAccess.DTOs.Converters
|
|||||||
convertCrossSectionNdmAnalysisStrategy.TraceLogger = TraceLogger;
|
convertCrossSectionNdmAnalysisStrategy.TraceLogger = TraceLogger;
|
||||||
var convertLogic = new DictionaryConvertStrategy<ICrossSectionNdmAnalysis, ICrossSectionNdmAnalysis>(this, convertCrossSectionNdmAnalysisStrategy);
|
var convertLogic = new DictionaryConvertStrategy<ICrossSectionNdmAnalysis, ICrossSectionNdmAnalysis>(this, convertCrossSectionNdmAnalysisStrategy);
|
||||||
ICrossSectionNdmAnalysis crossSectionNdmAnalysis = convertLogic.Convert(source);
|
ICrossSectionNdmAnalysis crossSectionNdmAnalysis = convertLogic.Convert(source);
|
||||||
TraceLogger?.AddMessage("Cross-Section Ndm Analysis converting has been finished succesfully", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage("Cross-Section Ndm Analysis converting has been finished successfully", TraceLogStatuses.Service);
|
||||||
return crossSectionNdmAnalysis;
|
return crossSectionNdmAnalysis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace DataAccess.DTOs
|
|||||||
TraceLogger?.AddMessage("Concrete library material converting is started", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage("Concrete library material converting is started", TraceLogStatuses.Service);
|
||||||
ConcreteLibMaterial newItem = new(source.Id);
|
ConcreteLibMaterial newItem = new(source.Id);
|
||||||
updateStrategy.Update(newItem, source);
|
updateStrategy.Update(newItem, source);
|
||||||
TraceLogger?.AddMessage("Concrete library material converting has been finished succesfully", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage("Concrete library material converting has been finished successfully", TraceLogStatuses.Service);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace DataAccess.DTOs
|
|||||||
convertStrategy.ReferenceDictionary = ReferenceDictionary;
|
convertStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||||
convertStrategy.TraceLogger = TraceLogger;
|
convertStrategy.TraceLogger = TraceLogger;
|
||||||
newItem.SectionRepository = GetNewCrossSectionRepository(source.SectionRepository);
|
newItem.SectionRepository = GetNewCrossSectionRepository(source.SectionRepository);
|
||||||
TraceLogger?.AddMessage("Cross-Section converting has been finished succesfully", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage("Cross-Section converting has been finished successfully", TraceLogStatuses.Service);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace DataAccess.DTOs.Converters
|
|||||||
TraceLogger?.AddMessage("Cross-section sonverting is started");
|
TraceLogger?.AddMessage("Cross-section sonverting is started");
|
||||||
CrossSectionNdmAnalysis newItem = new(source.Id);
|
CrossSectionNdmAnalysis newItem = new(source.Id);
|
||||||
updateStrategy.Update(newItem, source);
|
updateStrategy.Update(newItem, source);
|
||||||
TraceLogger?.AddMessage("Cross-section analysis was obtained succesfully");
|
TraceLogger?.AddMessage("Cross-section analysis was obtained successfully");
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ namespace DataAccess.DTOs.Converters
|
|||||||
};
|
};
|
||||||
TraceLogger?.AddMessage("Convert version processor is started", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage("Convert version processor is started", TraceLogStatuses.Service);
|
||||||
newItem.VersionProcessor = convertLogic.Convert(source.VersionProcessor);
|
newItem.VersionProcessor = convertLogic.Convert(source.VersionProcessor);
|
||||||
TraceLogger?.AddMessage("Cross-section ndm analysis has been converted succesfully", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage("Cross-section ndm analysis has been converted successfully", TraceLogStatuses.Service);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace DataAccess.DTOs
|
|||||||
public class CrossSectionRepositoryFromDTOConvertStrategy : ConvertStrategy<ICrossSectionRepository, ICrossSectionRepository>
|
public class CrossSectionRepositoryFromDTOConvertStrategy : ConvertStrategy<ICrossSectionRepository, ICrossSectionRepository>
|
||||||
{
|
{
|
||||||
private const string convertStarted = " converting is started";
|
private const string convertStarted = " converting is started";
|
||||||
private const string convertFinished = " converting has been finished succesfully";
|
private const string convertFinished = " converting has been finished successfully";
|
||||||
private CrossSectionRepository newRepository;
|
private CrossSectionRepository newRepository;
|
||||||
|
|
||||||
private IHasPrimitivesProcessLogic primitivesProcessLogic = new HasPrimitivesProcessLogic();
|
private IHasPrimitivesProcessLogic primitivesProcessLogic = new HasPrimitivesProcessLogic();
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace DataAccess.DTOs
|
|||||||
TraceLogger?.AddMessage("Elastic material converting is started", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage("Elastic material converting is started", TraceLogStatuses.Service);
|
||||||
ElasticMaterial newItem = new(source.Id);
|
ElasticMaterial newItem = new(source.Id);
|
||||||
updateStrategy.Update(newItem, source);
|
updateStrategy.Update(newItem, source);
|
||||||
TraceLogger?.AddMessage("Elastic material converting has been finished succesfully", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage("Elastic material converting has been finished successfully", TraceLogStatuses.Service);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace DataAccess.DTOs
|
|||||||
TraceLogger?.AddMessage("Fiber reinforcement material converting is started", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage("Fiber reinforcement material converting is started", TraceLogStatuses.Service);
|
||||||
FRMaterial newItem = new(source.MaterialType, source.Id);
|
FRMaterial newItem = new(source.MaterialType, source.Id);
|
||||||
updateStrategy.Update(newItem, source);
|
updateStrategy.Update(newItem, source);
|
||||||
TraceLogger?.AddMessage("FiberReinforcement material converting has been finished succesfully", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage("FiberReinforcement material converting has been finished successfully", TraceLogStatuses.Service);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace DataAccess.DTOs
|
|||||||
TraceLogger?.AddMessage($"Mx = {newDesignTuple.ForceTuple.Mx}, My = {newDesignTuple.ForceTuple.My}, Nz = {newDesignTuple.ForceTuple.Nz}");
|
TraceLogger?.AddMessage($"Mx = {newDesignTuple.ForceTuple.Mx}, My = {newDesignTuple.ForceTuple.My}, Nz = {newDesignTuple.ForceTuple.Nz}");
|
||||||
newItem.DesignForces.Add(newDesignTuple);
|
newItem.DesignForces.Add(newDesignTuple);
|
||||||
}
|
}
|
||||||
TraceLogger?.AddMessage($"Force combination list name = {newItem.Name} has been finished succesfully");
|
TraceLogger?.AddMessage($"Force combination list name = {newItem.Name} has been finished successfully");
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace DataAccess.DTOs
|
|||||||
public class HasForceActionsProcessLogic : IHasForceActionsProcessLogic
|
public class HasForceActionsProcessLogic : IHasForceActionsProcessLogic
|
||||||
{
|
{
|
||||||
private const string convertStarted = " converting is started";
|
private const string convertStarted = " converting is started";
|
||||||
private const string convertFinished = " converting has been finished succesfully";
|
private const string convertFinished = " converting has been finished successfully";
|
||||||
|
|
||||||
public IShiftTraceLogger TraceLogger { get; set; }
|
public IShiftTraceLogger TraceLogger { get; set; }
|
||||||
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace DataAccess.DTOs.Converters
|
|||||||
public class HasPrimitivesProcessLogic : IHasPrimitivesProcessLogic
|
public class HasPrimitivesProcessLogic : IHasPrimitivesProcessLogic
|
||||||
{
|
{
|
||||||
private const string convertStarted = " converting is started";
|
private const string convertStarted = " converting is started";
|
||||||
private const string convertFinished = " converting has been finished succesfully";
|
private const string convertFinished = " converting has been finished successfully";
|
||||||
|
|
||||||
public IHasPrimitives Source { get; set; }
|
public IHasPrimitives Source { get; set; }
|
||||||
public IHasPrimitives Target { get; set; }
|
public IHasPrimitives Target { get; set; }
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ namespace DataAccess.DTOs
|
|||||||
IHelperMaterial helperMaterial = GetHelperMaterial(source.HelperMaterial);
|
IHelperMaterial helperMaterial = GetHelperMaterial(source.HelperMaterial);
|
||||||
newItem.HelperMaterial = helperMaterial;
|
newItem.HelperMaterial = helperMaterial;
|
||||||
//GlobalRepository
|
//GlobalRepository
|
||||||
TraceLogger?.AddMessage($"Head material Name = {newItem.Name} converting has been finished succesfully", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage($"Head material Name = {newItem.Name} converting has been finished successfully", TraceLogStatuses.Service);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ namespace DataAccess.DTOs
|
|||||||
rebarConvertStrategy.ReferenceDictionary = ReferenceDictionary;
|
rebarConvertStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||||
rebarConvertStrategy.TraceLogger = TraceLogger;
|
rebarConvertStrategy.TraceLogger = TraceLogger;
|
||||||
RebarNdmPrimitive newItem = rebarConvertStrategy.Convert(rebar);
|
RebarNdmPrimitive newItem = rebarConvertStrategy.Convert(rebar);
|
||||||
TraceLogger?.AddMessage($"Primtive has been obtained succesfully, Name = {newItem.Name}");
|
TraceLogger?.AddMessage($"Primtive has been obtained successfully, Name = {newItem.Name}");
|
||||||
newItem.HostPrimitive = GetHostPrimitive(rebar);
|
newItem.HostPrimitive = GetHostPrimitive(rebar);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ namespace DataAccess.DTOs
|
|||||||
pointConvertStrategy.ReferenceDictionary = ReferenceDictionary;
|
pointConvertStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||||
pointConvertStrategy.TraceLogger = TraceLogger;
|
pointConvertStrategy.TraceLogger = TraceLogger;
|
||||||
PointNdmPrimitive newItem = pointConvertStrategy.Convert(point);
|
PointNdmPrimitive newItem = pointConvertStrategy.Convert(point);
|
||||||
TraceLogger?.AddMessage($"Primtive has been obtained succesfully, Name = {newItem.Name}");
|
TraceLogger?.AddMessage($"Primtive has been obtained successfully, Name = {newItem.Name}");
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ namespace DataAccess.DTOs
|
|||||||
ellipseConvertStrategy.ReferenceDictionary = ReferenceDictionary;
|
ellipseConvertStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||||
ellipseConvertStrategy.TraceLogger = TraceLogger;
|
ellipseConvertStrategy.TraceLogger = TraceLogger;
|
||||||
EllipseNdmPrimitive newItem = ellipseConvertStrategy.Convert(ellipse);
|
EllipseNdmPrimitive newItem = ellipseConvertStrategy.Convert(ellipse);
|
||||||
TraceLogger?.AddMessage($"Primtive has been obtained succesfully, Name = {newItem.Name}");
|
TraceLogger?.AddMessage($"Primtive has been obtained successfully, Name = {newItem.Name}");
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ namespace DataAccess.DTOs
|
|||||||
rectangleConvertStrategy.ReferenceDictionary = ReferenceDictionary;
|
rectangleConvertStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||||
rectangleConvertStrategy.TraceLogger = TraceLogger;
|
rectangleConvertStrategy.TraceLogger = TraceLogger;
|
||||||
RectangleNdmPrimitive newItem = rectangleConvertStrategy.Convert(rectangle);
|
RectangleNdmPrimitive newItem = rectangleConvertStrategy.Convert(rectangle);
|
||||||
TraceLogger?.AddMessage($"Primtive has been obtained succesfully, Name = {newItem.Name}");
|
TraceLogger?.AddMessage($"Primtive has been obtained successfully, Name = {newItem.Name}");
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,82 +1,69 @@
|
|||||||
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 System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DataAccess.DTOs
|
namespace DataAccess.DTOs
|
||||||
{
|
{
|
||||||
public class ProjectFromDTOConvertStrategy : IConvertStrategy<Project, ProjectDTO>
|
public class ProjectFromDTOConvertStrategy : ConvertStrategy<Project, ProjectDTO>
|
||||||
{
|
{
|
||||||
private IUpdateStrategy<IProject> updateStrategy;
|
private IUpdateStrategy<IProject> _updateStrategy;
|
||||||
private IConvertStrategy<IVisualAnalysis, IVisualAnalysis> visualAnalysisConvertStrategy = new VisualAnaysisFromDTOConvertStrategy();
|
private IConvertStrategy<IVisualAnalysis, IVisualAnalysis> _convertLogic;
|
||||||
|
|
||||||
public ProjectFromDTOConvertStrategy(IUpdateStrategy<IProject> updateStrategy)
|
public ProjectFromDTOConvertStrategy(IUpdateStrategy<IProject> updateStrategy,
|
||||||
|
IConvertStrategy<IVisualAnalysis, IVisualAnalysis> convertLogic,
|
||||||
|
Dictionary<(Guid id, Type type), ISaveable> refDictinary,
|
||||||
|
IShiftTraceLogger? traceLogger)
|
||||||
{
|
{
|
||||||
this.updateStrategy = updateStrategy;
|
_updateStrategy = updateStrategy;
|
||||||
|
_convertLogic = convertLogic;
|
||||||
|
ReferenceDictionary = refDictinary;
|
||||||
|
TraceLogger = traceLogger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectFromDTOConvertStrategy() : this (new ProjectUpdateStrategy())
|
public ProjectFromDTOConvertStrategy(
|
||||||
{
|
Dictionary<(Guid id, Type type), ISaveable> refDictinary,
|
||||||
|
IShiftTraceLogger? traceLogger)
|
||||||
}
|
: this(
|
||||||
|
new ProjectUpdateStrategy(),
|
||||||
|
new DictionaryConvertStrategy<IVisualAnalysis, IVisualAnalysis>(
|
||||||
|
refDictinary,
|
||||||
|
new VisualAnaysisFromDTOConvertStrategy(refDictinary, traceLogger),
|
||||||
|
traceLogger),
|
||||||
|
refDictinary,
|
||||||
|
traceLogger)
|
||||||
|
{ }
|
||||||
|
|
||||||
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
public override Project GetNewItem(ProjectDTO source)
|
||||||
public IShiftTraceLogger TraceLogger { get; set; }
|
{
|
||||||
|
TraceLogger?.AddMessage("Converting of project is started");
|
||||||
public Project Convert(ProjectDTO source)
|
Project newItem = new(source.Id);
|
||||||
{
|
List<IVisualAnalysis> analyses = GetAnalyses(source, newItem);
|
||||||
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)
|
|
||||||
{
|
|
||||||
TraceLogger?.AddMessage("Converting of project is started", TraceLogStatuses.Service);
|
|
||||||
Project newItem = new();
|
|
||||||
updateStrategy.Update(newItem, source);
|
|
||||||
visualAnalysisConvertStrategy.ReferenceDictionary = ReferenceDictionary;
|
|
||||||
visualAnalysisConvertStrategy.TraceLogger = TraceLogger;
|
|
||||||
var convertLogic = new DictionaryConvertStrategy<IVisualAnalysis, IVisualAnalysis>(this, visualAnalysisConvertStrategy);
|
|
||||||
newItem.VisualAnalyses.Clear();
|
newItem.VisualAnalyses.Clear();
|
||||||
TraceLogger?.AddMessage($"Source project has {source.VisualAnalyses.Count()} analyses", TraceLogStatuses.Service);
|
newItem.VisualAnalyses.AddRange(analyses);
|
||||||
foreach (var item in source.VisualAnalyses)
|
|
||||||
{
|
|
||||||
var visualAnalysis = convertLogic.Convert(item);
|
|
||||||
newItem.VisualAnalyses.Add(visualAnalysis);
|
|
||||||
}
|
|
||||||
if (newItem.VisualAnalyses.Any())
|
if (newItem.VisualAnalyses.Any())
|
||||||
{
|
{
|
||||||
TraceLogger?.AddMessage($"Totaly {newItem.VisualAnalyses.Count()} were(was) obtained", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage($"Totaly {newItem.VisualAnalyses.Count} were(was) obtained");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TraceLogger?.AddMessage($"Project does not have any analyses", TraceLogStatuses.Warning);
|
TraceLogger?.AddMessage($"Project does not have any analyses, it is possible to work with project", TraceLogStatuses.Warning);
|
||||||
}
|
}
|
||||||
TraceLogger?.AddMessage("Converting of project has completed succesfully", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage("Converting of project has been finished successfully");
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Check()
|
public List<IVisualAnalysis> GetAnalyses(ProjectDTO source, Project newItem)
|
||||||
{
|
{
|
||||||
var checkLogic = new CheckConvertLogic<Project, ProjectDTO>(this);
|
_updateStrategy.Update(newItem, source);
|
||||||
checkLogic.Check();
|
TraceLogger?.AddMessage($"Source project has {source.VisualAnalyses.Count} analyses");
|
||||||
|
List<IVisualAnalysis> analyses = new();
|
||||||
|
foreach (var item in source.VisualAnalyses)
|
||||||
|
{
|
||||||
|
var visualAnalysis = _convertLogic.Convert(item);
|
||||||
|
analyses.Add(visualAnalysis);
|
||||||
|
}
|
||||||
|
return analyses;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace DataAccess.DTOs
|
|||||||
TraceLogger?.AddMessage("Reinforcement library material converting is started", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage("Reinforcement library material converting is started", TraceLogStatuses.Service);
|
||||||
ReinforcementLibMaterial newItem = new(source.Id);
|
ReinforcementLibMaterial newItem = new(source.Id);
|
||||||
updateStrategy.Update(newItem, source);
|
updateStrategy.Update(newItem, source);
|
||||||
TraceLogger?.AddMessage("Reinforcement library material converting has been finished succesfully", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage("Reinforcement library material converting has been finished successfully", TraceLogStatuses.Service);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ namespace DataAccess.DTOs
|
|||||||
crossSectionConvertStrategy.TraceLogger = TraceLogger;
|
crossSectionConvertStrategy.TraceLogger = TraceLogger;
|
||||||
var convertLogic = new DictionaryConvertStrategy<ICrossSection, ICrossSection>(this, crossSectionConvertStrategy);
|
var convertLogic = new DictionaryConvertStrategy<ICrossSection, ICrossSection>(this, crossSectionConvertStrategy);
|
||||||
ICrossSection newItem = convertLogic.Convert(source);
|
ICrossSection newItem = convertLogic.Convert(source);
|
||||||
TraceLogger?.AddMessage("Cross-Section converting has been finished succesfully", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage("Cross-Section converting has been finished successfully", TraceLogStatuses.Service);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace DataAccess.DTOs
|
|||||||
newItem.Versions.Add(dateVersion);
|
newItem.Versions.Add(dateVersion);
|
||||||
}
|
}
|
||||||
TraceLogger?.AddMessage($"Totaly {newItem.Versions.Count} version(s) was(were) obtained", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage($"Totaly {newItem.Versions.Count} version(s) was(were) obtained", TraceLogStatuses.Service);
|
||||||
TraceLogger?.AddMessage("Version processor has been converted succesfully", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage("Version processor has been converted successfully", TraceLogStatuses.Service);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,42 +12,37 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace DataAccess.DTOs
|
namespace DataAccess.DTOs
|
||||||
{
|
{
|
||||||
public class VisualAnaysisFromDTOConvertStrategy : IConvertStrategy<IVisualAnalysis, IVisualAnalysis>
|
public class VisualAnaysisFromDTOConvertStrategy : ConvertStrategy<IVisualAnalysis, IVisualAnalysis>
|
||||||
{
|
{
|
||||||
private IConvertStrategy<IAnalysis, IAnalysis> analysisConvertStrategy = new AnalysisFromDTOConvertStrategy();
|
private IConvertStrategy<IAnalysis, IAnalysis> analysisConvertStrategy;
|
||||||
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
|
||||||
public IShiftTraceLogger TraceLogger { get; set; }
|
|
||||||
|
|
||||||
public IVisualAnalysis Convert(IVisualAnalysis source)
|
public VisualAnaysisFromDTOConvertStrategy(IConvertStrategy<IAnalysis, IAnalysis> analysisConvertStrategy,
|
||||||
|
Dictionary<(Guid id, Type type), ISaveable> refDictinary,
|
||||||
|
IShiftTraceLogger? traceLogger)
|
||||||
{
|
{
|
||||||
Check();
|
this.analysisConvertStrategy = analysisConvertStrategy;
|
||||||
try
|
ReferenceDictionary = refDictinary;
|
||||||
{
|
TraceLogger = traceLogger;
|
||||||
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)
|
public VisualAnaysisFromDTOConvertStrategy(
|
||||||
|
Dictionary<(Guid id, Type type), ISaveable> refDictinary,
|
||||||
|
IShiftTraceLogger? traceLogger)
|
||||||
|
: this(
|
||||||
|
new AnalysisFromDTOConvertStrategy(),
|
||||||
|
refDictinary,
|
||||||
|
traceLogger)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public override VisualAnalysis GetNewItem(IVisualAnalysis source)
|
||||||
{
|
{
|
||||||
|
TraceLogger?.AddMessage($"Visual Analysis Name = {source.Analysis.Name} converting is started");
|
||||||
analysisConvertStrategy.ReferenceDictionary = ReferenceDictionary;
|
analysisConvertStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||||
analysisConvertStrategy.TraceLogger = TraceLogger;
|
analysisConvertStrategy.TraceLogger = TraceLogger;
|
||||||
IAnalysis analysis = analysisConvertStrategy.Convert(source.Analysis);
|
IAnalysis analysis = analysisConvertStrategy.Convert(source.Analysis);
|
||||||
VisualAnalysis newItem = new(source.Id, analysis);
|
VisualAnalysis newItem = new(source.Id, analysis);
|
||||||
TraceLogger?.AddMessage($"Visual Analysis was obtained succesfully", TraceLogStatuses.Debug);
|
TraceLogger?.AddMessage($"Visual Analysis Name = {newItem.Analysis.Name} was obtained successfully");
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Check()
|
|
||||||
{
|
|
||||||
var checkLogic = new CheckConvertLogic<IVisualAnalysis, IVisualAnalysis>(this);
|
|
||||||
checkLogic.Check();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace DataAccess.DTOs
|
|||||||
public bool IsActual { get; set; }
|
public bool IsActual { get; set; }
|
||||||
|
|
||||||
[JsonProperty("VisualAnalyses")]
|
[JsonProperty("VisualAnalyses")]
|
||||||
public List<IVisualAnalysis> VisualAnalyses { get; private set; } = new();
|
public List<IVisualAnalysis> VisualAnalyses { get; set; } = new();
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string FileName { get; set; }
|
public string FileName { get; set; }
|
||||||
|
|||||||
75
DataAccess/Infrastructures/CheckRootObjectLogic.cs
Normal file
75
DataAccess/Infrastructures/CheckRootObjectLogic.cs
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
using DataAccess.DTOs;
|
||||||
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
using StructureHelperCommon.Models;
|
||||||
|
using StructureHelperCommon.Models.Projects;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DataAccess.Infrastructures
|
||||||
|
{
|
||||||
|
public class CheckRootObjectLogic : ICheckEntityLogic<IRootObjectDTO>
|
||||||
|
{
|
||||||
|
public IRootObjectDTO Entity { get; set; }
|
||||||
|
|
||||||
|
public string CheckResult { get; private set; }
|
||||||
|
|
||||||
|
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||||
|
|
||||||
|
public CheckRootObjectLogic(IShiftTraceLogger? traceLogger)
|
||||||
|
{
|
||||||
|
TraceLogger = traceLogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Check()
|
||||||
|
{
|
||||||
|
bool result = true;
|
||||||
|
string checkResult = string.Empty;
|
||||||
|
var checkRootResult = CheckRootObject();
|
||||||
|
if (checkRootResult.checkResult = false)
|
||||||
|
{
|
||||||
|
checkResult += checkRootResult.errorString;
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
CheckResult = checkResult;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private (bool checkResult, string errorString) CheckRootObject()
|
||||||
|
{
|
||||||
|
bool checkRootResult = true;
|
||||||
|
string errorString = string.Empty;
|
||||||
|
|
||||||
|
if (Entity.FileVersion is null)
|
||||||
|
{
|
||||||
|
checkRootResult = false;
|
||||||
|
errorString += "Section of file version is damaged";
|
||||||
|
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
|
||||||
|
return (checkRootResult, errorString);
|
||||||
|
}
|
||||||
|
var fileVersion = Entity.FileVersion;
|
||||||
|
var checkLogic = new CheckFileVersionLogic()
|
||||||
|
{
|
||||||
|
FileVersion = fileVersion,
|
||||||
|
TraceLogger = TraceLogger
|
||||||
|
};
|
||||||
|
var checkResult = checkLogic.Check();
|
||||||
|
if (checkResult == false)
|
||||||
|
{
|
||||||
|
checkRootResult = false;
|
||||||
|
errorString += checkLogic.CheckResult;
|
||||||
|
return (checkRootResult, errorString);
|
||||||
|
}
|
||||||
|
if (Entity.Project is null)
|
||||||
|
{
|
||||||
|
checkRootResult = false;
|
||||||
|
errorString += "Section of project is damaged";
|
||||||
|
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
|
||||||
|
return (checkRootResult, errorString);
|
||||||
|
}
|
||||||
|
return (checkRootResult, errorString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,10 +16,41 @@ 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;
|
private IGetProjectLogic getProjectLogic;
|
||||||
|
|
||||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||||
|
|
||||||
|
public OpenProjectResult OpenFile()
|
||||||
|
{
|
||||||
|
var result = new OpenProjectResult()
|
||||||
|
{
|
||||||
|
IsValid = true
|
||||||
|
};
|
||||||
|
if (GetFilePath() == false)
|
||||||
|
{
|
||||||
|
result.IsValid = false;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return OpenFile(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenProjectResult OpenFile(string fileName)
|
||||||
|
{
|
||||||
|
var result = new OpenProjectResult()
|
||||||
|
{
|
||||||
|
IsValid = true
|
||||||
|
};
|
||||||
|
if (!File.Exists(fileName))
|
||||||
|
{
|
||||||
|
result.IsValid = false;
|
||||||
|
TraceLogger?.AddMessage($"File {fileName} does not exists", TraceLogStatuses.Error);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
getProjectLogic = new GetProjectLogic(TraceLogger);
|
||||||
|
getProjectLogic.TraceLogger = TraceLogger;
|
||||||
|
getProjectLogic.FileName = fileName;
|
||||||
|
return getProjectLogic.GetProject();
|
||||||
|
}
|
||||||
|
|
||||||
private bool GetFilePath()
|
private bool GetFilePath()
|
||||||
{
|
{
|
||||||
var inputData = new OpenFileInputData()
|
var inputData = new OpenFileInputData()
|
||||||
@@ -37,106 +68,6 @@ namespace DataAccess.Infrastructures
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenProjectResult OpenFile()
|
|
||||||
{
|
|
||||||
var result = new OpenProjectResult()
|
|
||||||
{
|
|
||||||
IsValid = true
|
|
||||||
};
|
|
||||||
if (GetFilePath() == false)
|
|
||||||
{
|
|
||||||
result.IsValid = false;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
if (rootObject.FileVersion is null)
|
|
||||||
{
|
|
||||||
var errorString = "Section of file version is damaged";
|
|
||||||
result.Description += errorString;
|
|
||||||
result.IsValid = false;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
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
|
|
||||||
{
|
|
||||||
if (rootObject.Project is null)
|
|
||||||
{
|
|
||||||
var errorString = "Section of project is damaged";
|
|
||||||
result.Description += errorString;
|
|
||||||
result.IsValid = false;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
Project project = GetProject(rootObject);
|
|
||||||
project.FullFileName = fileName;
|
|
||||||
result.Project = project;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Project GetProject(RootObjectDTO? rootObject)
|
|
||||||
{
|
|
||||||
if (rootObject.Project is null)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
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();
|
|
||||||
RootObjectDTO 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,24 +12,33 @@ namespace DataAccess.Infrastructures
|
|||||||
{
|
{
|
||||||
public class FileSaveLogic : IFileSaveLogic
|
public class FileSaveLogic : IFileSaveLogic
|
||||||
{
|
{
|
||||||
private IFileVersion version;
|
|
||||||
private Dictionary<(Guid id, Type type), ISaveable> refDictinary;
|
|
||||||
|
|
||||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||||
|
|
||||||
public void SaveFile(IProject project)
|
public SaveFileResult SaveFile(IProject project)
|
||||||
{
|
{
|
||||||
|
SaveFileResult result = new();
|
||||||
if (project.FullFileName == string.Empty || project.FullFileName == "")
|
if (project.FullFileName == string.Empty || project.FullFileName == "")
|
||||||
{
|
{
|
||||||
var result = SelectFileName(project);
|
var selectResult = SelectFileName(project);
|
||||||
if (result.IsValid == false)
|
if (selectResult.IsValid == false)
|
||||||
{
|
{
|
||||||
TraceLogger?.AddMessage(result.Description);
|
TraceLogger?.AddMessage(selectResult.Description);
|
||||||
return;
|
result.IsValid = false;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
project.FullFileName = result.FileName;
|
project.FullFileName = selectResult.FileName;
|
||||||
}
|
}
|
||||||
SaveToFile(project);
|
result.FileName = project.FullFileName;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SaveToFile(project);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
result.IsValid = false;
|
||||||
|
result.Description += ex.Message;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SaveFileResult SelectFileName(IProject project)
|
private SaveFileResult SelectFileName(IProject project)
|
||||||
@@ -47,115 +56,24 @@ namespace DataAccess.Infrastructures
|
|||||||
|
|
||||||
private void SaveToFile(IProject project)
|
private void SaveToFile(IProject project)
|
||||||
{
|
{
|
||||||
try
|
ISaveProjectToFileLogic saveProjectLogic = new SaveProjectToFileLogic(TraceLogger)
|
||||||
{
|
{
|
||||||
version = ProgramSetting.GetCurrentFileVersion();
|
Project = project
|
||||||
refDictinary = new Dictionary<(Guid id, Type type), ISaveable>();
|
|
||||||
FileVersionDTO versionDTO = GetVersionDTO();
|
|
||||||
var versionString = Serialize(versionDTO, TraceLogger);
|
|
||||||
File.Delete(project.FullFileName);
|
|
||||||
refDictinary = new Dictionary<(Guid id, Type type), ISaveable>();
|
|
||||||
ProjectDTO projectDTO = GetProjectDTO(project);
|
|
||||||
RootObjectDTO rootObject = new()
|
|
||||||
{
|
|
||||||
FileVersion = versionDTO,
|
|
||||||
Project = projectDTO
|
|
||||||
};
|
|
||||||
var rootString = Serialize(rootObject, TraceLogger);
|
|
||||||
SaveStringToFile(project, rootString);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SaveStringToFile(IProject project, string versionString)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File.WriteAllText(project.FullFileName, versionString);
|
|
||||||
TraceLogger?.AddMessage($"File {project.FullFileName} was saved successfully", TraceLogStatuses.Service);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ProjectDTO GetProjectDTO(IProject project)
|
|
||||||
{
|
|
||||||
ProjectToDTOConvertStrategy convertStrategy = new()
|
|
||||||
{
|
|
||||||
ReferenceDictionary = refDictinary,
|
|
||||||
TraceLogger = TraceLogger
|
|
||||||
};
|
};
|
||||||
DictionaryConvertStrategy<ProjectDTO, IProject> dictionaryConvertStrategy = new()
|
saveProjectLogic.SaveProject();
|
||||||
{
|
|
||||||
ConvertStrategy = convertStrategy,
|
|
||||||
ReferenceDictionary = refDictinary,
|
|
||||||
TraceLogger = TraceLogger
|
|
||||||
};
|
|
||||||
ProjectDTO projectDTO = dictionaryConvertStrategy.Convert(project);
|
|
||||||
return projectDTO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileVersionDTO GetVersionDTO()
|
|
||||||
{
|
|
||||||
FileVersionToDTOConvertStrategy fileVersionDTOConvertStrategy = new()
|
|
||||||
{
|
|
||||||
ReferenceDictionary = refDictinary,
|
|
||||||
TraceLogger = TraceLogger
|
|
||||||
};
|
|
||||||
DictionaryConvertStrategy<FileVersionDTO,IFileVersion> dictionaryConvertStrategy = new()
|
|
||||||
{
|
|
||||||
ConvertStrategy = fileVersionDTOConvertStrategy,
|
|
||||||
ReferenceDictionary = refDictinary,
|
|
||||||
TraceLogger = TraceLogger
|
|
||||||
};
|
|
||||||
var versionDTO = dictionaryConvertStrategy.Convert(version);
|
|
||||||
return versionDTO;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string Serialize(object obj, IShiftTraceLogger logger)
|
public SaveFileResult SaveFileAs(IProject project)
|
||||||
{
|
|
||||||
JsonSerializerSettings settings = GetSerializingSettings(logger);
|
|
||||||
string serializedObject = JsonConvert.SerializeObject(obj, settings);
|
|
||||||
return serializedObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static JsonSerializerSettings GetSerializingSettings(IShiftTraceLogger logger)
|
|
||||||
{
|
|
||||||
List<(Type type, string name)> typesNames = TypeBinderListFactory.GetTypeNameList(TypeFileVersion.version_v1);
|
|
||||||
TypeBinder typeBinder = new(typesNames);
|
|
||||||
List<JsonConverter> jsonConverters = new List<JsonConverter>
|
|
||||||
{
|
|
||||||
new FileVersionDTOJsonConverter(logger),
|
|
||||||
new ProjectDTOJsonConverter(logger)
|
|
||||||
};
|
|
||||||
|
|
||||||
var settings = new JsonSerializerSettings
|
|
||||||
{
|
|
||||||
Converters = jsonConverters,
|
|
||||||
SerializationBinder = typeBinder,
|
|
||||||
Formatting = Formatting.Indented,
|
|
||||||
PreserveReferencesHandling = PreserveReferencesHandling.All,
|
|
||||||
MissingMemberHandling = MissingMemberHandling.Ignore,
|
|
||||||
TypeNameHandling = TypeNameHandling.All,
|
|
||||||
NullValueHandling = NullValueHandling.Include
|
|
||||||
};
|
|
||||||
return settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SaveFileAs(IProject project)
|
|
||||||
{
|
{
|
||||||
var tmpFullFileName = project.FullFileName;
|
var tmpFullFileName = project.FullFileName;
|
||||||
SaveFile(project);
|
project.FullFileName = string.Empty;
|
||||||
if (project.FullFileName == string.Empty)
|
var result = SaveFile(project);
|
||||||
|
if (result.IsValid == false)
|
||||||
{
|
{
|
||||||
project.FullFileName = tmpFullFileName;
|
project.FullFileName = tmpFullFileName;
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
42
DataAccess/Infrastructures/GetJsonDataByRootObjectLogic.cs
Normal file
42
DataAccess/Infrastructures/GetJsonDataByRootObjectLogic.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using DataAccess.DTOs;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using StructureHelperCommon.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DataAccess.Infrastructures
|
||||||
|
{
|
||||||
|
public class GetJsonDataByRootObjectLogic : IGetJsonDataByRootObjectLogic
|
||||||
|
{
|
||||||
|
private IGetJsonSettingsLogic getJsonSettingsLogic;
|
||||||
|
|
||||||
|
public GetJsonDataByRootObjectLogic(IGetJsonSettingsLogic getJsonSettingsLogic)
|
||||||
|
{
|
||||||
|
this.getJsonSettingsLogic = getJsonSettingsLogic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetJsonDataByRootObjectLogic(IShiftTraceLogger traceLogger) : this (new GetJsonSettingsLogic(traceLogger))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public IRootObjectDTO RootObject { get; set; }
|
||||||
|
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||||
|
|
||||||
|
public string GetJsonData()
|
||||||
|
{
|
||||||
|
var rootString = Serialize(RootObject);
|
||||||
|
return rootString;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string Serialize(object obj)
|
||||||
|
{
|
||||||
|
JsonSerializerSettings settings = getJsonSettingsLogic.GetSettings();
|
||||||
|
string serializedObject = JsonConvert.SerializeObject(obj, settings);
|
||||||
|
return serializedObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
51
DataAccess/Infrastructures/GetJsonSettingsLogic.cs
Normal file
51
DataAccess/Infrastructures/GetJsonSettingsLogic.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
using DataAccess.DTOs;
|
||||||
|
using DataAccess.JsonConverters;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using NLog;
|
||||||
|
using StructureHelperCommon.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DataAccess.Infrastructures
|
||||||
|
{
|
||||||
|
public class GetJsonSettingsLogic : IGetJsonSettingsLogic
|
||||||
|
{
|
||||||
|
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||||
|
|
||||||
|
public GetJsonSettingsLogic(IShiftTraceLogger? traceLogger)
|
||||||
|
{
|
||||||
|
TraceLogger = traceLogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonSerializerSettings GetSettings()
|
||||||
|
{
|
||||||
|
List<(Type type, string name)> typesNames = TypeBinderListFactory.GetTypeNameList(TypeFileVersion.version_v1);
|
||||||
|
TypeBinder typeBinder = new(typesNames);
|
||||||
|
List<JsonConverter> jsonConverters = GetConverters();
|
||||||
|
|
||||||
|
var settings = new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
Converters = jsonConverters,
|
||||||
|
SerializationBinder = typeBinder,
|
||||||
|
Formatting = Formatting.Indented,
|
||||||
|
PreserveReferencesHandling = PreserveReferencesHandling.All,
|
||||||
|
MissingMemberHandling = MissingMemberHandling.Ignore,
|
||||||
|
TypeNameHandling = TypeNameHandling.All,
|
||||||
|
NullValueHandling = NullValueHandling.Include
|
||||||
|
};
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<JsonConverter> GetConverters()
|
||||||
|
{
|
||||||
|
return new List<JsonConverter>
|
||||||
|
{
|
||||||
|
new FileVersionDTOJsonConverter(TraceLogger),
|
||||||
|
new ProjectDTOJsonConverter(TraceLogger)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
79
DataAccess/Infrastructures/GetProjectLogic.cs
Normal file
79
DataAccess/Infrastructures/GetProjectLogic.cs
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
using DataAccess.DTOs;
|
||||||
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
using StructureHelperCommon.Infrastructures.Settings;
|
||||||
|
using StructureHelperCommon.Models;
|
||||||
|
using StructureHelperCommon.Models.Calculators;
|
||||||
|
using StructureHelperCommon.Models.Projects;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DataAccess.Infrastructures
|
||||||
|
{
|
||||||
|
public class GetProjectLogic : IGetProjectLogic
|
||||||
|
{
|
||||||
|
private IGetRootObjectByJsonDataLogic getRootObjectLogic;
|
||||||
|
private RootObjectDTO? rootObject;
|
||||||
|
private ICheckEntityLogic<IRootObjectDTO> checkEntityLogic;
|
||||||
|
private OpenProjectResult result;
|
||||||
|
|
||||||
|
public GetProjectLogic(IGetRootObjectByJsonDataLogic getRootObjectLogic,
|
||||||
|
ICheckEntityLogic<IRootObjectDTO> checkEntityLogic,
|
||||||
|
IShiftTraceLogger traceLogger)
|
||||||
|
{
|
||||||
|
this.getRootObjectLogic = getRootObjectLogic;
|
||||||
|
this.checkEntityLogic = checkEntityLogic;
|
||||||
|
TraceLogger = traceLogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetProjectLogic(IShiftTraceLogger traceLogger) : this (
|
||||||
|
new GetRootObjectLogic(traceLogger),
|
||||||
|
new CheckRootObjectLogic(traceLogger),
|
||||||
|
traceLogger)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public string FileName { get; set; }
|
||||||
|
public IShiftTraceLogger TraceLogger { get; set; }
|
||||||
|
|
||||||
|
public OpenProjectResult GetProject()
|
||||||
|
{
|
||||||
|
result = new OpenProjectResult()
|
||||||
|
{
|
||||||
|
IsValid = true
|
||||||
|
};
|
||||||
|
string jsonData = File.ReadAllText(FileName);
|
||||||
|
getRootObjectLogic.JsonData = jsonData;
|
||||||
|
rootObject = getRootObjectLogic.GetRootObject();
|
||||||
|
checkEntityLogic.Entity = rootObject;
|
||||||
|
var checkResult = checkEntityLogic.Check();
|
||||||
|
if (checkResult == false)
|
||||||
|
{
|
||||||
|
TraceLogger?.AddMessage(checkEntityLogic.CheckResult, TraceLogStatuses.Error);
|
||||||
|
result.Description += checkEntityLogic.CheckResult;
|
||||||
|
result.IsValid = false;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
Project project = GetProjectByRootObject(rootObject);
|
||||||
|
project.FullFileName = FileName;
|
||||||
|
result.Project = project;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private Project GetProjectByRootObject(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}");
|
||||||
|
Dictionary<(Guid id, Type type), ISaveable> refDictinary = new Dictionary<(Guid id, Type type), ISaveable>();
|
||||||
|
IConvertStrategy<Project, ProjectDTO> convertStrategy = new ProjectFromDTOConvertStrategy(refDictinary, TraceLogger);
|
||||||
|
Project project = convertStrategy.Convert(rootObject.Project);
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
69
DataAccess/Infrastructures/GetRootObjectByProjectLogic.cs
Normal file
69
DataAccess/Infrastructures/GetRootObjectByProjectLogic.cs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
using DataAccess.DTOs;
|
||||||
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
using StructureHelperCommon.Infrastructures.Settings;
|
||||||
|
using StructureHelperCommon.Models;
|
||||||
|
using StructureHelperCommon.Models.Projects;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DataAccess.Infrastructures
|
||||||
|
{
|
||||||
|
public class GetRootObjectByProjectLogic : IGetRootObjectByProjectLogic
|
||||||
|
{
|
||||||
|
private readonly IFileVersion version = ProgramSetting.GetCurrentFileVersion();
|
||||||
|
private Dictionary<(Guid id, Type type), ISaveable> refDictinary = new Dictionary<(Guid id, Type type), ISaveable>();
|
||||||
|
|
||||||
|
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||||
|
|
||||||
|
public GetRootObjectByProjectLogic(IShiftTraceLogger? traceLogger)
|
||||||
|
{
|
||||||
|
TraceLogger = traceLogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IProject Project { get; set; }
|
||||||
|
|
||||||
|
public RootObjectDTO? GetRootObject()
|
||||||
|
{
|
||||||
|
FileVersionDTO fileVersion = GetVersionDTO();
|
||||||
|
ProjectDTO project = GetProjectDTO();
|
||||||
|
return new RootObjectDTO() { FileVersion = fileVersion, Project = project };
|
||||||
|
}
|
||||||
|
|
||||||
|
private FileVersionDTO GetVersionDTO()
|
||||||
|
{
|
||||||
|
FileVersionToDTOConvertStrategy fileVersionDTOConvertStrategy = new()
|
||||||
|
{
|
||||||
|
ReferenceDictionary = refDictinary,
|
||||||
|
TraceLogger = TraceLogger
|
||||||
|
};
|
||||||
|
DictionaryConvertStrategy<FileVersionDTO, IFileVersion> dictionaryConvertStrategy = new()
|
||||||
|
{
|
||||||
|
ConvertStrategy = fileVersionDTOConvertStrategy,
|
||||||
|
ReferenceDictionary = refDictinary,
|
||||||
|
TraceLogger = TraceLogger
|
||||||
|
};
|
||||||
|
var versionDTO = dictionaryConvertStrategy.Convert(version);
|
||||||
|
return versionDTO;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ProjectDTO GetProjectDTO()
|
||||||
|
{
|
||||||
|
ProjectToDTOConvertStrategy convertStrategy = new()
|
||||||
|
{
|
||||||
|
ReferenceDictionary = refDictinary,
|
||||||
|
TraceLogger = TraceLogger
|
||||||
|
};
|
||||||
|
DictionaryConvertStrategy<ProjectDTO, IProject> dictionaryConvertStrategy = new()
|
||||||
|
{
|
||||||
|
ConvertStrategy = convertStrategy,
|
||||||
|
ReferenceDictionary = refDictinary,
|
||||||
|
TraceLogger = TraceLogger
|
||||||
|
};
|
||||||
|
ProjectDTO projectDTO = dictionaryConvertStrategy.Convert(Project);
|
||||||
|
return projectDTO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
53
DataAccess/Infrastructures/GetRootObjectLogic.cs
Normal file
53
DataAccess/Infrastructures/GetRootObjectLogic.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using DataAccess.DTOs;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||||
|
using StructureHelperCommon.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DataAccess.Infrastructures
|
||||||
|
{
|
||||||
|
public class GetRootObjectLogic : IGetRootObjectByJsonDataLogic
|
||||||
|
{
|
||||||
|
private IGetJsonSettingsLogic jsonSettingsLogic;
|
||||||
|
|
||||||
|
public GetRootObjectLogic(
|
||||||
|
IGetJsonSettingsLogic jsonSettingsLogic,
|
||||||
|
IShiftTraceLogger traceLogger)
|
||||||
|
{
|
||||||
|
this.jsonSettingsLogic = jsonSettingsLogic;
|
||||||
|
TraceLogger = traceLogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetRootObjectLogic(IShiftTraceLogger traceLogger) : this (new GetJsonSettingsLogic(traceLogger), traceLogger)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public string JsonData { get; set; }
|
||||||
|
public IShiftTraceLogger TraceLogger { get; set; }
|
||||||
|
|
||||||
|
public RootObjectDTO? GetRootObject()
|
||||||
|
{
|
||||||
|
jsonSettingsLogic.TraceLogger = TraceLogger;
|
||||||
|
JsonSerializerSettings settings = jsonSettingsLogic.GetSettings();
|
||||||
|
TraceLogger?.AddMessage("Deserialization of data is started");
|
||||||
|
RootObjectDTO rootObject;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rootObject = JsonConvert.DeserializeObject<RootObjectDTO>(JsonData, settings);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
string errorString = "Error of deserialization of json data" + ex.Message;
|
||||||
|
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
|
||||||
|
throw new StructureHelperException(errorString);
|
||||||
|
}
|
||||||
|
TraceLogger?.AddMessage("Deserialization of data has been finished successfully");
|
||||||
|
return rootObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,5 +6,6 @@ namespace DataAccess.Infrastructures
|
|||||||
public interface IFileOpenLogic : ILogic
|
public interface IFileOpenLogic : ILogic
|
||||||
{
|
{
|
||||||
OpenProjectResult OpenFile();
|
OpenProjectResult OpenFile();
|
||||||
|
OpenProjectResult OpenFile(string fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
using StructureHelperCommon.Models.Projects;
|
using StructureHelperCommon.Models.Projects;
|
||||||
|
using StructureHelperCommon.Services.FileServices;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -10,7 +11,7 @@ namespace DataAccess.Infrastructures
|
|||||||
{
|
{
|
||||||
public interface IFileSaveLogic : ILogic
|
public interface IFileSaveLogic : ILogic
|
||||||
{
|
{
|
||||||
void SaveFile(IProject project);
|
SaveFileResult SaveFile(IProject project);
|
||||||
void SaveFileAs(IProject project);
|
SaveFileResult SaveFileAs(IProject project);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
DataAccess/Infrastructures/IGetJsonDataByRootObjectLogic.cs
Normal file
12
DataAccess/Infrastructures/IGetJsonDataByRootObjectLogic.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using DataAccess.DTOs;
|
||||||
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
|
||||||
|
namespace DataAccess.Infrastructures
|
||||||
|
{
|
||||||
|
public interface IGetJsonDataByRootObjectLogic : ILogic
|
||||||
|
{
|
||||||
|
IRootObjectDTO RootObject { get; set; }
|
||||||
|
|
||||||
|
string GetJsonData();
|
||||||
|
}
|
||||||
|
}
|
||||||
15
DataAccess/Infrastructures/IGetJsonSettingsLogic.cs
Normal file
15
DataAccess/Infrastructures/IGetJsonSettingsLogic.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DataAccess.Infrastructures
|
||||||
|
{
|
||||||
|
public interface IGetJsonSettingsLogic : ILogic
|
||||||
|
{
|
||||||
|
JsonSerializerSettings GetSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
18
DataAccess/Infrastructures/IGetProjectLogic.cs
Normal file
18
DataAccess/Infrastructures/IGetProjectLogic.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
using StructureHelperCommon.Models;
|
||||||
|
using StructureHelperCommon.Models.Projects;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DataAccess.Infrastructures
|
||||||
|
{
|
||||||
|
public interface IGetProjectLogic : ILogic
|
||||||
|
{
|
||||||
|
string FileName { get; set; }
|
||||||
|
IShiftTraceLogger TraceLogger { get; set; }
|
||||||
|
OpenProjectResult GetProject();
|
||||||
|
}
|
||||||
|
}
|
||||||
16
DataAccess/Infrastructures/IGetRootObjectByJsonDataLogic.cs
Normal file
16
DataAccess/Infrastructures/IGetRootObjectByJsonDataLogic.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using DataAccess.DTOs;
|
||||||
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
using StructureHelperCommon.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DataAccess.Infrastructures
|
||||||
|
{
|
||||||
|
public interface IGetRootObjectByJsonDataLogic : IGetRootObjectLogic
|
||||||
|
{
|
||||||
|
string JsonData { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
14
DataAccess/Infrastructures/IGetRootObjectByProjectLogic.cs
Normal file
14
DataAccess/Infrastructures/IGetRootObjectByProjectLogic.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using StructureHelperCommon.Models.Projects;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DataAccess.Infrastructures
|
||||||
|
{
|
||||||
|
public interface IGetRootObjectByProjectLogic : IGetRootObjectLogic
|
||||||
|
{
|
||||||
|
IProject Project { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
10
DataAccess/Infrastructures/IGetRootObjectLogic.cs
Normal file
10
DataAccess/Infrastructures/IGetRootObjectLogic.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using DataAccess.DTOs;
|
||||||
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
|
||||||
|
namespace DataAccess.Infrastructures
|
||||||
|
{
|
||||||
|
public interface IGetRootObjectLogic : ILogic
|
||||||
|
{
|
||||||
|
RootObjectDTO? GetRootObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,7 +12,8 @@ namespace DataAccess.Infrastructures
|
|||||||
public interface IProjectAccessLogic : ILogic
|
public interface IProjectAccessLogic : ILogic
|
||||||
{
|
{
|
||||||
OpenProjectResult OpenProject();
|
OpenProjectResult OpenProject();
|
||||||
void SaveProject(IProject project);
|
OpenProjectResult OpenProject(string fileName);
|
||||||
void SaveProjectAs(IProject project);
|
SaveFileResult SaveProject(IProject project);
|
||||||
|
SaveFileResult SaveProjectAs(IProject project);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
DataAccess/Infrastructures/ISaveProjectToFileLogic.cs
Normal file
12
DataAccess/Infrastructures/ISaveProjectToFileLogic.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
using StructureHelperCommon.Models.Projects;
|
||||||
|
|
||||||
|
namespace DataAccess.Infrastructures
|
||||||
|
{
|
||||||
|
public interface ISaveProjectToFileLogic : ILogic
|
||||||
|
{
|
||||||
|
IProject Project { get; set; }
|
||||||
|
|
||||||
|
void SaveProject();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,16 +32,24 @@ namespace DataAccess.Infrastructures
|
|||||||
return openLogic.OpenFile();
|
return openLogic.OpenFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveProject(IProject project)
|
public OpenProjectResult OpenProject(string fileName)
|
||||||
{
|
{
|
||||||
saveLogic.TraceLogger = TraceLogger;
|
openLogic.TraceLogger = TraceLogger;
|
||||||
saveLogic.SaveFile(project);
|
return openLogic.OpenFile(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveProjectAs(IProject project)
|
public SaveFileResult SaveProject(IProject project)
|
||||||
{
|
{
|
||||||
saveLogic.TraceLogger = TraceLogger;
|
saveLogic.TraceLogger = TraceLogger;
|
||||||
saveLogic.SaveFileAs(project);
|
var result = saveLogic.SaveFile(project);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SaveFileResult SaveProjectAs(IProject project)
|
||||||
|
{
|
||||||
|
saveLogic.TraceLogger = TraceLogger;
|
||||||
|
var result = saveLogic.SaveFileAs(project);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
61
DataAccess/Infrastructures/SaveProjectToFileLogic.cs
Normal file
61
DataAccess/Infrastructures/SaveProjectToFileLogic.cs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
using StructureHelperCommon.Models;
|
||||||
|
using StructureHelperCommon.Models.Projects;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DataAccess.Infrastructures
|
||||||
|
{
|
||||||
|
public class SaveProjectToFileLogic : ISaveProjectToFileLogic
|
||||||
|
{
|
||||||
|
private IGetRootObjectByProjectLogic getRootObjectLogic;
|
||||||
|
private IGetJsonDataByRootObjectLogic getJsonDataLogic;
|
||||||
|
|
||||||
|
public SaveProjectToFileLogic(
|
||||||
|
IGetRootObjectByProjectLogic getRootObjectLogic,
|
||||||
|
IGetJsonDataByRootObjectLogic getJsonDataLogic,
|
||||||
|
IShiftTraceLogger traceLogger)
|
||||||
|
{
|
||||||
|
this.getRootObjectLogic = getRootObjectLogic;
|
||||||
|
this.getJsonDataLogic = getJsonDataLogic;
|
||||||
|
TraceLogger = traceLogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SaveProjectToFileLogic(IShiftTraceLogger traceLogger) : this (
|
||||||
|
new GetRootObjectByProjectLogic(traceLogger),
|
||||||
|
new GetJsonDataByRootObjectLogic(traceLogger),
|
||||||
|
traceLogger
|
||||||
|
)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public IProject Project { get; set; }
|
||||||
|
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||||
|
|
||||||
|
public void SaveProject()
|
||||||
|
{
|
||||||
|
getRootObjectLogic.Project = Project;
|
||||||
|
var rootObject = getRootObjectLogic.GetRootObject();
|
||||||
|
getJsonDataLogic.RootObject = rootObject;
|
||||||
|
var jsonData = getJsonDataLogic.GetJsonData();
|
||||||
|
SaveStringToFile(jsonData);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveStringToFile(string jsonData)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.Delete(Project.FullFileName);
|
||||||
|
File.WriteAllText(Project.FullFileName, jsonData);
|
||||||
|
TraceLogger?.AddMessage($"File {Project.FullFileName} was saved successfully", TraceLogStatuses.Service);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,8 +6,6 @@ using System.Reflection;
|
|||||||
|
|
||||||
namespace DataAccess.JsonConverters
|
namespace DataAccess.JsonConverters
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public abstract class BaseJsonConverter<T> : JsonConverter<T>
|
public abstract class BaseJsonConverter<T> : JsonConverter<T>
|
||||||
{
|
{
|
||||||
private IWriteJsonLogic<T> writeJsonLogic;
|
private IWriteJsonLogic<T> writeJsonLogic;
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ using StructureHelper.Windows.MainWindow;
|
|||||||
using StructureHelperLogics.Services.NdmCalculations;
|
using StructureHelperLogics.Services.NdmCalculations;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace StructureHelper
|
namespace StructureHelper
|
||||||
{
|
{
|
||||||
@@ -31,9 +33,40 @@ namespace StructureHelper
|
|||||||
|
|
||||||
Container = builder.Build();
|
Container = builder.Build();
|
||||||
Scope = Container.Resolve<ILifetimeScope>();
|
Scope = Container.Resolve<ILifetimeScope>();
|
||||||
|
// Get the command-line arguments
|
||||||
|
string[] args = Environment.GetCommandLineArgs();
|
||||||
|
|
||||||
var window = Scope.Resolve<AnalysesManagerView>();
|
// Check if there is an argument provided for a file
|
||||||
window.Show();
|
if (args.Length > 1) // args[0] is the application path
|
||||||
|
{
|
||||||
|
OpenSpecifiedFile(args);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// No file specified, open normally
|
||||||
|
var window = new AnalysesManagerView();
|
||||||
|
window.Show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OpenSpecifiedFile(string[] args)
|
||||||
|
{
|
||||||
|
string filePath = args[1];
|
||||||
|
|
||||||
|
// Optional: Validate the file path
|
||||||
|
if (File.Exists(filePath))
|
||||||
|
{
|
||||||
|
// Pass the file path to your main window or handling logic
|
||||||
|
var vm = new AnalysesManagerViewModel();
|
||||||
|
vm.FileLogic.OpenNewFile(filePath);
|
||||||
|
//var window = Scope.Resolve<AnalysesManagerView>(vm);
|
||||||
|
var window = new AnalysesManagerView(vm);
|
||||||
|
window.Show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("File does not exist.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnExit(ExitEventArgs e)
|
protected override void OnExit(ExitEventArgs e)
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
BIN
StructureHelper/Infrastructure/UI/Icons/SH_лого_16.ico
Normal file
BIN
StructureHelper/Infrastructure/UI/Icons/SH_лого_16.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
BIN
StructureHelper/SH_лого_16.ico
Normal file
BIN
StructureHelper/SH_лого_16.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@@ -9,6 +9,7 @@
|
|||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
|
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
<ApplicationIcon>Infrastructure\UI\Icons\SH_лого_16.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -53,6 +54,10 @@
|
|||||||
<None Remove="Windows\MainWindow\СarbonMaterial32.png" />
|
<None Remove="Windows\MainWindow\СarbonMaterial32.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Infrastructure\UI\Icons\SH_лого_16.ico" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Autofac" Version="8.1.0" />
|
<PackageReference Include="Autofac" Version="8.1.0" />
|
||||||
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
|
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
xmlns:vm="clr-namespace:StructureHelper.Windows.ViewModels.Calculations.Calculators.GeometryCalculatorVMs"
|
xmlns:vm="clr-namespace:StructureHelper.Windows.ViewModels.Calculations.Calculators.GeometryCalculatorVMs"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DataContext="{d:DesignInstance vm:GeometryCalculatorResultViewModel}"
|
d:DataContext="{d:DesignInstance vm:GeometryCalculatorResultViewModel}"
|
||||||
Title="Geometry Properies" Height="450" Width="850" WindowStartupLocation="CenterScreen">
|
Title="Geometry Properties" Height="450" Width="850" WindowStartupLocation="CenterScreen">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition/>
|
<ColumnDefinition/>
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
<DataGridCheckBoxColumn Header="Valid" Binding="{Binding Path=IsValid}"/>
|
<DataGridCheckBoxColumn Header="Valid" Binding="{Binding Path=IsValid}"/>
|
||||||
<DataGridTextColumn Header="Name" Width="100" Binding="{Binding Name}"/>
|
<DataGridTextColumn Header="Name" Width="100" Binding="{Binding Name}"/>
|
||||||
<DataGridTextColumn Header="Short" Width="50" Binding="{Binding ShortName}"/>
|
<DataGridTextColumn Header="Short" Width="50" Binding="{Binding ShortName}"/>
|
||||||
<DataGridTextColumn Header="Unit" Width="100" Binding="{Binding MeasurementUnit}"/>
|
<DataGridTextColumn Header="Unit" Width="100" Binding="{Binding Text}"/>
|
||||||
<DataGridTextColumn Header="Value" Width="150" Binding="{Binding Value}"/>
|
<DataGridTextColumn Header="Value" Width="150" Binding="{Binding Value}"/>
|
||||||
<DataGridTextColumn Header="Description" Width="400" Binding="{Binding Description}"/>
|
<DataGridTextColumn Header="Description" Width="400" Binding="{Binding Description}"/>
|
||||||
</DataGrid.Columns>
|
</DataGrid.Columns>
|
||||||
|
|||||||
@@ -101,6 +101,10 @@ namespace StructureHelper.Windows.MainWindow
|
|||||||
SelectedAnalysis.Analysis.Name = name;
|
SelectedAnalysis.Analysis.Name = name;
|
||||||
SelectedAnalysis.Analysis.Tags = tags;
|
SelectedAnalysis.Analysis.Tags = tags;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ProgramSetting.SetCurrentProjectToNotActual();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void DeleteAnalysis()
|
private void DeleteAnalysis()
|
||||||
@@ -111,6 +115,7 @@ namespace StructureHelper.Windows.MainWindow
|
|||||||
if (dialogResult == DialogResult.Yes)
|
if (dialogResult == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
ProgramSetting.CurrentProject.VisualAnalyses.Remove(SelectedAnalysis);
|
ProgramSetting.CurrentProject.VisualAnalyses.Remove(SelectedAnalysis);
|
||||||
|
ProgramSetting.SetCurrentProjectToNotActual();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,6 +124,7 @@ namespace StructureHelper.Windows.MainWindow
|
|||||||
if (SelectedAnalysis is null) { return; }
|
if (SelectedAnalysis is null) { return; }
|
||||||
SelectedAnalysis.ActionToRun = ActionToRun;
|
SelectedAnalysis.ActionToRun = ActionToRun;
|
||||||
SelectedAnalysis?.Run();
|
SelectedAnalysis?.Run();
|
||||||
|
ProgramSetting.SetCurrentProjectToNotActual();
|
||||||
}
|
}
|
||||||
private void AddCrossSectionNdmAnalysis()
|
private void AddCrossSectionNdmAnalysis()
|
||||||
{
|
{
|
||||||
@@ -127,7 +133,7 @@ namespace StructureHelper.Windows.MainWindow
|
|||||||
analysis.Tags = "#New group";
|
analysis.Tags = "#New group";
|
||||||
var visualAnalysis = new VisualAnalysis(analysis);
|
var visualAnalysis = new VisualAnalysis(analysis);
|
||||||
ProgramSetting.CurrentProject.VisualAnalyses.Add(visualAnalysis);
|
ProgramSetting.CurrentProject.VisualAnalyses.Add(visualAnalysis);
|
||||||
//ProgramSetting.SetCurrentProjectToNotActual();
|
ProgramSetting.SetCurrentProjectToNotActual();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ActionToRun()
|
private void ActionToRun()
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using StructureHelperCommon.Infrastructures.Settings;
|
|||||||
using StructureHelperCommon.Models;
|
using StructureHelperCommon.Models;
|
||||||
using StructureHelperCommon.Models.Analyses;
|
using StructureHelperCommon.Models.Analyses;
|
||||||
using StructureHelperCommon.Models.Projects;
|
using StructureHelperCommon.Models.Projects;
|
||||||
|
using StructureHelperCommon.Services.FileServices;
|
||||||
using StructureHelperLogics.Models.CrossSections;
|
using StructureHelperLogics.Models.CrossSections;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -63,20 +64,26 @@ namespace StructureHelper.Windows.MainWindow
|
|||||||
ProgramSetting.Projects.Add(newProject);
|
ProgramSetting.Projects.Add(newProject);
|
||||||
return newProject;
|
return newProject;
|
||||||
}
|
}
|
||||||
private void SaveAsFile()
|
private SaveFileResult SaveAsFile()
|
||||||
{
|
{
|
||||||
var project = ProgramSetting.CurrentProject;
|
var project = ProgramSetting.CurrentProject;
|
||||||
traceLogger = new ShiftTraceLogger();
|
traceLogger = new ShiftTraceLogger();
|
||||||
projectAccessLogic.TraceLogger = traceLogger;
|
projectAccessLogic.TraceLogger = traceLogger;
|
||||||
projectAccessLogic.SaveProjectAs(project);
|
var result = projectAccessLogic.SaveProjectAs(project);
|
||||||
ShowEntries();
|
ShowEntries();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
private void ExitProgram()
|
public bool ExitProgram()
|
||||||
{
|
{
|
||||||
foreach (var project in ProgramSetting.Projects)
|
var collection = ProgramSetting.Projects.ToList();
|
||||||
|
foreach (var project in collection)
|
||||||
{
|
{
|
||||||
CloseFile(project);
|
if (CloseFile(project) == false)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
public bool CloseFile()
|
public bool CloseFile()
|
||||||
{
|
{
|
||||||
@@ -95,10 +102,20 @@ namespace StructureHelper.Windows.MainWindow
|
|||||||
ProgramSetting.Projects.Remove(project);
|
ProgramSetting.Projects.Remove(project);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
var dialogResult = MessageBox.Show($"Save file?", $"File {project.FullFileName} is not saved", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
|
DialogResult dialogResult = GetDialog(project);
|
||||||
if (dialogResult == DialogResult.Yes)
|
if (dialogResult == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
SaveFile(project);
|
var result = SaveFile(project);
|
||||||
|
if (result.IsValid = false)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (dialogResult == DialogResult.No)
|
||||||
|
{
|
||||||
|
project.IsActual = true;
|
||||||
|
ProgramSetting.Projects.Remove(project);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else if (dialogResult == DialogResult.Cancel)
|
else if (dialogResult == DialogResult.Cancel)
|
||||||
{
|
{
|
||||||
@@ -108,17 +125,24 @@ namespace StructureHelper.Windows.MainWindow
|
|||||||
CloseFile(project);
|
CloseFile(project);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static DialogResult GetDialog(IProject project)
|
||||||
|
{
|
||||||
|
return MessageBox.Show($"File {project.FullFileName} has unsaved changes", $"StructureHelper: Save file?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
|
||||||
|
}
|
||||||
|
|
||||||
private void SaveFile()
|
private void SaveFile()
|
||||||
{
|
{
|
||||||
var project = ProgramSetting.CurrentProject;
|
var project = ProgramSetting.CurrentProject;
|
||||||
SaveFile(project);
|
SaveFile(project);
|
||||||
}
|
}
|
||||||
private void SaveFile(IProject project)
|
private SaveFileResult SaveFile(IProject project)
|
||||||
{
|
{
|
||||||
traceLogger = new ShiftTraceLogger();
|
traceLogger = new ShiftTraceLogger();
|
||||||
projectAccessLogic.TraceLogger = traceLogger;
|
projectAccessLogic.TraceLogger = traceLogger;
|
||||||
projectAccessLogic.SaveProject(project);
|
var result = projectAccessLogic.SaveProject(project);
|
||||||
ShowEntries();
|
ShowEntries();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
private void OpenFile()
|
private void OpenFile()
|
||||||
{
|
{
|
||||||
@@ -128,29 +152,47 @@ namespace StructureHelper.Windows.MainWindow
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
OpenNewFile(currentProject);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OpenNewFile(IProject currentProject)
|
||||||
|
{
|
||||||
traceLogger = new ShiftTraceLogger();
|
traceLogger = new ShiftTraceLogger();
|
||||||
projectAccessLogic.TraceLogger = traceLogger;
|
projectAccessLogic.TraceLogger = traceLogger;
|
||||||
try
|
var result = projectAccessLogic.OpenProject();
|
||||||
|
if (result.IsValid == true)
|
||||||
{
|
{
|
||||||
var result = projectAccessLogic.OpenProject();
|
result.Project.IsActual = true;
|
||||||
if (result.IsValid == true)
|
ProgramSetting.Projects.Clear();
|
||||||
{
|
ProgramSetting.Projects.Add(result.Project);
|
||||||
result.Project.IsActual = true;
|
|
||||||
ProgramSetting.Projects.Clear();
|
|
||||||
ProgramSetting.Projects.Add(result.Project);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ProgramSetting.Projects.Add(currentProject);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
else
|
||||||
{
|
{
|
||||||
traceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
|
ProgramSetting.Projects.Add(currentProject);
|
||||||
}
|
}
|
||||||
ShowEntries();
|
ShowEntries();
|
||||||
ParentVM.AnalysesLogic.Refresh();
|
ParentVM.AnalysesLogic.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OpenNewFile(string fileName)
|
||||||
|
{
|
||||||
|
traceLogger = new ShiftTraceLogger();
|
||||||
|
projectAccessLogic.TraceLogger = traceLogger;
|
||||||
|
var result = projectAccessLogic.OpenProject(fileName);
|
||||||
|
if (result.IsValid == true)
|
||||||
|
{
|
||||||
|
result.Project.IsActual = true;
|
||||||
|
ProgramSetting.Projects.Clear();
|
||||||
|
ProgramSetting.Projects.Add(result.Project);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ProgramSetting.Projects.Add(new Project());
|
||||||
|
}
|
||||||
|
ShowEntries();
|
||||||
|
ParentVM.AnalysesLogic.Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
private void ShowEntries()
|
private void ShowEntries()
|
||||||
{
|
{
|
||||||
var filteredEntries = traceLogger.TraceLoggerEntries.Where(x => x.Priority < 300);
|
var filteredEntries = traceLogger.TraceLoggerEntries.Where(x => x.Priority < 300);
|
||||||
|
|||||||
@@ -40,7 +40,26 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</ToolBar>
|
</ToolBar>
|
||||||
<ToolBar ToolTip="Cross-sections">
|
<ToolBar ToolTip="Cross-sections">
|
||||||
<Button Style="{DynamicResource ToolButton}" Command="{Binding AnalysesLogic.AddAnalysisCommand}" ToolTip="NDM Analysis">
|
<Button Style="{DynamicResource ToolButton}" Command="{Binding AnalysesLogic.AddAnalysisCommand}">
|
||||||
|
<Button.ToolTip>
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="30"/>
|
||||||
|
<RowDefinition Height="60"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<TextBlock Text="NDM Cross-Section Analysis" FontWeight="Bold" Background="LightGray"/>
|
||||||
|
<Grid Grid.Row="1">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="60"/>
|
||||||
|
<ColumnDefinition Width="150"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Viewbox Stretch="Fill">
|
||||||
|
<ContentControl ContentTemplate="{DynamicResource NdmCrossSection}"/>
|
||||||
|
</Viewbox>
|
||||||
|
<TextBlock Grid.Column="1" TextWrapping="Wrap" Text="Extended analysis of cross-section of bar elements for strength, strain and cracks" FontStyle="Italic"/>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</Button.ToolTip>
|
||||||
<Viewbox>
|
<Viewbox>
|
||||||
<ContentControl ContentTemplate="{DynamicResource NdmCrossSection}"/>
|
<ContentControl ContentTemplate="{DynamicResource NdmCrossSection}"/>
|
||||||
</Viewbox>
|
</Viewbox>
|
||||||
|
|||||||
@@ -21,17 +21,22 @@ namespace StructureHelper.Windows.MainWindow
|
|||||||
public partial class AnalysesManagerView : Window
|
public partial class AnalysesManagerView : Window
|
||||||
{
|
{
|
||||||
private AnalysesManagerViewModel viewModel;
|
private AnalysesManagerViewModel viewModel;
|
||||||
public AnalysesManagerView()
|
|
||||||
|
public AnalysesManagerView(AnalysesManagerViewModel viewModel)
|
||||||
{
|
{
|
||||||
this.viewModel = new();
|
this.viewModel = viewModel;
|
||||||
this.DataContext = viewModel;
|
this.DataContext = viewModel;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.Closing += AnalysesManagerView_Closing;
|
this.Closing += AnalysesManagerView_Closing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AnalysesManagerView() : this (new AnalysesManagerViewModel())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
private void AnalysesManagerView_Closing(object? sender, CancelEventArgs e)
|
private void AnalysesManagerView_Closing(object? sender, CancelEventArgs e)
|
||||||
{
|
{
|
||||||
if (viewModel.FileLogic.CloseFile() == true)
|
if (viewModel.FileLogic.ExitProgram() == false)
|
||||||
{
|
{
|
||||||
e.Cancel = true;
|
e.Cancel = true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
xmlns:local="clr-namespace:StructureHelper.Windows.MainWindow"
|
xmlns:local="clr-namespace:StructureHelper.Windows.MainWindow"
|
||||||
d:DataContext="{d:DesignInstance local:AxisCanvasVM}"
|
d:DataContext="{d:DesignInstance local:AxisCanvasVM}"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="Grid properies" Height="200" Width="300" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
|
Title="Grid properties" Height="200" Width="300" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="*"/>
|
<RowDefinition Height="*"/>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<Window x:Class="StructureHelper.Windows.PrimitiveProperiesWindow.PrimitivePropertiesView"
|
<Window x:Class="StructureHelper.Windows.PrimitivePropertiesWindow.PrimitivePropertiesView"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:StructureHelper.Windows.PrimitiveProperiesWindow"
|
xmlns:local="clr-namespace:StructureHelper.Windows.PrimitivePropertiesWindow"
|
||||||
xmlns:vm="clr-namespace:StructureHelper.Windows.ViewModels.PrimitiveProperties"
|
xmlns:vm="clr-namespace:StructureHelper.Windows.ViewModels.PrimitiveProperties"
|
||||||
d:DataContext="{d:DesignInstance vm:PrimitivePropertiesViewModel}"
|
d:DataContext="{d:DesignInstance vm:PrimitivePropertiesViewModel}"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using System.Windows.Data;
|
|||||||
using PointViewPrimitive = StructureHelper.Infrastructure.UI.DataContexts.PointViewPrimitive;
|
using PointViewPrimitive = StructureHelper.Infrastructure.UI.DataContexts.PointViewPrimitive;
|
||||||
using RectangleViewPrimitive = StructureHelper.Infrastructure.UI.DataContexts.RectangleViewPrimitive;
|
using RectangleViewPrimitive = StructureHelper.Infrastructure.UI.DataContexts.RectangleViewPrimitive;
|
||||||
|
|
||||||
namespace StructureHelper.Windows.PrimitiveProperiesWindow
|
namespace StructureHelper.Windows.PrimitivePropertiesWindow
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Логика взаимодействия для PrimitiveProperties.xaml
|
/// Логика взаимодействия для PrimitiveProperties.xaml
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
|
||||||
namespace StructureHelper.Windows.ViewModels.Calculations.CalculationProperies
|
namespace StructureHelper.Windows.ViewModels.Calculations.CalculationProperties
|
||||||
{
|
{
|
||||||
public class CalculationPropertyViewModel : ViewModelBase, IDataErrorInfo
|
public class CalculationPropertyViewModel : ViewModelBase, IDataErrorInfo
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using StructureHelper.Infrastructure;
|
using StructureHelper.Infrastructure;
|
||||||
using StructureHelper.Infrastructure.Enums;
|
using StructureHelper.Infrastructure.Enums;
|
||||||
using StructureHelper.Infrastructure.UI.DataContexts;
|
using StructureHelper.Infrastructure.UI.DataContexts;
|
||||||
using StructureHelper.Windows.PrimitiveProperiesWindow;
|
using StructureHelper.Windows.PrimitivePropertiesWindow;
|
||||||
using StructureHelper.Windows.Services;
|
using StructureHelper.Windows.Services;
|
||||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||||
using StructureHelperCommon.Models.Calculators;
|
using StructureHelperCommon.Models.Calculators;
|
||||||
|
|||||||
@@ -15,12 +15,11 @@ namespace StructureHelperCommon.Infrastructures.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">Type of target object</typeparam>
|
/// <typeparam name="T">Type of target object</typeparam>
|
||||||
/// <typeparam name="V">Type of source object</typeparam>
|
/// <typeparam name="V">Type of source object</typeparam>
|
||||||
public class DictionaryConvertStrategy<T, V> : IConvertStrategy<T, V>
|
public class DictionaryConvertStrategy<T, V> : IDictionaryConvertStrategy<T, V> where T : ISaveable
|
||||||
where T : ISaveable
|
|
||||||
where V : ISaveable
|
where V : ISaveable
|
||||||
{
|
{
|
||||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||||
public IConvertStrategy<T,V> ConvertStrategy { get; set; }
|
public IConvertStrategy<T, V> ConvertStrategy { get; set; }
|
||||||
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
|
||||||
|
|
||||||
public DictionaryConvertStrategy(IBaseConvertStrategy baseConvertStrategy, IConvertStrategy<T, V> convertStrategy)
|
public DictionaryConvertStrategy(IBaseConvertStrategy baseConvertStrategy, IConvertStrategy<T, V> convertStrategy)
|
||||||
@@ -31,7 +30,16 @@ namespace StructureHelperCommon.Infrastructures.Interfaces
|
|||||||
}
|
}
|
||||||
public DictionaryConvertStrategy()
|
public DictionaryConvertStrategy()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public DictionaryConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary,
|
||||||
|
IConvertStrategy<T, V> convertStrategy,
|
||||||
|
IShiftTraceLogger traceLogger)
|
||||||
|
{
|
||||||
|
ReferenceDictionary = referenceDictionary;
|
||||||
|
ConvertStrategy = convertStrategy;
|
||||||
|
TraceLogger = traceLogger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Convert(V source)
|
public T Convert(V source)
|
||||||
@@ -56,7 +64,7 @@ namespace StructureHelperCommon.Infrastructures.Interfaces
|
|||||||
}
|
}
|
||||||
private void CheckInputData()
|
private void CheckInputData()
|
||||||
{
|
{
|
||||||
if(ReferenceDictionary is null)
|
if (ReferenceDictionary is null)
|
||||||
{
|
{
|
||||||
string errorString = ErrorStrings.ParameterIsNull + ": Reference Dictionary";
|
string errorString = ErrorStrings.ParameterIsNull + ": Reference Dictionary";
|
||||||
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
|
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using StructureHelperCommon.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace StructureHelperCommon.Infrastructures.Interfaces
|
||||||
|
{
|
||||||
|
public interface IDictionaryConvertStrategy<T, V> : IConvertStrategy<T, V>
|
||||||
|
where T : ISaveable
|
||||||
|
where V : ISaveable
|
||||||
|
{
|
||||||
|
IConvertStrategy<T, V> ConvertStrategy { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ namespace StructureHelperCommon.Models.Loggers
|
|||||||
public static string DimensionLess => "(dimensionless)";
|
public static string DimensionLess => "(dimensionless)";
|
||||||
public static string MethodBasedOn => "Method of calculation based on ";
|
public static string MethodBasedOn => "Method of calculation based on ";
|
||||||
public static string CalculationError => "Some errors happened during calculations: ";
|
public static string CalculationError => "Some errors happened during calculations: ";
|
||||||
public static string CalculationHasDone => "Calculation has done succesfully";
|
public static string CalculationHasDone => "Calculation has done successfully";
|
||||||
public static string Summary => "Summary";
|
public static string Summary => "Summary";
|
||||||
public static string Maximum => "Maximum";
|
public static string Maximum => "Maximum";
|
||||||
public static string Minimum => "Minimum";
|
public static string Minimum => "Minimum";
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
string message = string.Intern("Result of second order was obtained succesfully, new force combination was obtained");
|
string message = string.Intern("Result of second order was obtained successfully, new force combination was obtained");
|
||||||
TraceLogger?.AddMessage(message);
|
TraceLogger?.AddMessage(message);
|
||||||
tupleResult = GetForceResult(limitState, calcTerm, ndms, newTuple);
|
tupleResult = GetForceResult(limitState, calcTerm, ndms, newTuple);
|
||||||
return tupleResult;
|
return tupleResult;
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
|||||||
TraceLogger = TraceLogger
|
TraceLogger = TraceLogger
|
||||||
};
|
};
|
||||||
var ndms = triangulateLogic.GetNdms();
|
var ndms = triangulateLogic.GetNdms();
|
||||||
TraceLogger?.AddMessage($"Number of elementary parts N={ndms.Count()} were obtainded succesfully");
|
TraceLogger?.AddMessage($"Number of elementary parts N={ndms.Count()} were obtainded successfully");
|
||||||
TraceLogger?.AddMessage($"Summary area of elementary parts Asum={ndms.Sum(x=>x.Area * x.StressScale)}", TraceLogStatuses.Debug);
|
TraceLogger?.AddMessage($"Summary area of elementary parts Asum={ndms.Sum(x=>x.Area * x.StressScale)}", TraceLogStatuses.Debug);
|
||||||
foreach (var predicateEntry in InputData.PredicateEntries)
|
foreach (var predicateEntry in InputData.PredicateEntries)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces.Logics
|
|||||||
{
|
{
|
||||||
TraceLogger?.AddMessage($"Calculator type: {GetType()}", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage($"Calculator type: {GetType()}", TraceLogStatuses.Service);
|
||||||
TraceLogger?.AddMessage($"Logic of analisys based on calculating sum of secant stifness of elementary parts EA,i = A,i * Esec,i");
|
TraceLogger?.AddMessage($"Logic of analisys based on calculating sum of secant stifness of elementary parts EA,i = A,i * Esec,i");
|
||||||
TraceLogger?.AddMessage($"Calculating geometry properies for strains");
|
TraceLogger?.AddMessage($"Calculating geometry properties for strains");
|
||||||
TraceLogger?.AddEntry(new TraceTablesFactory().GetByForceTuple(StrainTuple));
|
TraceLogger?.AddEntry(new TraceTablesFactory().GetByForceTuple(StrainTuple));
|
||||||
var loaderStainMatrix = TupleConverter.ConvertToLoaderStrainMatrix(StrainTuple);
|
var loaderStainMatrix = TupleConverter.ConvertToLoaderStrainMatrix(StrainTuple);
|
||||||
var (MxFactor, MyFactor, NzFactor) = GeometryOperations.GetSofteningsFactors(NdmCollection, loaderStainMatrix);
|
var (MxFactor, MyFactor, NzFactor) = GeometryOperations.GetSofteningsFactors(NdmCollection, loaderStainMatrix);
|
||||||
|
|||||||
@@ -74,9 +74,9 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
|||||||
CrackWidthRebarTupleResult longRebarResult = ProcessLongTermCalculations();
|
CrackWidthRebarTupleResult longRebarResult = ProcessLongTermCalculations();
|
||||||
CrackWidthRebarTupleResult shortRebarResult = ProcessShortTermCalculations();
|
CrackWidthRebarTupleResult shortRebarResult = ProcessShortTermCalculations();
|
||||||
result.LongTermResult = longRebarResult;
|
result.LongTermResult = longRebarResult;
|
||||||
TraceLogger?.AddMessage("Long term result has been obtained succesfully", TraceLogStatuses.Debug);
|
TraceLogger?.AddMessage("Long term result has been obtained successfully", TraceLogStatuses.Debug);
|
||||||
result.ShortTermResult = shortRebarResult;
|
result.ShortTermResult = shortRebarResult;
|
||||||
TraceLogger?.AddMessage("Short term result has been obtained succesfully", TraceLogStatuses.Debug);
|
TraceLogger?.AddMessage("Short term result has been obtained successfully", TraceLogStatuses.Debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CrackWidthRebarTupleResult ProcessShortTermCalculations()
|
private CrackWidthRebarTupleResult ProcessShortTermCalculations()
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
|||||||
throw new StructureHelperException(errorString);
|
throw new StructureHelperException(errorString);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
TraceLogger?.AddMessage($"Checking parameters has done succefully", TraceLogStatuses.Service);
|
TraceLogger?.AddMessage($"Checking parameters has done successfully", TraceLogStatuses.Service);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ namespace StructureHelperLogics.Services.NdmPrimitives
|
|||||||
|
|
||||||
static string firstAxisName => ProgramSetting.GeometryNames.FstAxisName;
|
static string firstAxisName => ProgramSetting.GeometryNames.FstAxisName;
|
||||||
static string secondAxisName => ProgramSetting.GeometryNames.SndAxisName;
|
static string secondAxisName => ProgramSetting.GeometryNames.SndAxisName;
|
||||||
|
static string thirdAxisName => ProgramSetting.GeometryNames.TrdAxisName;
|
||||||
static IEnumerable<IUnit> units = UnitsFactory.GetUnitCollection();
|
static IEnumerable<IUnit> units = UnitsFactory.GetUnitCollection();
|
||||||
private IEnumerable<INdm> ndms;
|
private IEnumerable<INdm> ndms;
|
||||||
private IStrainMatrix strainMatrix;
|
private IStrainMatrix strainMatrix;
|
||||||
@@ -38,6 +39,7 @@ namespace StructureHelperLogics.Services.NdmPrimitives
|
|||||||
parameters.AddRange(GetMomentOfInertia(prefixActual, ndms, strainMatrix));
|
parameters.AddRange(GetMomentOfInertia(prefixActual, ndms, strainMatrix));
|
||||||
parameters.AddRange(GetAreaRatio(ndms, strainMatrix));
|
parameters.AddRange(GetAreaRatio(ndms, strainMatrix));
|
||||||
parameters.AddRange(GetMomentOfInertiaRatio(ndms, strainMatrix));
|
parameters.AddRange(GetMomentOfInertiaRatio(ndms, strainMatrix));
|
||||||
|
parameters.AddRange(GetSummaryForces(ndms, strainMatrix));
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
private IEnumerable<IValueParameter<string>> GetSimpleArea(IEnumerable<INdm> ndms)
|
private IEnumerable<IValueParameter<string>> GetSimpleArea(IEnumerable<INdm> ndms)
|
||||||
@@ -257,5 +259,61 @@ namespace StructureHelperLogics.Services.NdmPrimitives
|
|||||||
parameters.Add(secondParameter);
|
parameters.Add(secondParameter);
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<IValueParameter<string>> GetSummaryForces(IEnumerable<INdm> locNdms, IStrainMatrix? locStrainMatrix)
|
||||||
|
{
|
||||||
|
var parameters = new List<IValueParameter<string>>();
|
||||||
|
var unitType = UnitTypes.Force;
|
||||||
|
var unit = unitLogic.GetUnit(unitType, "kN");
|
||||||
|
var unitName = unit.Name;
|
||||||
|
var unitMultiPlayer = unit.Multiplyer;
|
||||||
|
var forceSum = new ValueParameter<string>()
|
||||||
|
{
|
||||||
|
IsValid = true,
|
||||||
|
Name = $"Summary force",
|
||||||
|
ShortName = $"N{thirdAxisName.ToLower()},sum",
|
||||||
|
Text = unitName,
|
||||||
|
Description = $"Summary longitudinal force along {thirdAxisName.ToUpper()}-axis"
|
||||||
|
};
|
||||||
|
FillForceParameters(locNdms, locStrainMatrix, unitMultiPlayer, PosNegFlag.Both, forceSum);
|
||||||
|
var forcePositive = new ValueParameter<string>()
|
||||||
|
{
|
||||||
|
IsValid = true,
|
||||||
|
Name = $"Positive force",
|
||||||
|
ShortName = $"N{thirdAxisName.ToLower()},pos",
|
||||||
|
Text = unitName,
|
||||||
|
Description = $"Summary of positive longitudinal force along {thirdAxisName.ToUpper()}-axis"
|
||||||
|
};
|
||||||
|
FillForceParameters(locNdms, locStrainMatrix, unitMultiPlayer, PosNegFlag.Positive, forcePositive);
|
||||||
|
var forceNegative = new ValueParameter<string>()
|
||||||
|
{
|
||||||
|
IsValid = true,
|
||||||
|
Name = $"Negative force",
|
||||||
|
ShortName = $"N{thirdAxisName.ToLower()},neg",
|
||||||
|
Text = unitName,
|
||||||
|
Description = $"Summary of negative longitudinal force along {thirdAxisName.ToUpper()}-axis"
|
||||||
|
};
|
||||||
|
FillForceParameters(locNdms, locStrainMatrix, unitMultiPlayer, PosNegFlag.Negative, forceNegative);
|
||||||
|
|
||||||
|
parameters.Add(forceSum);
|
||||||
|
parameters.Add(forcePositive);
|
||||||
|
parameters.Add(forceNegative);
|
||||||
|
return parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void FillForceParameters(IEnumerable<INdm> locNdms, IStrainMatrix? locStrainMatrix, double unitMultiPlayer, PosNegFlag posNegFlag, ValueParameter<string> forceSum)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sumForceNz = GeometryOperations.GetSummaryForce(locNdms, locStrainMatrix, posNegFlag);
|
||||||
|
forceSum.Value = (sumForceNz * unitMultiPlayer).ToString();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
forceSum.IsValid = false;
|
||||||
|
forceSum.Value = (double.NaN).ToString();
|
||||||
|
forceSum.Description += $": {ex}";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\DataAccess\DataAccess.csproj" />
|
||||||
<ProjectReference Include="..\FieldVisualizer\FieldVisualizer.csproj" />
|
<ProjectReference Include="..\FieldVisualizer\FieldVisualizer.csproj" />
|
||||||
<ProjectReference Include="..\StructureHelperCommon\StructureHelperCommon.csproj" />
|
<ProjectReference Include="..\StructureHelperCommon\StructureHelperCommon.csproj" />
|
||||||
<ProjectReference Include="..\StructureHelperLogics\StructureHelperLogics.csproj" />
|
<ProjectReference Include="..\StructureHelperLogics\StructureHelperLogics.csproj" />
|
||||||
|
|||||||
@@ -0,0 +1,119 @@
|
|||||||
|
using DataAccess.DTOs;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
using StructureHelperCommon.Models;
|
||||||
|
using StructureHelperCommon.Models.Analyses;
|
||||||
|
using StructureHelperCommon.Models.Projects;
|
||||||
|
|
||||||
|
namespace StructureHelperTests.UnitTests.ConvertStrategiesTest
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
public class ProjectFromDTOConvertStrategyTests
|
||||||
|
{
|
||||||
|
private Mock<IUpdateStrategy<IProject>> _mockUpdateStrategy;
|
||||||
|
private Mock<IDictionaryConvertStrategy<IVisualAnalysis, IVisualAnalysis>> _mockConvertLogic;
|
||||||
|
private Mock<IShiftTraceLogger> _mockTraceLogger;
|
||||||
|
private Dictionary<(Guid id, Type type), ISaveable> _referenceDictionary;
|
||||||
|
private ProjectFromDTOConvertStrategy _convertStrategy;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp()
|
||||||
|
{
|
||||||
|
_mockUpdateStrategy = new Mock<IUpdateStrategy<IProject>>();
|
||||||
|
_mockConvertLogic = new Mock<IDictionaryConvertStrategy<IVisualAnalysis, IVisualAnalysis>>();
|
||||||
|
_mockTraceLogger = new Mock<IShiftTraceLogger>();
|
||||||
|
_referenceDictionary = new Dictionary<(Guid, Type), ISaveable>();
|
||||||
|
|
||||||
|
_convertStrategy = new ProjectFromDTOConvertStrategy(
|
||||||
|
_mockUpdateStrategy.Object,
|
||||||
|
_mockConvertLogic.Object,
|
||||||
|
_referenceDictionary,
|
||||||
|
_mockTraceLogger.Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetNewItem_ShouldLogStartAndEndMessages()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projectDto = new ProjectDTO
|
||||||
|
{
|
||||||
|
VisualAnalyses = new List<IVisualAnalysis> { new Mock<IVisualAnalysis>().Object }
|
||||||
|
};
|
||||||
|
|
||||||
|
_mockConvertLogic
|
||||||
|
.Setup(s => s.Convert(It.IsAny<IVisualAnalysis>()))
|
||||||
|
.Returns(new Mock<IVisualAnalysis>().Object);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = _convertStrategy.GetNewItem(projectDto);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
_mockTraceLogger.Verify(logger => logger.AddMessage("Converting of project is started"), Times.Once);
|
||||||
|
_mockTraceLogger.Verify(logger => logger.AddMessage("Converting of project has been finished successfully"), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetNewItem_ShouldLogWarningIfNoAnalyses()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projectDto = new ProjectDTO
|
||||||
|
{
|
||||||
|
VisualAnalyses = Enumerable.Empty<IVisualAnalysis>().ToList()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = _convertStrategy.GetNewItem(projectDto);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
_mockTraceLogger.Verify(logger => logger.AddMessage("Project does not have any analyses, it is possible to work with project", TraceLogStatuses.Warning), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetAnalyses_ShouldConvertEachVisualAnalysisAndLogCount()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projectDto = new ProjectDTO
|
||||||
|
{
|
||||||
|
VisualAnalyses = new List<IVisualAnalysis> { new Mock<IVisualAnalysis>().Object, new Mock<IVisualAnalysis>().Object }
|
||||||
|
};
|
||||||
|
var newItem = new Project();
|
||||||
|
|
||||||
|
_mockConvertLogic
|
||||||
|
.Setup(s => s.Convert(It.IsAny<IVisualAnalysis>()))
|
||||||
|
.Returns(new Mock<IVisualAnalysis>().Object);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var analyses = _convertStrategy.GetAnalyses(projectDto, newItem);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.AreEqual(projectDto.VisualAnalyses.Count, analyses.Count);
|
||||||
|
_mockConvertLogic.Verify(s => s.Convert(It.IsAny<IVisualAnalysis>()), Times.Exactly(projectDto.VisualAnalyses.Count));
|
||||||
|
_mockTraceLogger.Verify(logger => logger.AddMessage($"Source project has {projectDto.VisualAnalyses.Count} analyses"), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetAnalyses_ShouldLogConvertedAnalysisCount()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projectDto = new ProjectDTO
|
||||||
|
{
|
||||||
|
VisualAnalyses = new List<IVisualAnalysis> { new Mock<IVisualAnalysis>().Object }
|
||||||
|
};
|
||||||
|
var newItem = new Project();
|
||||||
|
|
||||||
|
_mockConvertLogic
|
||||||
|
.Setup(s => s.Convert(It.IsAny<IVisualAnalysis>()))
|
||||||
|
.Returns(new Mock<IVisualAnalysis>().Object);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = _convertStrategy.GetNewItem(projectDto);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
_mockTraceLogger.Verify(logger => logger.AddMessage("Totaly 1 were(was) obtained"), Times.Once);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user