diff --git a/DataAccess/DTOs/Converters/AnalysisFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/AnalysisFromDTOConvertStrategy.cs index 4f9e6ca..1a0a8ba 100644 --- a/DataAccess/DTOs/Converters/AnalysisFromDTOConvertStrategy.cs +++ b/DataAccess/DTOs/Converters/AnalysisFromDTOConvertStrategy.cs @@ -16,17 +16,32 @@ namespace DataAccess.DTOs.Converters { public class AnalysisFromDTOConvertStrategy : IConvertStrategy { - private const string Message = "Analysis type is"; - private IConvertStrategy convertCrossSectionNdmAnalysisStrategy = new CrossSectionNdmAnalysisFromDTOConvertStrategy(); + private const string AnalysisIs = "Analysis type is"; + + private IConvertStrategy convertCrossSectionNdmAnalysisStrategy; + private IConvertStrategy versionProcessorConvertStrategy; + + public AnalysisFromDTOConvertStrategy(IConvertStrategy convertCrossSectionNdmAnalysisStrategy, + IConvertStrategy versionProcessorConvertStrategy) + { + this.convertCrossSectionNdmAnalysisStrategy = convertCrossSectionNdmAnalysisStrategy; + this.versionProcessorConvertStrategy = versionProcessorConvertStrategy; + } + + public AnalysisFromDTOConvertStrategy() : this (new CrossSectionNdmAnalysisFromDTOConvertStrategy(), + new VersionProcessorFromDTOConvertStrategy()) + { + + } public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } public IShiftTraceLogger TraceLogger { get; set; } public IAnalysis Convert(IAnalysis source) { - Check(); try { + Check(); IAnalysis analysis = GetAnalysis(source); return analysis; } @@ -41,10 +56,10 @@ namespace DataAccess.DTOs.Converters private IAnalysis GetAnalysis(IAnalysis source) { - IAnalysis analysis; + IAnalysis newItem; if (source is ICrossSectionNdmAnalysis crossSectionNdmAnalysis) { - analysis = GetCrossSectionNdmAnalysis(crossSectionNdmAnalysis); + newItem = GetCrossSectionNdmAnalysis(crossSectionNdmAnalysis); } else { @@ -52,21 +67,29 @@ namespace DataAccess.DTOs.Converters TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error); throw new StructureHelperException(errorString); } - foreach (var item in source.VersionProcessor.Versions) - { - //to do - } + newItem.VersionProcessor = GetVersionProcessor(source.VersionProcessor); + return newItem; + } - return analysis; + private IVersionProcessor GetVersionProcessor(IVersionProcessor source) + { + TraceLogger?.AddMessage("Version processor converting is started", TraceLogStatuses.Service); + versionProcessorConvertStrategy.ReferenceDictionary = ReferenceDictionary; + versionProcessorConvertStrategy.TraceLogger = TraceLogger; + IVersionProcessor versionProcessor = versionProcessorConvertStrategy.Convert(source); + TraceLogger?.AddMessage("Version processor converting has been finished succesfully", TraceLogStatuses.Service); + return versionProcessor; } private ICrossSectionNdmAnalysis GetCrossSectionNdmAnalysis(ICrossSectionNdmAnalysis source) { - TraceLogger?.AddMessage(Message + " Cross-Section Ndm Analysis", TraceLogStatuses.Debug); + TraceLogger?.AddMessage(AnalysisIs + " Cross-Section Ndm Analysis", TraceLogStatuses.Service); + TraceLogger?.AddMessage("Cross-Section Ndm Analysis converting is started", TraceLogStatuses.Service); convertCrossSectionNdmAnalysisStrategy.ReferenceDictionary = ReferenceDictionary; convertCrossSectionNdmAnalysisStrategy.TraceLogger = TraceLogger; var convertLogic = new DictionaryConvertStrategy(this, convertCrossSectionNdmAnalysisStrategy); ICrossSectionNdmAnalysis crossSectionNdmAnalysis = convertLogic.Convert(source); + TraceLogger?.AddMessage("Cross-Section Ndm Analysis converting has been finished succesfully", TraceLogStatuses.Service); return crossSectionNdmAnalysis; } diff --git a/DataAccess/DTOs/Converters/ConcreteLibMaterialFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/ConcreteLibMaterialFromDTOConvertStrategy.cs new file mode 100644 index 0000000..2ea37a0 --- /dev/null +++ b/DataAccess/DTOs/Converters/ConcreteLibMaterialFromDTOConvertStrategy.cs @@ -0,0 +1,35 @@ +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models; +using StructureHelperLogics.Models.Materials; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class ConcreteLibMaterialFromDTOConvertStrategy : ConvertStrategy + { + private readonly IUpdateStrategy updateStrategy; + + public ConcreteLibMaterialFromDTOConvertStrategy(IUpdateStrategy updateStrategy) + { + this.updateStrategy = updateStrategy; + } + + public ConcreteLibMaterialFromDTOConvertStrategy() : this (new ConcreteLibUpdateStrategy()) + { + + } + + public override ConcreteLibMaterial GetNewItem(ConcreteLibMaterialDTO source) + { + TraceLogger?.AddMessage("Concrete library material converting is started", TraceLogStatuses.Service); + ConcreteLibMaterial newItem = new(source.Id); + updateStrategy.Update(newItem, source); + TraceLogger?.AddMessage("Concrete library material converting has been finished succesfully", TraceLogStatuses.Service); + return newItem; + } + } +} diff --git a/DataAccess/DTOs/Converters/CrossSectionFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/CrossSectionFromDTOConvertStrategy.cs new file mode 100644 index 0000000..1b6a64f --- /dev/null +++ b/DataAccess/DTOs/Converters/CrossSectionFromDTOConvertStrategy.cs @@ -0,0 +1,69 @@ +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models; +using StructureHelperCommon.Models.Loggers; +using StructureHelperLogics.Models.CrossSections; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class CrossSectionFromDTOConvertStrategy : IConvertStrategy + { + private readonly IConvertStrategy convertStrategy; + + public CrossSectionFromDTOConvertStrategy(IConvertStrategy convertStrategy) + { + this.convertStrategy = convertStrategy; + } + + public CrossSectionFromDTOConvertStrategy() : this (new CrossSectionRepositoryFromDTOConvertStrategy()) + { + + } + + public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } + public IShiftTraceLogger TraceLogger { get; set; } + + public ICrossSection Convert(ICrossSection source) + { + try + { + Check(); + return GetNewCrossSection(source); + } + catch (Exception ex) + { + TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error); + TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error); + throw; + } + } + + private ICrossSection GetNewCrossSection(ICrossSection source) + { + TraceLogger?.AddMessage("Cross-Section converting is started", TraceLogStatuses.Service); + CrossSection newItem = new(source.Id); + convertStrategy.ReferenceDictionary = ReferenceDictionary; + convertStrategy.TraceLogger = TraceLogger; + newItem.SectionRepository = GetNewCrossSectionRepository(source.SectionRepository); + TraceLogger?.AddMessage("Cross-Section converting has been finished succesfully", TraceLogStatuses.Service); + return newItem; + } + + private ICrossSectionRepository GetNewCrossSectionRepository(ICrossSectionRepository source) + { + ICrossSectionRepository newItem = convertStrategy.Convert(source); + TraceLogger?.AddMessage($"Object of type <<{newItem.GetType()}>> was obtained", TraceLogStatuses.Service); + return newItem; + } + + private void Check() + { + var checkLogic = new CheckConvertLogic(this); + checkLogic.Check(); + } + } +} diff --git a/DataAccess/DTOs/Converters/CrossSectionNdmAnalysisFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/CrossSectionNdmAnalysisFromDTOConvertStrategy.cs index c270d18..f8fe4e3 100644 --- a/DataAccess/DTOs/Converters/CrossSectionNdmAnalysisFromDTOConvertStrategy.cs +++ b/DataAccess/DTOs/Converters/CrossSectionNdmAnalysisFromDTOConvertStrategy.cs @@ -1,5 +1,6 @@ using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Models; +using StructureHelperCommon.Models.Analyses; using StructureHelperCommon.Models.Loggers; using StructureHelperLogic.Models.Analyses; using StructureHelperLogics.Models.Analyses; @@ -13,7 +14,18 @@ namespace DataAccess.DTOs.Converters { public class CrossSectionNdmAnalysisFromDTOConvertStrategy : IConvertStrategy { - private IUpdateStrategy updateStrategy = new CrossSectionNdmAnalysisUpdateStrategy(); + private IUpdateStrategy updateStrategy; + + public CrossSectionNdmAnalysisFromDTOConvertStrategy(IUpdateStrategy updateStrategy) + { + this.updateStrategy = updateStrategy; + } + + public CrossSectionNdmAnalysisFromDTOConvertStrategy() : this(new CrossSectionNdmAnalysisUpdateStrategy()) + { + + } + public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } public IShiftTraceLogger TraceLogger { get; set; } @@ -21,7 +33,8 @@ namespace DataAccess.DTOs.Converters { try { - CrossSectionNdmAnalysis newItem = GetCrossSectinNDMAnalysis(source); + Check(); + ICrossSectionNdmAnalysis newItem = GetCrossSectinNDMAnalysis(source); return newItem; } catch (Exception ex) @@ -33,11 +46,19 @@ namespace DataAccess.DTOs.Converters } - private CrossSectionNdmAnalysis GetCrossSectinNDMAnalysis(ICrossSectionNdmAnalysis source) + private ICrossSectionNdmAnalysis GetCrossSectinNDMAnalysis(ICrossSectionNdmAnalysis source) { + TraceLogger?.AddMessage("Cross-section sonverting is started"); CrossSectionNdmAnalysis newItem = new(source.Id); updateStrategy.Update(newItem, source); + TraceLogger?.AddMessage("Cross-section analysis was obtained succesfully"); return newItem; } + + private void Check() + { + var checkLogic = new CheckConvertLogic(this); + checkLogic.Check(); + } } } diff --git a/DataAccess/DTOs/Converters/CrossSectionNdmAnalysisToDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/CrossSectionNdmAnalysisToDTOConvertStrategy.cs index 8a8cb7d..a98f817 100644 --- a/DataAccess/DTOs/Converters/CrossSectionNdmAnalysisToDTOConvertStrategy.cs +++ b/DataAccess/DTOs/Converters/CrossSectionNdmAnalysisToDTOConvertStrategy.cs @@ -1,6 +1,7 @@ using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Models; using StructureHelperCommon.Models.Analyses; +using StructureHelperCommon.Models.Loggers; using StructureHelperLogic.Models.Analyses; using StructureHelperLogics.Models.Analyses; using System; @@ -38,7 +39,22 @@ namespace DataAccess.DTOs.Converters public CrossSectionNdmAnalysisDTO Convert(ICrossSectionNdmAnalysis source) { - Check(); + try + { + Check(); + return GetNewAnalysis(source); + } + catch (Exception ex) + { + TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error); + TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error); + throw; + } + } + + private CrossSectionNdmAnalysisDTO GetNewAnalysis(ICrossSectionNdmAnalysis source) + { + TraceLogger?.AddMessage("Cross-section ndm analysis converting is started", TraceLogStatuses.Debug); CrossSectionNdmAnalysisDTO newItem = new(); newItem.Id = source.Id; updateStrategy.Update(newItem, source); @@ -50,7 +66,9 @@ namespace DataAccess.DTOs.Converters ConvertStrategy = convertStrategy, TraceLogger = TraceLogger }; + TraceLogger?.AddMessage("Convert version processor is started", TraceLogStatuses.Service); newItem.VersionProcessor = convertLogic.Convert(source.VersionProcessor); + TraceLogger?.AddMessage("Cross-section ndm analysis has been converted succesfully", TraceLogStatuses.Service); return newItem; } diff --git a/DataAccess/DTOs/Converters/CrossSectionRepositoryFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/CrossSectionRepositoryFromDTOConvertStrategy.cs new file mode 100644 index 0000000..561f890 --- /dev/null +++ b/DataAccess/DTOs/Converters/CrossSectionRepositoryFromDTOConvertStrategy.cs @@ -0,0 +1,52 @@ +using StructureHelper.Models.Materials; +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models; +using StructureHelperCommon.Models.Loggers; +using StructureHelperLogics.Models.CrossSections; +using StructureHelperLogics.Models.Materials; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class CrossSectionRepositoryFromDTOConvertStrategy : ConvertStrategy + { + private const string convertStarted = " converting is started"; + private const string convertFinished = " converting has been finished succesfully"; + private CrossSectionRepository newRepository; + + public override CrossSectionRepository GetNewItem(ICrossSectionRepository source) + { + TraceLogger?.AddMessage("Cross-Section repository" + convertStarted, TraceLogStatuses.Service); + newRepository = new(source.Id); + ProcessMaterials(source); + ProcessActions(source); + TraceLogger?.AddMessage("Cross-Section repository" + convertFinished, TraceLogStatuses.Service); + return newRepository; + } + + private void ProcessActions(ICrossSectionRepository source) + { + TraceLogger?.AddMessage("Actions"+ convertStarted, TraceLogStatuses.Service); + TraceLogger?.AddMessage("Actions" + convertFinished, TraceLogStatuses.Service); + throw new NotImplementedException(); + } + + private void ProcessMaterials(IHasHeadMaterials source) + { + TraceLogger?.AddMessage("Materials" + convertStarted, TraceLogStatuses.Service); + var convertStrategy = new HeadMaterialFromDTOConvertStrategy + { + ReferenceDictionary = ReferenceDictionary, + TraceLogger = TraceLogger + }; + var convertLogic = new DictionaryConvertStrategy(this, convertStrategy); + var updateStrategy = new HasMaterialFromDTOUpdateStrategy(convertLogic); + updateStrategy.Update(newRepository, source); + TraceLogger?.AddMessage("Materials" + convertFinished, TraceLogStatuses.Service); + } + } +} diff --git a/DataAccess/DTOs/Converters/DateVersionFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/DateVersionFromDTOConvertStrategy.cs new file mode 100644 index 0000000..1db2fc4 --- /dev/null +++ b/DataAccess/DTOs/Converters/DateVersionFromDTOConvertStrategy.cs @@ -0,0 +1,71 @@ +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models; +using StructureHelperCommon.Models.Analyses; +using StructureHelperCommon.Models.Loggers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class DateVersionFromDTOConvertStrategy : IConvertStrategy + { + private IUpdateStrategy updateStrategy; + private IConvertStrategy convertStrategy; + private DictionaryConvertStrategy convertLogic; + + public DateVersionFromDTOConvertStrategy(IUpdateStrategy updateStrategy, + IConvertStrategy convertStrategy) + { + this.updateStrategy = updateStrategy; + this.convertStrategy = convertStrategy; + } + + public DateVersionFromDTOConvertStrategy() : this ( + new DateVersionUpdateStrategy(), + new VersionItemFromDTOConvertStrategy()) + { + + } + + + public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } + public IShiftTraceLogger TraceLogger { get; set; } + + public IDateVersion Convert(IDateVersion source) + { + try + { + Check(); + return GetDateVersion(source); + } + catch (Exception ex) + { + TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error); + TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error); + throw; + } + } + + private DateVersion GetDateVersion(IDateVersion source) + { + TraceLogger?.AddMessage("Date version converting is started", TraceLogStatuses.Service); + DateVersion newItem = new(source.Id); + updateStrategy.Update(newItem, source); + convertStrategy.ReferenceDictionary = ReferenceDictionary; + convertStrategy.TraceLogger = TraceLogger; + convertLogic = new DictionaryConvertStrategy(this, convertStrategy); + newItem.AnalysisVersion = convertLogic.Convert(source.AnalysisVersion); + TraceLogger?.AddMessage($"Date version date = {newItem.DateTime} converting has been finished", TraceLogStatuses.Service); + return newItem; + } + + private void Check() + { + var checkLogic = new CheckConvertLogic(this); + checkLogic.Check(); + } + } +} diff --git a/DataAccess/DTOs/Converters/DateVersionToDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/DateVersionToDTOConvertStrategy.cs index c4902a2..29ff5d1 100644 --- a/DataAccess/DTOs/Converters/DateVersionToDTOConvertStrategy.cs +++ b/DataAccess/DTOs/Converters/DateVersionToDTOConvertStrategy.cs @@ -1,6 +1,7 @@ using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Models; using StructureHelperCommon.Models.Analyses; +using StructureHelperCommon.Models.Loggers; using StructureHelperLogic.Models.Analyses; using StructureHelperLogics.Models.CrossSections; using System; @@ -37,7 +38,22 @@ namespace DataAccess.DTOs public DateVersionDTO Convert(IDateVersion source) { - Check(); + try + { + Check(); + return GetNewDateVersion(source); + } + catch (Exception ex) + { + TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error); + TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error); + throw; + } + } + + private DateVersionDTO GetNewDateVersion(IDateVersion source) + { + TraceLogger?.AddMessage("Date version converting is started", TraceLogStatuses.Debug); DateVersionDTO newItem = new() { Id = source.Id @@ -47,14 +63,13 @@ namespace DataAccess.DTOs convertStrategy.TraceLogger = TraceLogger; convertLogic = new DictionaryConvertStrategy(this, convertStrategy); newItem.AnalysisVersion = convertLogic.Convert(source.AnalysisVersion); + TraceLogger?.AddMessage("Date version converting has been finished", TraceLogStatuses.Service); return newItem; } private void Check() { - var checkLogic = new CheckConvertLogic(); - checkLogic.ConvertStrategy = this; - checkLogic.TraceLogger = TraceLogger; + var checkLogic = new CheckConvertLogic(this); checkLogic.Check(); } } diff --git a/DataAccess/DTOs/Converters/DesignForceTupleFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/DesignForceTupleFromDTOConvertStrategy.cs new file mode 100644 index 0000000..d26159b --- /dev/null +++ b/DataAccess/DTOs/Converters/DesignForceTupleFromDTOConvertStrategy.cs @@ -0,0 +1,45 @@ +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models.Forces; +using StructureHelperCommon.Models.Forces.Logics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class DesignForceTupleFromDTOConvertStrategy : ConvertStrategy + { + private IUpdateStrategy updateStrategy; + private IConvertStrategy forceTupleConvertStrategy; + + public DesignForceTupleFromDTOConvertStrategy( + IUpdateStrategy updateStrategy, + IConvertStrategy forceTupleConvertStrategy) + { + this.updateStrategy = updateStrategy; + this.forceTupleConvertStrategy = forceTupleConvertStrategy; + } + + public DesignForceTupleFromDTOConvertStrategy() : this( + new DesignForceTupleUpdateStrategy(), + new ForceTupleFromDTOConvertStrategy()) + { + + } + + public override DesignForceTuple GetNewItem(DesignForceTupleDTO source) + { + TraceLogger?.AddMessage("Design force tuple converting is started"); + DesignForceTuple newItem = new(source.Id); + updateStrategy.Update(newItem, source); + forceTupleConvertStrategy.ReferenceDictionary = ReferenceDictionary; + forceTupleConvertStrategy.TraceLogger = TraceLogger; + var convertLogic = new DictionaryConvertStrategy(this, forceTupleConvertStrategy); + newItem.ForceTuple = convertLogic.Convert((ForceTupleDTO)source.ForceTuple); + TraceLogger?.AddMessage("Design force tuple converting has been finished"); + return newItem; + } + } +} diff --git a/DataAccess/DTOs/Converters/DesignForceTupleToDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/DesignForceTupleToDTOConvertStrategy.cs index 216dd14..cd33d18 100644 --- a/DataAccess/DTOs/Converters/DesignForceTupleToDTOConvertStrategy.cs +++ b/DataAccess/DTOs/Converters/DesignForceTupleToDTOConvertStrategy.cs @@ -24,7 +24,8 @@ namespace DataAccess.DTOs.Converters this.forceTupleConvertStrategy = forceTupleConvertStrategy; } - public DesignForceTupleToDTOConvertStrategy() : this(new DesignForceTupleUpdateStrategy(), + public DesignForceTupleToDTOConvertStrategy() : this( + new DesignForceTupleUpdateStrategy(), new ForceTupleToDTOConvertStrategy()) { diff --git a/DataAccess/DTOs/Converters/ElasticMaterialFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/ElasticMaterialFromDTOConvertStrategy.cs new file mode 100644 index 0000000..e60fda1 --- /dev/null +++ b/DataAccess/DTOs/Converters/ElasticMaterialFromDTOConvertStrategy.cs @@ -0,0 +1,35 @@ +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models; +using StructureHelperLogics.Models.Materials; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class ElasticMaterialFromDTOConvertStrategy : ConvertStrategy + { + private readonly IUpdateStrategy updateStrategy; + + public ElasticMaterialFromDTOConvertStrategy(IUpdateStrategy updateStrategy) + { + this.updateStrategy = updateStrategy; + } + + public ElasticMaterialFromDTOConvertStrategy() : this (new ElasticUpdateStrategy()) + { + + } + + public override ElasticMaterial GetNewItem(ElasticMaterialDTO source) + { + TraceLogger?.AddMessage("Elastic material converting is started", TraceLogStatuses.Service); + ElasticMaterial newItem = new(source.Id); + updateStrategy.Update(newItem, source); + TraceLogger?.AddMessage("Elastic material converting has been finished succesfully", TraceLogStatuses.Service); + return newItem; + } + } +} diff --git a/DataAccess/DTOs/Converters/FRMaterialFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/FRMaterialFromDTOConvertStrategy.cs new file mode 100644 index 0000000..e1f5489 --- /dev/null +++ b/DataAccess/DTOs/Converters/FRMaterialFromDTOConvertStrategy.cs @@ -0,0 +1,35 @@ +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models; +using StructureHelperLogics.Models.Materials; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class FRMaterialFromDTOConvertStrategy : ConvertStrategy + { + private IUpdateStrategy updateStrategy; + + public FRMaterialFromDTOConvertStrategy(IUpdateStrategy updateStrategy) + { + this.updateStrategy = updateStrategy; + } + + public FRMaterialFromDTOConvertStrategy() : this(new FRUpdateStrategy()) + { + + } + + public override FRMaterial GetNewItem(FRMaterialDTO source) + { + TraceLogger?.AddMessage("Fiber reinforcement material converting is started", TraceLogStatuses.Service); + FRMaterial newItem = new(source.MaterialType, source.Id); + updateStrategy.Update(newItem, source); + TraceLogger?.AddMessage("FiberReinforcement material converting has been finished succesfully", TraceLogStatuses.Service); + return newItem; + } + } +} diff --git a/DataAccess/DTOs/Converters/ForceActionToDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/ForceActionToDTOConvertStrategy.cs index de24785..f535e98 100644 --- a/DataAccess/DTOs/Converters/ForceActionToDTOConvertStrategy.cs +++ b/DataAccess/DTOs/Converters/ForceActionToDTOConvertStrategy.cs @@ -6,7 +6,7 @@ using StructureHelperCommon.Models.Loggers; namespace DataAccess.DTOs.Converters { - public class ForceActionToDTOConvertStrategy : IConvertStrategy + public class ForceActionToDTOConvertStrategy : ConvertStrategy { private IConvertStrategy forceCombinationByFactorConvertStrategy; private IConvertStrategy forceCombinationListConvertStrategy; @@ -26,24 +26,7 @@ namespace DataAccess.DTOs.Converters } - public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } - public IShiftTraceLogger TraceLogger { get; set; } - - public IForceAction Convert(IForceAction source) - { - try - { - return ProcessForceAction(source); - } - catch (Exception ex) - { - TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error); - TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error); - throw; - } - } - - private IForceAction ProcessForceAction(IForceAction source) + public override IForceAction GetNewItem(IForceAction source) { if (source is IForceCombinationByFactor forceCombinationByFactor) { diff --git a/DataAccess/DTOs/Converters/ForceActionsFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/ForceActionsFromDTOConvertStrategy.cs new file mode 100644 index 0000000..b7a7b98 --- /dev/null +++ b/DataAccess/DTOs/Converters/ForceActionsFromDTOConvertStrategy.cs @@ -0,0 +1,66 @@ +using StructureHelperCommon.Infrastructures.Exceptions; +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models; +using StructureHelperCommon.Models.Forces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class ForceActionsFromDTOConvertStrategy : ConvertStrategy + { + private IConvertStrategy listConvertStrategy; + private IConvertStrategy factorConvertStrategy; + + public ForceActionsFromDTOConvertStrategy( + IConvertStrategy listConvertStrategy, + IConvertStrategy factorConvertStrategy) + { + this.listConvertStrategy = listConvertStrategy; + this.factorConvertStrategy = factorConvertStrategy; + } + + public ForceActionsFromDTOConvertStrategy() : this ( + new ForceCombinationListFromDTOConvertStrategy(), + new ForceCombinationByFactorFromDTOConvertStrategy()) + { + + } + + public override IForceAction GetNewItem(IForceAction source) + { + if (source is ForceCombinationByFactorDTO combination) + { + return GetForceCombination(combination); + } + if (source is ForceCombinationListDTO forceList) + { + return GetForceList(forceList); + } + string errorString = ErrorStrings.ObjectTypeIsUnknownObj(source); + TraceLogger.AddMessage(errorString, TraceLogStatuses.Error); + throw new StructureHelperException(errorString); + } + + private IForceAction GetForceCombination(ForceCombinationByFactorDTO source) + { + TraceLogger?.AddMessage("Force action is combination by factors"); + factorConvertStrategy.ReferenceDictionary = ReferenceDictionary; + factorConvertStrategy.TraceLogger = TraceLogger; + ForceCombinationByFactor newItem = factorConvertStrategy.Convert(source); + return newItem; + } + + private IForceAction GetForceList(ForceCombinationListDTO forceList) + { + TraceLogger?.AddMessage("Force action is combination by list"); + listConvertStrategy.ReferenceDictionary = ReferenceDictionary; + listConvertStrategy.TraceLogger = TraceLogger; + ForceCombinationList newItem = listConvertStrategy.Convert(forceList); + return newItem; + } + } +} diff --git a/DataAccess/DTOs/Converters/ForceCombinationByFactorFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/ForceCombinationByFactorFromDTOConvertStrategy.cs new file mode 100644 index 0000000..166718e --- /dev/null +++ b/DataAccess/DTOs/Converters/ForceCombinationByFactorFromDTOConvertStrategy.cs @@ -0,0 +1,57 @@ +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models.Forces; +using StructureHelperCommon.Models.Forces.Logics; +using StructureHelperCommon.Models.Shapes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class ForceCombinationByFactorFromDTOConvertStrategy : ConvertStrategy + { + private IUpdateStrategy baseUpdateStrategy; + private IUpdateStrategy updateStrategy; + private IConvertStrategy pointConvertStrategy; + private IConvertStrategy forceTupleConvertStrategy; + + public ForceCombinationByFactorFromDTOConvertStrategy( + IUpdateStrategy baseUpdateStrategy, + IUpdateStrategy updateStrategy, + IConvertStrategy pointConvertStrategy, + IConvertStrategy forceTupleConvertStrategy) + { + this.baseUpdateStrategy = baseUpdateStrategy; + this.updateStrategy = updateStrategy; + this.pointConvertStrategy = pointConvertStrategy; + this.forceTupleConvertStrategy = forceTupleConvertStrategy; + } + + public ForceCombinationByFactorFromDTOConvertStrategy() : this( + new ForceActionBaseUpdateStrategy(), + new ForceCombinationByFactorUpdateStrategy(), + new Point2DFromDTOConvertStrategy(), + new ForceTupleFromDTOConvertStrategy()) + { + + } + + public override ForceCombinationByFactor GetNewItem(ForceCombinationByFactorDTO source) + { + TraceLogger.AddMessage($"Force combination by factor name = {source.Name} is starting"); + ForceCombinationByFactor newItem = new(source.Id); + baseUpdateStrategy.Update(newItem, source); + updateStrategy.Update(newItem, source); + pointConvertStrategy.ReferenceDictionary = ReferenceDictionary; + pointConvertStrategy.TraceLogger = TraceLogger; + newItem.ForcePoint = pointConvertStrategy.Convert((Point2DDTO)source.ForcePoint); + forceTupleConvertStrategy.ReferenceDictionary = ReferenceDictionary; + forceTupleConvertStrategy.TraceLogger = TraceLogger; + newItem.FullSLSForces = forceTupleConvertStrategy.Convert((ForceTupleDTO)source.FullSLSForces); + TraceLogger.AddMessage($"Force combination by factor name = {newItem.Name} has been finished"); + return newItem; + } + } +} diff --git a/DataAccess/DTOs/Converters/ForceCombinationListFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/ForceCombinationListFromDTOConvertStrategy.cs new file mode 100644 index 0000000..509fb81 --- /dev/null +++ b/DataAccess/DTOs/Converters/ForceCombinationListFromDTOConvertStrategy.cs @@ -0,0 +1,61 @@ +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models.Forces; +using StructureHelperCommon.Models.Forces.Logics; +using StructureHelperCommon.Models.Shapes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class ForceCombinationListFromDTOConvertStrategy : ConvertStrategy + { + private IUpdateStrategy baseUpdateStrategy; + private IUpdateStrategy updateStrategy; + private IConvertStrategy pointConvertStrategy; + private IConvertStrategy designTupleConvertStrategy; + + public ForceCombinationListFromDTOConvertStrategy( + IUpdateStrategy baseUpdateStrategy, + IUpdateStrategy updateStrategy, + IConvertStrategy pointConvertStrategy, + IConvertStrategy designTupleConvertStrategy) + { + this.baseUpdateStrategy = baseUpdateStrategy; + this.updateStrategy = updateStrategy; + this.pointConvertStrategy = pointConvertStrategy; + this.designTupleConvertStrategy = designTupleConvertStrategy; + } + + public ForceCombinationListFromDTOConvertStrategy() : this( + new ForceActionBaseUpdateStrategy(), + new ForceCombinationListUpdateStrategy(), + new Point2DFromDTOConvertStrategy(), + new DesignForceTupleFromDTOConvertStrategy()) + { + + } + + public override ForceCombinationList GetNewItem(ForceCombinationListDTO source) + { + TraceLogger?.AddMessage($"Force combination list name = {source.Name} is starting"); + ForceCombinationList newItem = new(source.Id); + baseUpdateStrategy.Update(newItem, source); + updateStrategy.Update(newItem, source); + pointConvertStrategy.ReferenceDictionary = ReferenceDictionary; + pointConvertStrategy.TraceLogger = TraceLogger; + newItem.ForcePoint = pointConvertStrategy.Convert((Point2DDTO)source.ForcePoint); + designTupleConvertStrategy.ReferenceDictionary = ReferenceDictionary; + designTupleConvertStrategy.TraceLogger = TraceLogger; + foreach (var item in source.DesignForces) + { + DesignForceTuple newDesignTuple = designTupleConvertStrategy.Convert((DesignForceTupleDTO)item); + newItem.DesignForces.Add(newDesignTuple); + } + TraceLogger?.AddMessage($"Force combination list name = {newItem.Name} has been finished succesfully"); + return newItem; + } + } +} diff --git a/DataAccess/DTOs/Converters/ForceTupleFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/ForceTupleFromDTOConvertStrategy.cs new file mode 100644 index 0000000..f69d28d --- /dev/null +++ b/DataAccess/DTOs/Converters/ForceTupleFromDTOConvertStrategy.cs @@ -0,0 +1,32 @@ +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models.Forces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class ForceTupleFromDTOConvertStrategy : ConvertStrategy + { + private readonly IUpdateStrategy updateStrategy; + + public ForceTupleFromDTOConvertStrategy(IUpdateStrategy updateStrategy) + { + this.updateStrategy = updateStrategy; + } + + public ForceTupleFromDTOConvertStrategy() : this(new ForceTupleUpdateStrategy()) + { + + } + + public override ForceTuple GetNewItem(ForceTupleDTO source) + { + ForceTuple newItem = new(source.Id); + updateStrategy.Update(newItem, source); + return newItem; + } + } +} diff --git a/DataAccess/DTOs/Converters/ForceTupleToDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/ForceTupleToDTOConvertStrategy.cs index 67dd1a0..c0ceaac 100644 --- a/DataAccess/DTOs/Converters/ForceTupleToDTOConvertStrategy.cs +++ b/DataAccess/DTOs/Converters/ForceTupleToDTOConvertStrategy.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace DataAccess.DTOs { - public class ForceTupleToDTOConvertStrategy : IConvertStrategy + public class ForceTupleToDTOConvertStrategy : ConvertStrategy { private IUpdateStrategy updateStrategy; @@ -27,27 +27,11 @@ namespace DataAccess.DTOs } - public ForceTupleDTO Convert(IForceTuple source) + public override ForceTupleDTO GetNewItem(IForceTuple source) { - Check(); - try - { - ForceTupleDTO newItem = new() { Id = source.Id}; - updateStrategy.Update(newItem, source); - return newItem; - } - catch (Exception ex) - { - TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Debug); - TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error); - throw; - } - } - - private void Check() - { - var checkLogic = new CheckConvertLogic(this); - checkLogic.Check(); + ForceTupleDTO newItem = new() { Id = source.Id}; + updateStrategy.Update(newItem, source); + return newItem; } } } diff --git a/DataAccess/DTOs/Converters/HasMaterialFromDTOUpdateStrategy.cs b/DataAccess/DTOs/Converters/HasMaterialFromDTOUpdateStrategy.cs new file mode 100644 index 0000000..b794e60 --- /dev/null +++ b/DataAccess/DTOs/Converters/HasMaterialFromDTOUpdateStrategy.cs @@ -0,0 +1,37 @@ +using StructureHelper.Models.Materials; +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperLogics.Models.Materials; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +//Copyright (c) 2024 Redikultsev Evgeny, Ekaterinburg, Russia +//All rights reserved. + +namespace DataAccess.DTOs +{ + /// + /// Creates copies of materials from source and adds them into target material list + /// + public class HasMaterialFromDTOUpdateStrategy : IUpdateStrategy + { + private readonly IConvertStrategy convertStrategy; + + public HasMaterialFromDTOUpdateStrategy(IConvertStrategy convertStrategy) + { + this.convertStrategy = convertStrategy; + } + + public void Update(IHasHeadMaterials targetObject, IHasHeadMaterials sourceObject) + { + targetObject.HeadMaterials.Clear(); + foreach (var item in sourceObject.HeadMaterials) + { + var newItem = convertStrategy.Convert(item); + targetObject.HeadMaterials.Add(newItem); + } + } + } +} diff --git a/DataAccess/DTOs/Converters/HeadMaterialFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/HeadMaterialFromDTOConvertStrategy.cs new file mode 100644 index 0000000..e47560d --- /dev/null +++ b/DataAccess/DTOs/Converters/HeadMaterialFromDTOConvertStrategy.cs @@ -0,0 +1,58 @@ +using DataAccess.DTOs.Converters; +using StructureHelper.Models.Materials; +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models; +using StructureHelperCommon.Models.Loggers; +using StructureHelperLogics.Models.CrossSections; +using StructureHelperLogics.Models.Materials; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class HeadMaterialFromDTOConvertStrategy : ConvertStrategy + { + private IUpdateStrategy updateStrategy; + private IConvertStrategy helperMaterialConvertStrategy; + + public HeadMaterialFromDTOConvertStrategy( + IUpdateStrategy updateStrategy, + IConvertStrategy helperMaterialConvertStrategy) + { + this.updateStrategy = updateStrategy; + this.helperMaterialConvertStrategy = helperMaterialConvertStrategy; + } + + public HeadMaterialFromDTOConvertStrategy() : this ( + new HeadMaterialBaseUpdateStrategy(), + new HelperMaterialFromDTOConvertStrategy()) + { + + } + public override IHeadMaterial GetNewItem(IHeadMaterial source) + { + TraceLogger?.AddMessage("Head material converting is started", TraceLogStatuses.Service); + HeadMaterial newItem = new(source.Id); + updateStrategy.Update(newItem, source); + IHelperMaterial helperMaterial = GetHelperMaterial(source.HelperMaterial); + newItem.HelperMaterial = helperMaterial; + //GlobalRepository + TraceLogger?.AddMessage($"Head material Name = {newItem.Name} converting has been finished succesfully", TraceLogStatuses.Service); + return newItem; + } + + private IHelperMaterial GetHelperMaterial(IHelperMaterial source) + { + TraceLogger?.AddMessage("Helper material converting is started", TraceLogStatuses.Service); + helperMaterialConvertStrategy.ReferenceDictionary = ReferenceDictionary; + helperMaterialConvertStrategy.TraceLogger = TraceLogger; + IHelperMaterial newItem = helperMaterialConvertStrategy.Convert(source); + TraceLogger?.AddMessage($"Object of type <<{newItem.GetType()}>> was obtained", TraceLogStatuses.Service); + return newItem; + } + + } +} diff --git a/DataAccess/DTOs/Converters/HelperMaterialDTOSafetyFactorUpdateStrategy.cs b/DataAccess/DTOs/Converters/HelperMaterialDTOSafetyFactorUpdateStrategy.cs index 41a53bb..caedb75 100644 --- a/DataAccess/DTOs/Converters/HelperMaterialDTOSafetyFactorUpdateStrategy.cs +++ b/DataAccess/DTOs/Converters/HelperMaterialDTOSafetyFactorUpdateStrategy.cs @@ -8,12 +8,13 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace DataAccess.DTOs.Converters +namespace DataAccess.DTOs { public class HelperMaterialDTOSafetyFactorUpdateStrategy : IUpdateStrategy { private IUpdateStrategy safetyFactorUpdateStrategy; private IUpdateStrategy partialFactorUpdateStrategy; + private IMaterialSafetyFactorDTOLogic factorDTOLogic; public HelperMaterialDTOSafetyFactorUpdateStrategy( IUpdateStrategy safetyFactorUpdateStrategy, @@ -23,11 +24,11 @@ namespace DataAccess.DTOs.Converters this.partialFactorUpdateStrategy = partialFactorUpdateStrategy; } - public HelperMaterialDTOSafetyFactorUpdateStrategy() : this( - new MaterialSafetyFactorUpdateStrategy(), + public HelperMaterialDTOSafetyFactorUpdateStrategy(IMaterialSafetyFactorDTOLogic factorDTOLogic) : this( + new MaterialSafetyFactorBaseUpdateStrategy(), new MaterialPartialFactorUpdateStrategy()) { - + this.factorDTOLogic = factorDTOLogic; } public void Update(IHelperMaterial targetObject, IHelperMaterial sourceObject) @@ -40,35 +41,29 @@ namespace DataAccess.DTOs.Converters targetObject.SafetyFactors.Clear(); foreach (var safetyFactor in sourceObject.SafetyFactors) { - MaterialSafetyFactorDTO newSafetyFactor = GetNewSafetyFactorByOld(safetyFactor); + IMaterialSafetyFactor newSafetyFactor = GetNewSafetyFactorByOld(safetyFactor); targetObject.SafetyFactors.Add(newSafetyFactor); } } } - private MaterialSafetyFactorDTO GetNewSafetyFactorByOld(IMaterialSafetyFactor safetyFactor) + private IMaterialSafetyFactor GetNewSafetyFactorByOld(IMaterialSafetyFactor safetyFactor) { - MaterialSafetyFactorDTO newSafetyFactor = new() - { - Id = safetyFactor.Id - }; + IMaterialSafetyFactor newSafetyFactor = factorDTOLogic.GetNewSafetyFactorByOld(safetyFactor); safetyFactorUpdateStrategy.Update(newSafetyFactor, safetyFactor); newSafetyFactor.PartialFactors.Clear(); foreach (var partialFactor in safetyFactor.PartialFactors) { - MaterialPartialFactorDTO newPartialFactor = GetNewPartialFactorByOld(partialFactor); + IMaterialPartialFactor newPartialFactor = GetNewPartialFactorByOld(partialFactor); newSafetyFactor.PartialFactors.Add(newPartialFactor); } return newSafetyFactor; } - private MaterialPartialFactorDTO GetNewPartialFactorByOld(IMaterialPartialFactor partialFactor) + private IMaterialPartialFactor GetNewPartialFactorByOld(IMaterialPartialFactor partialFactor) { - MaterialPartialFactorDTO newPartialFactor = new() - { - Id = partialFactor.Id - }; + IMaterialPartialFactor newPartialFactor = factorDTOLogic.GetNewPartialFactorByOld(partialFactor); partialFactorUpdateStrategy.Update(newPartialFactor, partialFactor); return newPartialFactor; } diff --git a/DataAccess/DTOs/Converters/HelperMaterialFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/HelperMaterialFromDTOConvertStrategy.cs new file mode 100644 index 0000000..dc5f73c --- /dev/null +++ b/DataAccess/DTOs/Converters/HelperMaterialFromDTOConvertStrategy.cs @@ -0,0 +1,113 @@ +using DataAccess.DTOs.Converters; +using StructureHelper.Models.Materials; +using StructureHelperCommon.Infrastructures.Exceptions; +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models; +using StructureHelperLogics.Models.Materials; +using System; +using System.CodeDom; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class HelperMaterialFromDTOConvertStrategy : ConvertStrategy + { + const string MaterialIs = "Material type is: "; + private IConvertStrategy concreteConvertStrategy; + private IConvertStrategy reinforcementConvertStrategy; + private IConvertStrategy elasticConvertStrategy; + private IConvertStrategy frConvertStrategy; + private IUpdateStrategy safetyFactorUpdateStrategy = new HelperMaterialDTOSafetyFactorUpdateStrategy(new MaterialSafetyFactorsFromDTOLogic()); + + public HelperMaterialFromDTOConvertStrategy() : this( + new ConcreteLibMaterialFromDTOConvertStrategy(), + new ReinforcementLibMaterialFromDTOConvertStrategy(), + new ElasticMaterialFromDTOConvertStrategy(), + new FRMaterialFromDTOConvertStrategy() + ) + { + + } + + public HelperMaterialFromDTOConvertStrategy( + IConvertStrategy concreteConvertStrategy, + IConvertStrategy reinforcementConvertStrategy, + IConvertStrategy elasticConvertStrategy, + IConvertStrategy frConvertStrategy) + { + this.concreteConvertStrategy = concreteConvertStrategy; + this.reinforcementConvertStrategy = reinforcementConvertStrategy; + this.elasticConvertStrategy = elasticConvertStrategy; + this.frConvertStrategy = frConvertStrategy; + } + + public override IHelperMaterial GetNewItem(IHelperMaterial source) + { + if (source is ConcreteLibMaterialDTO concrete) + { + return GetConcreteMaterial(concrete); + } + else if (source is ReinforcementLibMaterialDTO reinforcement) + { + return GetReinforcementMaterial(reinforcement); + } + else if (source is FRMaterialDTO frMaterial) + { + return GetFRMaterial(frMaterial); + } + else if (source is ElasticMaterialDTO elastic) + { + return GetElasticMaterial(elastic); + } + else + { + string errorString = ErrorStrings.ObjectTypeIsUnknownObj(source) + ": helper material type"; + TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error); + throw new StructureHelperException(errorString); + } + } + + private IHelperMaterial GetElasticMaterial(ElasticMaterialDTO source) + { + TraceLogger?.AddMessage(MaterialIs + "Elastic material", TraceLogStatuses.Service); + reinforcementConvertStrategy.ReferenceDictionary = ReferenceDictionary; + reinforcementConvertStrategy.TraceLogger = TraceLogger; + var newItem = elasticConvertStrategy.Convert(source); + safetyFactorUpdateStrategy.Update(newItem, source); + return newItem; + } + + private IHelperMaterial GetFRMaterial(FRMaterialDTO source) + { + TraceLogger?.AddMessage(MaterialIs + "Fiber reinforcement material", TraceLogStatuses.Service); + reinforcementConvertStrategy.ReferenceDictionary = ReferenceDictionary; + reinforcementConvertStrategy.TraceLogger = TraceLogger; + var newItem = frConvertStrategy.Convert(source); + safetyFactorUpdateStrategy.Update(newItem, source); + return newItem; + } + + private IHelperMaterial GetReinforcementMaterial(ReinforcementLibMaterialDTO source) + { + TraceLogger?.AddMessage(MaterialIs + "Reinforcement library material", TraceLogStatuses.Service); + reinforcementConvertStrategy.ReferenceDictionary = ReferenceDictionary; + reinforcementConvertStrategy.TraceLogger = TraceLogger; + var newItem = reinforcementConvertStrategy.Convert(source); + safetyFactorUpdateStrategy.Update(newItem, source); + return newItem; + } + + private IHelperMaterial GetConcreteMaterial(ConcreteLibMaterialDTO source) + { + TraceLogger?.AddMessage(MaterialIs + "Concrete library material", TraceLogStatuses.Service); + concreteConvertStrategy.ReferenceDictionary = ReferenceDictionary; + concreteConvertStrategy.TraceLogger = TraceLogger; + var newItem = concreteConvertStrategy.Convert(source); + safetyFactorUpdateStrategy.Update(newItem, source); + return newItem; + } + } +} diff --git a/DataAccess/DTOs/Converters/HelperMaterialToDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/HelperMaterialToDTOConvertStrategy.cs index 97646e2..9043712 100644 --- a/DataAccess/DTOs/Converters/HelperMaterialToDTOConvertStrategy.cs +++ b/DataAccess/DTOs/Converters/HelperMaterialToDTOConvertStrategy.cs @@ -20,7 +20,7 @@ namespace DataAccess.DTOs private LibMaterialToDTOConvertStrategy reinforcementConvertStrategy; private IConvertStrategy elasticConvertStrategy; private IConvertStrategy frMaterialConvertStrategy; - private IUpdateStrategy safetyFactorUpdateStrategy = new HelperMaterialDTOSafetyFactorUpdateStrategy(); + private IUpdateStrategy safetyFactorUpdateStrategy = new HelperMaterialDTOSafetyFactorUpdateStrategy(new MaterialSafetyFactorToDTOLogic()); public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } public IShiftTraceLogger TraceLogger { get; set; } diff --git a/DataAccess/DTOs/Converters/IMaterialSafetyFactorDTOLogic.cs b/DataAccess/DTOs/Converters/IMaterialSafetyFactorDTOLogic.cs new file mode 100644 index 0000000..98a9a0a --- /dev/null +++ b/DataAccess/DTOs/Converters/IMaterialSafetyFactorDTOLogic.cs @@ -0,0 +1,10 @@ +using StructureHelperCommon.Models.Materials.Libraries; + +namespace DataAccess.DTOs +{ + public interface IMaterialSafetyFactorDTOLogic + { + IMaterialPartialFactor GetNewPartialFactorByOld(IMaterialPartialFactor partialFactor); + IMaterialSafetyFactor GetNewSafetyFactorByOld(IMaterialSafetyFactor safetyFactor); + } +} \ No newline at end of file diff --git a/DataAccess/DTOs/Converters/MaterialSafetyFactorToDTOLogic.cs b/DataAccess/DTOs/Converters/MaterialSafetyFactorToDTOLogic.cs new file mode 100644 index 0000000..68e6a7b --- /dev/null +++ b/DataAccess/DTOs/Converters/MaterialSafetyFactorToDTOLogic.cs @@ -0,0 +1,30 @@ +using StructureHelperCommon.Models.Materials.Libraries; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class MaterialSafetyFactorToDTOLogic : IMaterialSafetyFactorDTOLogic + { + public IMaterialSafetyFactor GetNewSafetyFactorByOld(IMaterialSafetyFactor safetyFactor) + { + MaterialSafetyFactorDTO newSafetyFactor = new() + { + Id = safetyFactor.Id + }; + return newSafetyFactor; + } + + public IMaterialPartialFactor GetNewPartialFactorByOld(IMaterialPartialFactor partialFactor) + { + MaterialPartialFactorDTO newPartialFactor = new() + { + Id = partialFactor.Id + }; + return newPartialFactor; + } + } +} diff --git a/DataAccess/DTOs/Converters/MaterialSafetyFactorsFromDTOLogic.cs b/DataAccess/DTOs/Converters/MaterialSafetyFactorsFromDTOLogic.cs new file mode 100644 index 0000000..5cf18d6 --- /dev/null +++ b/DataAccess/DTOs/Converters/MaterialSafetyFactorsFromDTOLogic.cs @@ -0,0 +1,24 @@ +using StructureHelperCommon.Models.Materials.Libraries; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class MaterialSafetyFactorsFromDTOLogic : IMaterialSafetyFactorDTOLogic + { + public IMaterialSafetyFactor GetNewSafetyFactorByOld(IMaterialSafetyFactor safetyFactor) + { + MaterialSafetyFactor newItem = new(safetyFactor.Id); + return newItem; + } + public IMaterialPartialFactor GetNewPartialFactorByOld(IMaterialPartialFactor partialFactor) + { + MaterialPartialFactor newItem = new(partialFactor.Id); + return newItem; + } + + } +} diff --git a/DataAccess/DTOs/Converters/MaterialSafetyFactorToDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/MaterialSafetyFactorsToDTOConvertStrategy.cs similarity index 75% rename from DataAccess/DTOs/Converters/MaterialSafetyFactorToDTOConvertStrategy.cs rename to DataAccess/DTOs/Converters/MaterialSafetyFactorsToDTOConvertStrategy.cs index 4c9252e..72f1b2e 100644 --- a/DataAccess/DTOs/Converters/MaterialSafetyFactorToDTOConvertStrategy.cs +++ b/DataAccess/DTOs/Converters/MaterialSafetyFactorsToDTOConvertStrategy.cs @@ -9,13 +9,13 @@ using System.Threading.Tasks; namespace DataAccess.DTOs { - public class MaterialSafetyFactorToDTOConvertStrategy : IConvertStrategy + public class MaterialSafetyFactorsToDTOConvertStrategy : IConvertStrategy { private IUpdateStrategy updateStrategy; public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } public IShiftTraceLogger TraceLogger { get; set; } - public MaterialSafetyFactorToDTOConvertStrategy(IUpdateStrategy updateStrategy) + public MaterialSafetyFactorsToDTOConvertStrategy(IUpdateStrategy updateStrategy) { this.updateStrategy = updateStrategy; } diff --git a/DataAccess/DTOs/Converters/Point2DFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/Point2DFromDTOConvertStrategy.cs new file mode 100644 index 0000000..36da054 --- /dev/null +++ b/DataAccess/DTOs/Converters/Point2DFromDTOConvertStrategy.cs @@ -0,0 +1,34 @@ +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models.Shapes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class Point2DFromDTOConvertStrategy : ConvertStrategy + { + private IUpdateStrategy updateStrategy; + + public Point2DFromDTOConvertStrategy(IUpdateStrategy updateStrategy) + { + this.updateStrategy = updateStrategy; + } + + public Point2DFromDTOConvertStrategy() : this (new Point2DUpdateStrategy()) + { + + } + + public override Point2D GetNewItem(Point2DDTO source) + { + TraceLogger?.AddMessage("Point 2D converting is started"); + Point2D newItem = new(source.Id); + updateStrategy.Update(newItem, source); + TraceLogger?.AddMessage("Point 2D converting has been finished"); + return newItem; + } + } +} diff --git a/DataAccess/DTOs/Converters/ProjectFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/ProjectFromDTOConvertStrategy.cs index 8e03426..b60c3e9 100644 --- a/DataAccess/DTOs/Converters/ProjectFromDTOConvertStrategy.cs +++ b/DataAccess/DTOs/Converters/ProjectFromDTOConvertStrategy.cs @@ -48,18 +48,28 @@ namespace DataAccess.DTOs 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(this, visualAnalysisConvertStrategy); newItem.VisualAnalyses.Clear(); + TraceLogger?.AddMessage($"Source project has {source.VisualAnalyses.Count()} analyses", TraceLogStatuses.Service); foreach (var item in source.VisualAnalyses) { var visualAnalysis = convertLogic.Convert(item); newItem.VisualAnalyses.Add(visualAnalysis); } - TraceLogger?.AddMessage("Converting project has completed succesfully", TraceLogStatuses.Info); + if (newItem.VisualAnalyses.Any()) + { + TraceLogger?.AddMessage($"Totaly {newItem.VisualAnalyses.Count()} were(was) obtained", TraceLogStatuses.Service); + } + else + { + TraceLogger?.AddMessage($"Project does not have any analyses", TraceLogStatuses.Warning); + } + TraceLogger?.AddMessage("Converting of project has completed succesfully", TraceLogStatuses.Service); return newItem; } diff --git a/DataAccess/DTOs/Converters/ReinforcementLibMaterialFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/ReinforcementLibMaterialFromDTOConvertStrategy.cs new file mode 100644 index 0000000..3d8b698 --- /dev/null +++ b/DataAccess/DTOs/Converters/ReinforcementLibMaterialFromDTOConvertStrategy.cs @@ -0,0 +1,35 @@ +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models; +using StructureHelperLogics.Models.Materials; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class ReinforcementLibMaterialFromDTOConvertStrategy : ConvertStrategy + { + private readonly IUpdateStrategy updateStrategy; + + public ReinforcementLibMaterialFromDTOConvertStrategy(IUpdateStrategy updateStrategy) + { + this.updateStrategy = updateStrategy; + } + + public ReinforcementLibMaterialFromDTOConvertStrategy() : this(new ReinforcementLibUpdateStrategy()) + { + + } + + public override ReinforcementLibMaterial GetNewItem(ReinforcementLibMaterialDTO source) + { + TraceLogger?.AddMessage("Reinforcement library material converting is started", TraceLogStatuses.Service); + ReinforcementLibMaterial newItem = new(source.Id); + updateStrategy.Update(newItem, source); + TraceLogger?.AddMessage("Reinforcement library material converting has been finished succesfully", TraceLogStatuses.Service); + return newItem; + } + } +} diff --git a/DataAccess/DTOs/Converters/VersionItemFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/VersionItemFromDTOConvertStrategy.cs new file mode 100644 index 0000000..439a8b4 --- /dev/null +++ b/DataAccess/DTOs/Converters/VersionItemFromDTOConvertStrategy.cs @@ -0,0 +1,77 @@ +using StructureHelperCommon.Infrastructures.Exceptions; +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models; +using StructureHelperCommon.Models.Loggers; +using StructureHelperLogics.Models.CrossSections; + +namespace DataAccess.DTOs +{ + public class VersionItemFromDTOConvertStrategy : IConvertStrategy + { + private const string AnalysisIs = "Analysis type is"; + private IConvertStrategy crossSectionConvertStrategy; + + public VersionItemFromDTOConvertStrategy(IConvertStrategy crossSectionConvertStrategy) + { + this.crossSectionConvertStrategy = crossSectionConvertStrategy; + } + + public VersionItemFromDTOConvertStrategy() : this (new CrossSectionFromDTOConvertStrategy()) + { + + } + + public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } + public IShiftTraceLogger TraceLogger { get; set; } + + public ISaveable Convert(ISaveable source) + { + try + { + Check(); + return GetNewAnalysis(source); + } + catch (Exception ex) + { + TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error); + TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error); + throw; + } + } + + private ISaveable GetNewAnalysis(ISaveable source) + { + ISaveable newItem; + if (source is ICrossSection crossSection) + { + newItem = ProcessCrossSection(crossSection); + } + else + { + string errorString = ErrorStrings.ObjectTypeIsUnknownObj(source); + TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error); + throw new StructureHelperException(errorString); + } + TraceLogger?.AddMessage($"Object of type <<{newItem.GetType()}>> was obtained", TraceLogStatuses.Service); + return newItem; + } + + private ICrossSection ProcessCrossSection(ICrossSection source) + { + TraceLogger?.AddMessage(AnalysisIs + " Cross-Section", TraceLogStatuses.Service); + TraceLogger?.AddMessage("Cross-Section converting is started", TraceLogStatuses.Service); + crossSectionConvertStrategy.ReferenceDictionary = ReferenceDictionary; + crossSectionConvertStrategy.TraceLogger = TraceLogger; + var convertLogic = new DictionaryConvertStrategy(this, crossSectionConvertStrategy); + ICrossSection newItem = convertLogic.Convert(source); + TraceLogger?.AddMessage("Cross-Section converting has been finished succesfully", TraceLogStatuses.Service); + return newItem; + } + + private void Check() + { + var checkLogic = new CheckConvertLogic(this); + checkLogic.Check(); + } + } +} diff --git a/DataAccess/DTOs/Converters/VersionItemToDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/VersionItemToDTOConvertStrategy.cs index 4b42376..cad4a30 100644 --- a/DataAccess/DTOs/Converters/VersionItemToDTOConvertStrategy.cs +++ b/DataAccess/DTOs/Converters/VersionItemToDTOConvertStrategy.cs @@ -1,6 +1,7 @@ using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Models; +using StructureHelperCommon.Models.Loggers; using StructureHelperLogics.Models.CrossSections; using System; using System.Collections.Generic; @@ -13,7 +14,7 @@ namespace DataAccess.DTOs { public class VersionItemToDTOConvertStrategy : IConvertStrategy { - private const string Message = "Analysis type is"; + private const string AnalysisIs = "Analysis type is"; private IConvertStrategy crossSectionConvertStrategy = new CrossSectionToDTOConvertStrategy(); public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } public IShiftTraceLogger TraceLogger { get; set; } @@ -21,11 +22,25 @@ namespace DataAccess.DTOs public ISaveable Convert(ISaveable source) { - Check(); - ISaveable saveable; + try + { + Check(); + return GetNewAnalysis(source); + } + catch (Exception ex) + { + TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error); + TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error); + throw; + } + } + + private ISaveable GetNewAnalysis(ISaveable source) + { + ISaveable newItem; if (source is ICrossSection crossSection) { - saveable = ProcessCrossSection(crossSection); + newItem = ProcessCrossSection(crossSection); } else { @@ -33,12 +48,12 @@ namespace DataAccess.DTOs TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error); throw new StructureHelperException(errorString); } - return saveable; + return newItem; } private ISaveable ProcessCrossSection(ICrossSection crossSection) { - TraceLogger?.AddMessage(Message + " Cross-Section Ndm Analysis", TraceLogStatuses.Debug); + TraceLogger?.AddMessage(AnalysisIs + " Cross-Section Ndm Analysis", TraceLogStatuses.Debug); ISaveable saveable; crossSectionConvertStrategy.ReferenceDictionary = ReferenceDictionary; crossSectionConvertStrategy.TraceLogger = TraceLogger; @@ -54,9 +69,7 @@ namespace DataAccess.DTOs private void Check() { - var checkLogic = new CheckConvertLogic(); - checkLogic.ConvertStrategy = this; - checkLogic.TraceLogger = TraceLogger; + var checkLogic = new CheckConvertLogic(this); checkLogic.Check(); } } diff --git a/DataAccess/DTOs/Converters/VersionProcessorFromDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/VersionProcessorFromDTOConvertStrategy.cs new file mode 100644 index 0000000..c03fbec --- /dev/null +++ b/DataAccess/DTOs/Converters/VersionProcessorFromDTOConvertStrategy.cs @@ -0,0 +1,72 @@ +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models; +using StructureHelperCommon.Models.Analyses; +using StructureHelperCommon.Models.Loggers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class VersionProcessorFromDTOConvertStrategy : IConvertStrategy + { + private IConvertStrategy dateVersionConvertStrategy; + private ICheckConvertLogic checkLogic; + + public VersionProcessorFromDTOConvertStrategy( + IConvertStrategy dateVersionConvertStrategy) + { + this.dateVersionConvertStrategy = dateVersionConvertStrategy; + this.checkLogic = checkLogic; + } + + public VersionProcessorFromDTOConvertStrategy() : this(new DateVersionFromDTOConvertStrategy()) + { + + } + + public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } + public IShiftTraceLogger TraceLogger { get; set; } + + public IVersionProcessor Convert(IVersionProcessor source) + { + try + { + Check(); + IVersionProcessor versionProcessor = GetVersionProcessor(source); + return versionProcessor; + } + catch (Exception ex) + { + TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error); + TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error); + throw; + } + } + + private IVersionProcessor GetVersionProcessor(IVersionProcessor source) + { + TraceLogger?.AddMessage("Version processor converting is started", TraceLogStatuses.Debug); + IVersionProcessor newItem = new VersionProcessor(source.Id); + TraceLogger?.AddMessage($"Source version processor has {source.Versions.Count} version(s)", TraceLogStatuses.Service); + dateVersionConvertStrategy.ReferenceDictionary = ReferenceDictionary; + dateVersionConvertStrategy.TraceLogger = TraceLogger; + foreach (var item in source.Versions) + { + IDateVersion dateVersion = dateVersionConvertStrategy.Convert(item); + newItem.Versions.Add(dateVersion); + } + TraceLogger?.AddMessage($"Totaly {newItem.Versions.Count} version(s) was(were) obtained", TraceLogStatuses.Service); + TraceLogger?.AddMessage("Version processor has been converted succesfully", TraceLogStatuses.Service); + return newItem; + } + + private void Check() + { + var checkLogic = new CheckConvertLogic(this); + checkLogic.Check(); + } + } +} diff --git a/DataAccess/DTOs/DTOEntities/FRMaterialDTO.cs b/DataAccess/DTOs/DTOEntities/FRMaterialDTO.cs index c061b79..8856a56 100644 --- a/DataAccess/DTOs/DTOEntities/FRMaterialDTO.cs +++ b/DataAccess/DTOs/DTOEntities/FRMaterialDTO.cs @@ -15,6 +15,8 @@ namespace DataAccess.DTOs { [JsonProperty("Id")] public Guid Id { get; set; } + [JsonProperty("MaterialType")] + public MaterialTypes MaterialType { get; set; } = MaterialTypes.CarbonFiber; [JsonProperty("ULSConcreteStrength")] public double ULSConcreteStrength { get; set; } [JsonProperty("SunThickness")] diff --git a/StructureHelper/Documentation/Manuals/Руководство пользователя.docx b/StructureHelper/Documentation/Manuals/Руководство пользователя.docx index dd88887..ead914c 100644 Binary files a/StructureHelper/Documentation/Manuals/Руководство пользователя.docx and b/StructureHelper/Documentation/Manuals/Руководство пользователя.docx differ diff --git a/StructureHelper/Documentation/Manuals/Руководство пользователя.pdf b/StructureHelper/Documentation/Manuals/Руководство пользователя.pdf index 1a6af0c..0c762e0 100644 Binary files a/StructureHelper/Documentation/Manuals/Руководство пользователя.pdf and b/StructureHelper/Documentation/Manuals/Руководство пользователя.pdf differ diff --git a/StructureHelper/Services/Settings/GlobalRepository.cs b/StructureHelper/Services/Settings/GlobalRepository.cs deleted file mode 100644 index e0ef821..0000000 --- a/StructureHelper/Services/Settings/GlobalRepository.cs +++ /dev/null @@ -1,36 +0,0 @@ -using StructureHelper.Models.Materials; -using StructureHelperCommon.Infrastructures.Interfaces; -using StructureHelperCommon.Models.Forces; -using StructureHelperCommon.Models.Repositories; -using StructureHelperLogics.Models.Materials; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace StructureHelper.Services.Settings -{ - internal static class GlobalRepository - { - private static IDataRepository materials; - private static IDataRepository actions; - - public static IDataRepository Materials - { - get - { - materials ??= new ListRepository(new HeadMaterialUpdateStrategy()); - return materials; - } - } - public static IDataRepository Actions - { - get - { - actions ??= new ListRepository(new ActionUpdateStrategy()); - return actions; - } - } - } -} diff --git a/StructureHelper/StructureHelper.csproj b/StructureHelper/StructureHelper.csproj index 1a0483e..dd1b343 100644 --- a/StructureHelper/StructureHelper.csproj +++ b/StructureHelper/StructureHelper.csproj @@ -86,6 +86,7 @@ + diff --git a/StructureHelper/Windows/MainWindow/CrossSectionViewModel.cs b/StructureHelper/Windows/MainWindow/CrossSectionViewModel.cs index a166ab5..8dd59a9 100644 --- a/StructureHelper/Windows/MainWindow/CrossSectionViewModel.cs +++ b/StructureHelper/Windows/MainWindow/CrossSectionViewModel.cs @@ -2,7 +2,6 @@ using StructureHelper.Infrastructure; using StructureHelper.Infrastructure.UI.DataContexts; using StructureHelper.Models.Materials; -using StructureHelper.Services.Settings; using StructureHelper.Windows.PrimitiveTemplates.RCs.Beams; using StructureHelper.Windows.PrimitiveTemplates.RCs.RectangleBeam; using StructureHelper.Windows.ViewModels; @@ -15,7 +14,6 @@ using StructureHelperLogics.Models.CrossSections; using StructureHelperLogics.Models.Templates.CrossSections.RCs; using StructureHelperLogics.Models.Templates.RCs; using StructureHelperLogics.Services.NdmPrimitives; -using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; @@ -290,14 +288,14 @@ namespace StructureHelper.Windows.MainWindow CalculatorsLogic.AddItems(newRepository.Calculators); var primitives = PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(newRepository.Primitives); PrimitiveLogic.Refresh(); - foreach (var item in newRepository.HeadMaterials) - { - GlobalRepository.Materials.Create(item); - } - foreach (var item in newRepository.ForceActions) - { - GlobalRepository.Actions.Create(item); - } + //foreach (var item in newRepository.HeadMaterials) + //{ + // GlobalRepository.Materials.Create(item); + //} + //foreach (var item in newRepository.ForceActions) + //{ + // GlobalRepository.Actions.Create(item); + //} return primitives; } diff --git a/StructureHelper/Windows/ViewModels/Forces/ActionsViewModel.cs b/StructureHelper/Windows/ViewModels/Forces/ActionsViewModel.cs index 8f623d4..670bdcc 100644 --- a/StructureHelper/Windows/ViewModels/Forces/ActionsViewModel.cs +++ b/StructureHelper/Windows/ViewModels/Forces/ActionsViewModel.cs @@ -1,5 +1,4 @@ using StructureHelper.Infrastructure.Enums; -using StructureHelper.Services.Settings; using StructureHelper.Windows.Forces; using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Infrastructures.Interfaces; @@ -31,7 +30,7 @@ namespace StructureHelper.Windows.ViewModels.Forces NewItem = new ForceCombinationByFactor() { Name = "New Factored Combination" }; } else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $": Actual type: {nameof(paramType)}"); - GlobalRepository.Actions.Create(NewItem); + //GlobalRepository.Actions.Create(NewItem); base.AddMethod(parameter); } } @@ -42,7 +41,7 @@ namespace StructureHelper.Windows.ViewModels.Forces if (dialogResult == DialogResult.Yes) { if (DeleteAction() != true) return; - GlobalRepository.Actions.Delete(SelectedItem.Id); + //GlobalRepository.Actions.Delete(SelectedItem.Id); base.DeleteMethod(parameter); } } @@ -51,7 +50,7 @@ namespace StructureHelper.Windows.ViewModels.Forces { NewItem = SelectedItem.Clone() as IForceAction; NewItem.Name = $"{NewItem.Name} copy"; - GlobalRepository.Actions.Create(NewItem); + //GlobalRepository.Actions.Create(NewItem); Collection.Add(NewItem); Items.Add(NewItem); SelectedItem = NewItem; @@ -59,7 +58,8 @@ namespace StructureHelper.Windows.ViewModels.Forces public override void EditMethod(object parameter) { - var copyObject = GlobalRepository.Actions.GetById(SelectedItem.Id).Clone() as IAction; + //var copyObject = GlobalRepository.Actions.GetById(SelectedItem.Id).Clone() as IAction; + var copyObject = SelectedItem.Clone() as IAction; System.Windows.Window wnd; if (SelectedItem is IForceCombinationList) { @@ -75,7 +75,7 @@ namespace StructureHelper.Windows.ViewModels.Forces wnd.ShowDialog(); if (wnd.DialogResult == true) { - GlobalRepository.Actions.Update(SelectedItem); + //GlobalRepository.Actions.Update(SelectedItem); } else { diff --git a/StructureHelper/Windows/ViewModels/Materials/MaterialsViewModel.cs b/StructureHelper/Windows/ViewModels/Materials/MaterialsViewModel.cs index 1e4bb33..dbe54ff 100644 --- a/StructureHelper/Windows/ViewModels/Materials/MaterialsViewModel.cs +++ b/StructureHelper/Windows/ViewModels/Materials/MaterialsViewModel.cs @@ -1,7 +1,6 @@ using StructureHelper.Infrastructure; using StructureHelper.Infrastructure.Enums; using StructureHelper.Models.Materials; -using StructureHelper.Services.Settings; using StructureHelper.Windows.MainWindow.Materials; using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperLogics.Models.CrossSections; @@ -42,7 +41,7 @@ namespace StructureHelper.Windows.ViewModels.Materials else if (parameterType == MaterialType.CarbonFiber) { AddCarbonFiber(); } else if (parameterType == MaterialType.GlassFiber) { AddGlassFiber(); } else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $". Expected: {typeof(MaterialType)}, Actual type: {nameof(parameterType)}"); - GlobalRepository.Materials.Create(NewItem); + //GlobalRepository.Materials.Create(NewItem); base.AddMethod(parameter); } public override void DeleteMethod(object parameter) @@ -58,18 +57,19 @@ namespace StructureHelper.Windows.ViewModels.Materials var dialogResult = MessageBox.Show("Delete material?", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { - GlobalRepository.Materials.Delete(SelectedItem.Id); + //GlobalRepository.Materials.Delete(SelectedItem.Id); base.DeleteMethod(parameter); } } public override void EditMethod(object parameter) { - var copyObject = GlobalRepository.Materials.GetById(SelectedItem.Id).Clone() as IHeadMaterial; + //var copyObject = GlobalRepository.Materials.GetById(SelectedItem.Id).Clone() as IHeadMaterial; + var copyObject = SelectedItem.Clone() as IHeadMaterial; var wnd = new HeadMaterialView(SelectedItem); wnd.ShowDialog(); if (wnd.DialogResult == true) { - GlobalRepository.Materials.Update(SelectedItem); + // } else { @@ -82,7 +82,6 @@ namespace StructureHelper.Windows.ViewModels.Materials { NewItem = SelectedItem.Clone() as IHeadMaterial; NewItem.Name = $"{NewItem.Name} copy"; - GlobalRepository.Materials.Create(NewItem); Collection.Add(NewItem); Items.Add(NewItem); SelectedItem = NewItem; diff --git a/StructureHelper/Windows/ViewModels/NdmCrossSections/PrimitiveViewModelLogic.cs b/StructureHelper/Windows/ViewModels/NdmCrossSections/PrimitiveViewModelLogic.cs index 989d5b7..9eebd09 100644 --- a/StructureHelper/Windows/ViewModels/NdmCrossSections/PrimitiveViewModelLogic.cs +++ b/StructureHelper/Windows/ViewModels/NdmCrossSections/PrimitiveViewModelLogic.cs @@ -1,20 +1,13 @@ using StructureHelper.Infrastructure; using StructureHelper.Infrastructure.Enums; using StructureHelper.Infrastructure.UI.DataContexts; -using StructureHelper.Services.Settings; using StructureHelper.Windows.PrimitiveProperiesWindow; -using StructureHelper.Windows.PrimitiveTemplates.RCs.Beams; -using StructureHelper.Windows.PrimitiveTemplates.RCs.RectangleBeam; using StructureHelper.Windows.Services; using StructureHelperCommon.Infrastructures.Exceptions; -using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Models.Calculators; -using StructureHelperCommon.Models.Materials; using StructureHelperCommon.Models.Shapes; using StructureHelperLogics.Models.CrossSections; using StructureHelperLogics.Models.Primitives; -using StructureHelperLogics.Models.Templates.CrossSections.RCs; -using StructureHelperLogics.Models.Templates.RCs; using StructureHelperLogics.NdmCalculations.Analyses.ByForces; using StructureHelperLogics.NdmCalculations.Cracking; using StructureHelperLogics.NdmCalculations.Primitives; @@ -25,7 +18,7 @@ using System.Linq; using System.Windows.Forms; using System.Windows.Input; -//Copyright (c) 2023 Redikultsev Evgeny, Ekaterinburg, Russia +//Copyright (c) 2024 Redikultsev Evgeny, Ekaterinburg, Russia //All rights reserved. namespace StructureHelper.Windows.ViewModels.NdmCrossSections diff --git a/StructureHelperCommon/Infrastructures/Enums/MaterialTypes.cs b/StructureHelperCommon/Infrastructures/Enums/MaterialTypes.cs index de81fbe..9386b85 100644 --- a/StructureHelperCommon/Infrastructures/Enums/MaterialTypes.cs +++ b/StructureHelperCommon/Infrastructures/Enums/MaterialTypes.cs @@ -3,10 +3,10 @@ { public enum MaterialTypes { - Concrete, - Reinforcement, - //Steel, - CarbonFiber, - GlassFiber, + Concrete = 0, + Reinforcement = 1, + Steel = 3, + CarbonFiber = 4, + GlassFiber = 5, } } diff --git a/StructureHelperCommon/Infrastructures/Interfaces/ConvertStrategy.cs b/StructureHelperCommon/Infrastructures/Interfaces/ConvertStrategy.cs new file mode 100644 index 0000000..b4dd482 --- /dev/null +++ b/StructureHelperCommon/Infrastructures/Interfaces/ConvertStrategy.cs @@ -0,0 +1,40 @@ +using StructureHelperCommon.Models; +using StructureHelperCommon.Models.Loggers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperCommon.Infrastructures.Interfaces +{ + public abstract class ConvertStrategy : IConvertStrategy + where T : ISaveable + where V : ISaveable + { + public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } + public IShiftTraceLogger TraceLogger { get; set; } + + public virtual T Convert(V source) + { + try + { + Check(); + return GetNewItem(source); + } + catch (Exception ex) + { + TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error); + TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error); + throw; + } + } + + public abstract T GetNewItem(V source); + private void Check() + { + var checkLogic = new CheckConvertLogic(this); + checkLogic.Check(); + } + } +} diff --git a/StructureHelperCommon/Infrastructures/Interfaces/DictionaryConvertStrategy.cs b/StructureHelperCommon/Infrastructures/Interfaces/DictionaryConvertStrategy.cs index ddc95df..b6b4a53 100644 --- a/StructureHelperCommon/Infrastructures/Interfaces/DictionaryConvertStrategy.cs +++ b/StructureHelperCommon/Infrastructures/Interfaces/DictionaryConvertStrategy.cs @@ -10,6 +10,11 @@ using System.Windows.Media; namespace StructureHelperCommon.Infrastructures.Interfaces { + /// + /// Find object in refernce dictionary, if it exists return existing object, else return new one by child logic + /// + /// Type of target object + /// Type of source object public class DictionaryConvertStrategy : IConvertStrategy where T : ISaveable where V : ISaveable diff --git a/StructureHelperCommon/Infrastructures/Interfaces/IConvertStrategy.cs b/StructureHelperCommon/Infrastructures/Interfaces/IConvertStrategy.cs index d3adaa9..ce7a940 100644 --- a/StructureHelperCommon/Infrastructures/Interfaces/IConvertStrategy.cs +++ b/StructureHelperCommon/Infrastructures/Interfaces/IConvertStrategy.cs @@ -7,10 +7,20 @@ using System.Threading.Tasks; namespace StructureHelperCommon.Infrastructures.Interfaces { + /// + /// Converts object of type of ISaveable to another one + /// + /// Target object type + /// Source object type public interface IConvertStrategy : IBaseConvertStrategy where T :ISaveable where V :ISaveable { + /// + /// Converts object to another one + /// + /// Source object + /// Converted object T Convert(V source); } } diff --git a/StructureHelperCommon/Infrastructures/Settings/GlobalRepository.cs b/StructureHelperCommon/Infrastructures/Settings/GlobalRepository.cs new file mode 100644 index 0000000..a569044 --- /dev/null +++ b/StructureHelperCommon/Infrastructures/Settings/GlobalRepository.cs @@ -0,0 +1,30 @@ +using StructureHelper.Models.Materials; +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models.Forces; +using StructureHelperCommon.Models.Repositories; + +namespace StructureHelperCommon.Infrastructures.Settings +{ + internal static class GlobalRepository + { + private static IDataRepository materials; + private static IDataRepository actions; + + //public static IDataRepository Materials + //{ + // get + // { + // materials ??= new ListRepository(new HeadMaterialUpdateStrategy()); + // return materials; + // } + //} + //public static IDataRepository Actions + //{ + // get + // { + // actions ??= new ListRepository(new ActionUpdateStrategy()); + // return actions; + // } + //} + } +} diff --git a/StructureHelperCommon/Models/Analyses/IAnalysis.cs b/StructureHelperCommon/Models/Analyses/IAnalysis.cs index db475f6..eee4d36 100644 --- a/StructureHelperCommon/Models/Analyses/IAnalysis.cs +++ b/StructureHelperCommon/Models/Analyses/IAnalysis.cs @@ -11,6 +11,6 @@ namespace StructureHelperCommon.Models.Analyses { string Name { get; set; } string Tags { get; set; } - IVersionProcessor VersionProcessor { get;} + IVersionProcessor VersionProcessor { get; set; } } } diff --git a/StructureHelperCommon/Models/Forces/ForceCombinationByFactor.cs b/StructureHelperCommon/Models/Forces/ForceCombinationByFactor.cs index 300acbd..c9a2745 100644 --- a/StructureHelperCommon/Models/Forces/ForceCombinationByFactor.cs +++ b/StructureHelperCommon/Models/Forces/ForceCombinationByFactor.cs @@ -22,7 +22,7 @@ namespace StructureHelperCommon.Models.Forces /// public IPoint2D ForcePoint { get; set; } /// - public IForceTuple FullSLSForces { get; private set; } + public IForceTuple FullSLSForces { get; set; } /// public double ULSFactor { get; set; } /// diff --git a/StructureHelperCommon/Models/Forces/ForceCombinationList.cs b/StructureHelperCommon/Models/Forces/ForceCombinationList.cs index 04a0dca..7b6bff8 100644 --- a/StructureHelperCommon/Models/Forces/ForceCombinationList.cs +++ b/StructureHelperCommon/Models/Forces/ForceCombinationList.cs @@ -22,7 +22,7 @@ namespace StructureHelperCommon.Models.Forces /// public IPoint2D ForcePoint { get; set; } /// - public List DesignForces { get; private set; } + public List DesignForces { get; set; } public ForceCombinationList(Guid id) diff --git a/StructureHelperCommon/Models/Forces/IForceCombinationByFactor.cs b/StructureHelperCommon/Models/Forces/IForceCombinationByFactor.cs index 3c0edcd..828c461 100644 --- a/StructureHelperCommon/Models/Forces/IForceCombinationByFactor.cs +++ b/StructureHelperCommon/Models/Forces/IForceCombinationByFactor.cs @@ -9,7 +9,7 @@ namespace StructureHelperCommon.Models.Forces { public interface IForceCombinationByFactor : IForceAction { - IForceTuple FullSLSForces { get; } + IForceTuple FullSLSForces { get; set; } double ULSFactor { get; set; } double LongTermFactor { get; set; } } diff --git a/StructureHelperCommon/Models/Forces/IForceCombinationList.cs b/StructureHelperCommon/Models/Forces/IForceCombinationList.cs index 24715eb..0f42630 100644 --- a/StructureHelperCommon/Models/Forces/IForceCombinationList.cs +++ b/StructureHelperCommon/Models/Forces/IForceCombinationList.cs @@ -6,6 +6,6 @@ namespace StructureHelperCommon.Models.Forces { public interface IForceCombinationList : IForceAction { - List DesignForces { get;} + List DesignForces { get; set; } } } diff --git a/StructureHelperCommon/Models/Materials/IHasSafetyFactors.cs b/StructureHelperCommon/Models/Materials/IHasSafetyFactors.cs new file mode 100644 index 0000000..de280ba --- /dev/null +++ b/StructureHelperCommon/Models/Materials/IHasSafetyFactors.cs @@ -0,0 +1,10 @@ +using StructureHelperCommon.Models.Materials.Libraries; +using System.Collections.Generic; + +namespace StructureHelperLogics.Models.Materials +{ + public interface IHasSafetyFactors + { + List SafetyFactors { get; set; } + } +} \ No newline at end of file diff --git a/StructureHelperLogics/Models/Materials/IHeadMaterial.cs b/StructureHelperCommon/Models/Materials/IHeadMaterial.cs similarity index 97% rename from StructureHelperLogics/Models/Materials/IHeadMaterial.cs rename to StructureHelperCommon/Models/Materials/IHeadMaterial.cs index 6701d05..af722d0 100644 --- a/StructureHelperLogics/Models/Materials/IHeadMaterial.cs +++ b/StructureHelperCommon/Models/Materials/IHeadMaterial.cs @@ -2,6 +2,7 @@ using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperLogics.Models.Materials; +using System; using System.Windows.Media; namespace StructureHelper.Models.Materials diff --git a/StructureHelperLogics/Models/Materials/IHelperMaterial.cs b/StructureHelperCommon/Models/Materials/IHelperMaterial.cs similarity index 81% rename from StructureHelperLogics/Models/Materials/IHelperMaterial.cs rename to StructureHelperCommon/Models/Materials/IHelperMaterial.cs index e82cf06..e1f0563 100644 --- a/StructureHelperLogics/Models/Materials/IHelperMaterial.cs +++ b/StructureHelperCommon/Models/Materials/IHelperMaterial.cs @@ -9,10 +9,9 @@ using System.Text; namespace StructureHelperLogics.Models.Materials { - public interface IHelperMaterial : ISaveable, ICloneable + public interface IHelperMaterial : ISaveable, ICloneable, IHasSafetyFactors { IMaterial GetLoaderMaterial(LimitStates limitState, CalcTerms calcTerm); IMaterial GetCrackedLoaderMaterial(LimitStates limitState, CalcTerms calcTerm); - List SafetyFactors { get; set; } } } diff --git a/StructureHelperLogics/Models/Materials/ILibMaterial.cs b/StructureHelperCommon/Models/Materials/ILibMaterial.cs similarity index 100% rename from StructureHelperLogics/Models/Materials/ILibMaterial.cs rename to StructureHelperCommon/Models/Materials/ILibMaterial.cs diff --git a/StructureHelperCommon/Models/Materials/Libraries/Logics/MaterialSafetyFactorBaseUpdateStrategy.cs b/StructureHelperCommon/Models/Materials/Libraries/Logics/MaterialSafetyFactorBaseUpdateStrategy.cs new file mode 100644 index 0000000..e7328c6 --- /dev/null +++ b/StructureHelperCommon/Models/Materials/Libraries/Logics/MaterialSafetyFactorBaseUpdateStrategy.cs @@ -0,0 +1,23 @@ +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Services; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperCommon.Models.Materials.Libraries +{ + public class MaterialSafetyFactorBaseUpdateStrategy : IUpdateStrategy + { + public void Update(IMaterialSafetyFactor targetObject, IMaterialSafetyFactor sourceObject) + { + CheckObject.IsNull(sourceObject); + CheckObject.IsNull(targetObject); + if (ReferenceEquals(targetObject, sourceObject)) { return; } + targetObject.Name = sourceObject.Name; + targetObject.Take = sourceObject.Take; + targetObject.Description = sourceObject.Description; + } + } +} diff --git a/StructureHelperCommon/Models/Materials/Libraries/Logics/MaterialSafetyFactorUpdateStrategy.cs b/StructureHelperCommon/Models/Materials/Libraries/Logics/MaterialSafetyFactorUpdateStrategy.cs index 77ae6c3..69b27e8 100644 --- a/StructureHelperCommon/Models/Materials/Libraries/Logics/MaterialSafetyFactorUpdateStrategy.cs +++ b/StructureHelperCommon/Models/Materials/Libraries/Logics/MaterialSafetyFactorUpdateStrategy.cs @@ -10,14 +10,13 @@ namespace StructureHelperCommon.Models.Materials.Libraries { public class MaterialSafetyFactorUpdateStrategy : IUpdateStrategy { + private IUpdateStrategy baseUpdateStrategy = new MaterialSafetyFactorBaseUpdateStrategy(); public void Update(IMaterialSafetyFactor targetObject, IMaterialSafetyFactor sourceObject) { CheckObject.IsNull(sourceObject); CheckObject.IsNull(targetObject); if (ReferenceEquals(targetObject, sourceObject)) { return; } - targetObject.Name = sourceObject.Name; - targetObject.Take = sourceObject.Take; - targetObject.Description = sourceObject.Description; + baseUpdateStrategy.Update(targetObject, sourceObject); targetObject.PartialFactors.Clear(); foreach (var item in sourceObject.PartialFactors) { diff --git a/StructureHelperLogics/Models/Analyses/CrossSectionNdmAnalysis.cs b/StructureHelperLogics/Models/Analyses/CrossSectionNdmAnalysis.cs index 23bb058..7d65ed4 100644 --- a/StructureHelperLogics/Models/Analyses/CrossSectionNdmAnalysis.cs +++ b/StructureHelperLogics/Models/Analyses/CrossSectionNdmAnalysis.cs @@ -10,7 +10,7 @@ namespace StructureHelperLogic.Models.Analyses public Guid Id { get; private set; } public string Name { get; set; } public string Tags { get; set; } - public IVersionProcessor VersionProcessor { get; private set; } + public IVersionProcessor VersionProcessor { get; set; } public CrossSectionNdmAnalysis(Guid id, IVersionProcessor versionProcessor) { diff --git a/StructureHelperLogics/Models/CrossSections/CrossSection.cs b/StructureHelperLogics/Models/CrossSections/CrossSection.cs index 494de31..e32ed17 100644 --- a/StructureHelperLogics/Models/CrossSections/CrossSection.cs +++ b/StructureHelperLogics/Models/CrossSections/CrossSection.cs @@ -8,7 +8,7 @@ namespace StructureHelperLogics.Models.CrossSections { public class CrossSection : ICrossSection { - public ICrossSectionRepository SectionRepository { get; private set; } = new CrossSectionRepository(); + public ICrossSectionRepository SectionRepository { get; set; } = new CrossSectionRepository(); public Guid Id { get; private set; } diff --git a/StructureHelperLogics/Models/CrossSections/ICrossSection.cs b/StructureHelperLogics/Models/CrossSections/ICrossSection.cs index b06e613..7ff9c97 100644 --- a/StructureHelperLogics/Models/CrossSections/ICrossSection.cs +++ b/StructureHelperLogics/Models/CrossSections/ICrossSection.cs @@ -9,6 +9,6 @@ namespace StructureHelperLogics.Models.CrossSections { public interface ICrossSection : ISaveable, ICloneable { - ICrossSectionRepository SectionRepository { get; } + ICrossSectionRepository SectionRepository { get; set; } } } diff --git a/StructureHelperLogics/Models/Materials/FRMaterials/FRMaterial.cs b/StructureHelperLogics/Models/Materials/FRMaterials/FRMaterial.cs index 380b550..4ad45aa 100644 --- a/StructureHelperLogics/Models/Materials/FRMaterials/FRMaterial.cs +++ b/StructureHelperLogics/Models/Materials/FRMaterials/FRMaterial.cs @@ -1,5 +1,6 @@ using LoaderCalculator.Data.Materials; using StructureHelperCommon.Infrastructures.Enums; +using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Settings; using StructureHelperCommon.Models.Materials.Libraries; @@ -14,9 +15,9 @@ namespace StructureHelperLogics.Models.Materials public class FRMaterial : IFRMaterial { private IElasticMaterialLogic elasticMaterialLogic => new ElasticMaterialLogic(); - private MaterialTypes materialType; IUpdateStrategy updateStrategy = new FRUpdateStrategy(); public Guid Id { get; } + public MaterialTypes MaterialType { get; } public double Modulus{ get; set; } public double CompressiveStrength { get; set; } public double TensileStrength { get; set; } @@ -28,11 +29,16 @@ namespace StructureHelperLogics.Models.Materials public FRMaterial(MaterialTypes materialType, Guid id) { + if (materialType != MaterialTypes.CarbonFiber || + materialType != MaterialTypes.GlassFiber) + { + throw new StructureHelperException(ErrorStrings.DataIsInCorrect + $": Material type {materialType} is not right"); + } Id = id; ULSConcreteStrength = 14e6d; SumThickness = 0.175e-3d; - this.materialType = materialType; - SafetyFactors.AddRange(PartialCoefficientFactory.GetDefaultFRSafetyFactors(ProgramSetting.FRCodeType, this.materialType)); + MaterialType = materialType; + SafetyFactors.AddRange(PartialCoefficientFactory.GetDefaultFRSafetyFactors(ProgramSetting.FRCodeType, this.MaterialType)); } public FRMaterial(MaterialTypes materialType) : this (materialType, Guid.NewGuid()) @@ -42,7 +48,7 @@ namespace StructureHelperLogics.Models.Materials public object Clone() { - var newItem = new FRMaterial(this.materialType); + var newItem = new FRMaterial(this.MaterialType); updateStrategy.Update(newItem, this); return newItem; } diff --git a/StructureHelperLogics/Models/Materials/FRMaterials/IFRMaterial.cs b/StructureHelperLogics/Models/Materials/FRMaterials/IFRMaterial.cs index 1300b2d..b44a73e 100644 --- a/StructureHelperLogics/Models/Materials/FRMaterials/IFRMaterial.cs +++ b/StructureHelperLogics/Models/Materials/FRMaterials/IFRMaterial.cs @@ -1,4 +1,5 @@ -using StructureHelperCommon.Models.Materials.Libraries; +using StructureHelperCommon.Infrastructures.Enums; +using StructureHelperCommon.Models.Materials.Libraries; using System; using System.Collections.Generic; using System.Linq; @@ -9,6 +10,7 @@ namespace StructureHelperLogics.Models.Materials { public interface IFRMaterial : IElasticMaterial { + MaterialTypes MaterialType { get; } double ULSConcreteStrength { get; set; } double SumThickness { get; set; } double GammaF2 { get; } diff --git a/StructureHelperLogics/Models/Materials/HeadMaterialRepository.cs b/StructureHelperLogics/Models/Materials/HeadMaterialRepository.cs deleted file mode 100644 index 3afd932..0000000 --- a/StructureHelperLogics/Models/Materials/HeadMaterialRepository.cs +++ /dev/null @@ -1,32 +0,0 @@ -using StructureHelper.Models.Materials; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace StructureHelperLogics.Models.Materials -{ - public class HeadMaterialRepository : IHeadMaterialRepository - { - public object Parent { get; private set; } - - public List HeadMaterials { get; set; } - - public HeadMaterialRepository() - { - HeadMaterials = new List(); - } - - public HeadMaterialRepository(object parent) - { - Parent = parent; - HeadMaterials = new List(); - } - - public void RegisterParent(object obj) - { - Parent = obj; - } - } -} diff --git a/StructureHelperLogics/Models/Materials/IHasHeadMaterials.cs b/StructureHelperLogics/Models/Materials/IHasHeadMaterials.cs index 8a21667..2294791 100644 --- a/StructureHelperLogics/Models/Materials/IHasHeadMaterials.cs +++ b/StructureHelperLogics/Models/Materials/IHasHeadMaterials.cs @@ -9,6 +9,6 @@ namespace StructureHelperLogics.Models.Materials { public interface IHasHeadMaterials { - List HeadMaterials { get; } + List HeadMaterials { get;} } } diff --git a/StructureHelperLogics/Models/Materials/IHeadMaterialRepository.cs b/StructureHelperLogics/Models/Materials/IHeadMaterialRepository.cs deleted file mode 100644 index 5b16aca..0000000 --- a/StructureHelperLogics/Models/Materials/IHeadMaterialRepository.cs +++ /dev/null @@ -1,18 +0,0 @@ -using StructureHelper.Models.Materials; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Serialization; - -namespace StructureHelperLogics.Models.Materials -{ - public interface IHeadMaterialRepository - { - object Parent { get; } - List HeadMaterials { get; set; } - void RegisterParent(object obj); - - } -} diff --git a/StructureHelperLogics/Models/Materials/Logics/HeadMaterialBaseUpdateStrategy.cs b/StructureHelperLogics/Models/Materials/Logics/HeadMaterialBaseUpdateStrategy.cs new file mode 100644 index 0000000..6a69959 --- /dev/null +++ b/StructureHelperLogics/Models/Materials/Logics/HeadMaterialBaseUpdateStrategy.cs @@ -0,0 +1,23 @@ +using StructureHelper.Models.Materials; +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Services; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperLogics.Models.Materials +{ + public class HeadMaterialBaseUpdateStrategy : IUpdateStrategy + { + public void Update(IHeadMaterial targetObject, IHeadMaterial sourceObject) + { + CheckObject.IsNull(sourceObject); + CheckObject.IsNull(targetObject); + if (ReferenceEquals(targetObject, sourceObject)) { return; } + targetObject.Name = sourceObject.Name; + targetObject.Color = sourceObject.Color; + } + } +} diff --git a/StructureHelperLogics/Models/Materials/Logics/HeadMaterialUpdateStrategy.cs b/StructureHelperLogics/Models/Materials/Logics/HeadMaterialUpdateStrategy.cs index 53feb86..1964408 100644 --- a/StructureHelperLogics/Models/Materials/Logics/HeadMaterialUpdateStrategy.cs +++ b/StructureHelperLogics/Models/Materials/Logics/HeadMaterialUpdateStrategy.cs @@ -6,6 +6,7 @@ namespace StructureHelperLogics.Models.Materials { public class HeadMaterialUpdateStrategy : IUpdateStrategy { + private IUpdateStrategy updateStrategy = new HeadMaterialBaseUpdateStrategy(); private IUpdateStrategy helperMaterialUpdateStrategy; public HeadMaterialUpdateStrategy(IUpdateStrategy helperMaterialUpdateStrategy) @@ -19,8 +20,7 @@ namespace StructureHelperLogics.Models.Materials CheckObject.IsNull(sourceObject); CheckObject.IsNull(targetObject); if (ReferenceEquals(targetObject, sourceObject)) { return; } - targetObject.Name = sourceObject.Name; - targetObject.Color = sourceObject.Color; + updateStrategy.Update(targetObject, sourceObject); targetObject.HelperMaterial = sourceObject.HelperMaterial.Clone() as IHelperMaterial; helperMaterialUpdateStrategy.Update(targetObject.HelperMaterial, sourceObject.HelperMaterial); } diff --git a/StructureHelperTests/StructureHelperTests.csproj b/StructureHelperTests/StructureHelperTests.csproj index 2e75b34..4a6e9ce 100644 --- a/StructureHelperTests/StructureHelperTests.csproj +++ b/StructureHelperTests/StructureHelperTests.csproj @@ -32,6 +32,7 @@ + diff --git a/StructureHelperTests/UnitTests/UpdateStrategiesTests/ConcreteLibUpdateStrategyTests.cs b/StructureHelperTests/UnitTests/UpdateStrategiesTests/ConcreteLibUpdateStrategyTests.cs index 619aeca..10082b0 100644 --- a/StructureHelperTests/UnitTests/UpdateStrategiesTests/ConcreteLibUpdateStrategyTests.cs +++ b/StructureHelperTests/UnitTests/UpdateStrategiesTests/ConcreteLibUpdateStrategyTests.cs @@ -60,17 +60,6 @@ namespace StructureHelperTests.UnitTests.UpdateStrategiesTests targetMock.VerifySet(t => t.TensionForSLS = It.IsAny(), Times.Never); targetMock.VerifySet(t => t.RelativeHumidity = It.IsAny(), Times.Never); } - - [Test] - public void Update_ShouldThrowStructureHelperException_WhenObjectsAreOfDifferentTypes() - { - // Arrange - var targetMock = new Mock(); - var sourceMock = new Mock(); - - // Act & Assert - Assert.Throws(() => strategy.Update(targetMock.Object, sourceMock.Object)); - } } } diff --git a/StructureHelperTests/UnitTests/UpdateStrategiesTests/LibMaterialUpdateStrategyTests.cs b/StructureHelperTests/UnitTests/UpdateStrategiesTests/LibMaterialUpdateStrategyTests.cs index 1019f67..87dcc28 100644 --- a/StructureHelperTests/UnitTests/UpdateStrategiesTests/LibMaterialUpdateStrategyTests.cs +++ b/StructureHelperTests/UnitTests/UpdateStrategiesTests/LibMaterialUpdateStrategyTests.cs @@ -27,17 +27,6 @@ namespace StructureHelperTests.UnitTests.UpdateStrategiesTests mockTargetMaterial.Setup(t => t.SafetyFactors).Returns(targetSafetyFactors); } - [Test] - public void Update_ShouldThrowException_WhenTargetAndSourceAreDifferentTypes() - { - // Arrange - var mockTarget1 = new ConcreteLibMaterial(); - var mockTarget2 = new ReinforcementLibMaterial(); - - // Act & Assert - Assert.Throws(() => updateStrategy.Update(mockTarget1, mockTarget2)); - } - [Test] public void Update_ShouldCopyMaterialEntityAndMaterialLogic() {