diff --git a/DataAccess/DTOs/Converters/ConcreteLibMaterialToDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/ConcreteLibMaterialToDTOConvertStrategy.cs index 4445907..2f66a14 100644 --- a/DataAccess/DTOs/Converters/ConcreteLibMaterialToDTOConvertStrategy.cs +++ b/DataAccess/DTOs/Converters/ConcreteLibMaterialToDTOConvertStrategy.cs @@ -1,7 +1,4 @@ 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; @@ -9,43 +6,19 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace DataAccess.DTOs.Converters +namespace DataAccess.DTOs { - public class ConcreteLibMaterialToDTOConvertStrategy : IConvertStrategy + public class ConcreteLibMaterialToDTOConvertStrategy : LibMaterialToDTOConvertStrategy { - private IUpdateStrategy updateStrategy = new ConcreteLibUpdateStrategy(); - private IUpdateStrategy libMaterialUpdateStrategy = new LibMaterialDTOUpdateStrategy(); - public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } - public IShiftTraceLogger TraceLogger { get; set; } + public override IUpdateStrategy UpdateStrategy { get; } = new ConcreteLibUpdateStrategy(); - public ConcreteLibMaterialDTO Convert(IConcreteLibMaterial source) + public override ConcreteLibMaterialDTO GetMaterialDTO(IConcreteLibMaterial source) { - Check(); ConcreteLibMaterialDTO newItem = new() { Id = source.Id }; - try - { - updateStrategy.Update(newItem, source); - libMaterialUpdateStrategy.Update(newItem, source); - } - catch (Exception ex) - { - TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Debug); - TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error); - throw; - } return newItem; } - - private void Check() - { - var checkLogic = new CheckConvertLogic(); - checkLogic.ConvertStrategy = this; - checkLogic.TraceLogger = TraceLogger; - checkLogic.Check(); - } - } } diff --git a/DataAccess/DTOs/Converters/HelperMaterialToDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/HelperMaterialToDTOConvertStrategy.cs index 74efe81..270392e 100644 --- a/DataAccess/DTOs/Converters/HelperMaterialToDTOConvertStrategy.cs +++ b/DataAccess/DTOs/Converters/HelperMaterialToDTOConvertStrategy.cs @@ -9,21 +9,26 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace DataAccess.DTOs.Converters +namespace DataAccess.DTOs { internal class HelperMaterialToDTOConvertStrategy : IConvertStrategy { - private IConvertStrategy concreteConvertStrategy; + private LibMaterialToDTOConvertStrategy concreteConvertStrategy; + private LibMaterialToDTOConvertStrategy reinforcementConvertStrategy; public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } public IShiftTraceLogger TraceLogger { get; set; } public HelperMaterialToDTOConvertStrategy( - IConvertStrategy concreteConvertStrategy) + LibMaterialToDTOConvertStrategy concreteConvertStrategy, + LibMaterialToDTOConvertStrategy reinforcementConvertStrategy) { this.concreteConvertStrategy = concreteConvertStrategy; + this.reinforcementConvertStrategy = reinforcementConvertStrategy; } - public HelperMaterialToDTOConvertStrategy() : this (new ConcreteLibMaterialToDTOConvertStrategy()) + public HelperMaterialToDTOConvertStrategy() : this ( + new ConcreteLibMaterialToDTOConvertStrategy(), + new ReinforcementLibMaterialToDTOConvertStrategy()) { } @@ -39,7 +44,9 @@ namespace DataAccess.DTOs.Converters } if (source is IReinforcementLibMaterial reinforcementMaterial) { - return source; + reinforcementConvertStrategy.ReferenceDictionary = ReferenceDictionary; + reinforcementConvertStrategy.TraceLogger = TraceLogger; + return reinforcementConvertStrategy.Convert(reinforcementMaterial); } else { diff --git a/DataAccess/DTOs/Converters/LibMaterialDTOUpdateStrategy.cs b/DataAccess/DTOs/Converters/LibMaterialDTOUpdateStrategy.cs index 9962149..5270ac7 100644 --- a/DataAccess/DTOs/Converters/LibMaterialDTOUpdateStrategy.cs +++ b/DataAccess/DTOs/Converters/LibMaterialDTOUpdateStrategy.cs @@ -8,7 +8,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace DataAccess.DTOs.Converters +namespace DataAccess.DTOs { public class LibMaterialDTOUpdateStrategy : IUpdateStrategy { @@ -28,6 +28,7 @@ namespace DataAccess.DTOs.Converters } + /// public void Update(ILibMaterial targetObject, ILibMaterial sourceObject) { CheckObject.IsNull(sourceObject); @@ -38,18 +39,37 @@ namespace DataAccess.DTOs.Converters targetObject.SafetyFactors.Clear(); foreach (var safetyFactor in sourceObject.SafetyFactors) { - MaterialSafetyFactorDTO newSafetyFactor = new() { Id = safetyFactor.Id}; - safetyFactorUpdateStrategy.Update(newSafetyFactor, safetyFactor); - newSafetyFactor.PartialFactors.Clear(); - foreach (var partialFactor in safetyFactor.PartialFactors) - { - MaterialPartialFactorDTO newPartialFactor = new() { Id = partialFactor.Id }; - partialFactorUpdateStrategy.Update(newPartialFactor, partialFactor); - newSafetyFactor.PartialFactors.Add(newPartialFactor); - } + MaterialSafetyFactorDTO newSafetyFactor = GetNewSafetyFactorByOld(safetyFactor); targetObject.SafetyFactors.Add(newSafetyFactor); } } } + + private MaterialSafetyFactorDTO GetNewSafetyFactorByOld(IMaterialSafetyFactor safetyFactor) + { + MaterialSafetyFactorDTO newSafetyFactor = new() + { + Id = safetyFactor.Id + }; + safetyFactorUpdateStrategy.Update(newSafetyFactor, safetyFactor); + newSafetyFactor.PartialFactors.Clear(); + foreach (var partialFactor in safetyFactor.PartialFactors) + { + MaterialPartialFactorDTO newPartialFactor = GetNewPartialFactorByOld(partialFactor); + newSafetyFactor.PartialFactors.Add(newPartialFactor); + } + + return newSafetyFactor; + } + + private MaterialPartialFactorDTO GetNewPartialFactorByOld(IMaterialPartialFactor partialFactor) + { + MaterialPartialFactorDTO newPartialFactor = new() + { + Id = partialFactor.Id + }; + partialFactorUpdateStrategy.Update(newPartialFactor, partialFactor); + return newPartialFactor; + } } } diff --git a/DataAccess/DTOs/Converters/LibMaterialToDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/LibMaterialToDTOConvertStrategy.cs new file mode 100644 index 0000000..ff160d3 --- /dev/null +++ b/DataAccess/DTOs/Converters/LibMaterialToDTOConvertStrategy.cs @@ -0,0 +1,53 @@ +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.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public abstract class LibMaterialToDTOConvertStrategy : IConvertStrategy + where T : V + where V : ILibMaterial + { + public abstract IUpdateStrategy UpdateStrategy { get; } + public abstract T GetMaterialDTO(V source); + private IUpdateStrategy libMaterialUpdateStrategy = new LibMaterialDTOUpdateStrategy(); + public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } + public IShiftTraceLogger TraceLogger { get; set; } + + public T Convert(V source) + { + Check(); + T newItem = GetMaterialDTO(source); + try + { + UpdateStrategy.Update(newItem, source); + libMaterialUpdateStrategy.Update(newItem, source); + } + catch (Exception ex) + { + TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Debug); + TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error); + throw; + } + return newItem; + } + + + private void Check() + { + var checkLogic = new CheckConvertLogic(); + checkLogic.ConvertStrategy = this; + checkLogic.TraceLogger = TraceLogger; + checkLogic.Check(); + } + + } +} diff --git a/DataAccess/DTOs/Converters/ReinforcementLibMaterialToDTOConvertStrategy.cs b/DataAccess/DTOs/Converters/ReinforcementLibMaterialToDTOConvertStrategy.cs new file mode 100644 index 0000000..f92fcc3 --- /dev/null +++ b/DataAccess/DTOs/Converters/ReinforcementLibMaterialToDTOConvertStrategy.cs @@ -0,0 +1,24 @@ +using StructureHelperCommon.Infrastructures.Interfaces; +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 ReinforcementLibMaterialToDTOConvertStrategy : LibMaterialToDTOConvertStrategy + { + public override IUpdateStrategy UpdateStrategy { get; } = new ReinforcementLibUpdateStrategy(); + + public override ReinforcementLibMaterialDTO GetMaterialDTO(IReinforcementLibMaterial source) + { + ReinforcementLibMaterialDTO newItem = new() + { + Id = source.Id + }; + return newItem; + } + } +} diff --git a/DataAccess/DTOs/ElasticMaterialDTO.cs b/DataAccess/DTOs/ElasticMaterialDTO.cs new file mode 100644 index 0000000..3ad6e3a --- /dev/null +++ b/DataAccess/DTOs/ElasticMaterialDTO.cs @@ -0,0 +1,43 @@ +using LoaderCalculator.Data.Materials; +using Newtonsoft.Json; +using StructureHelperCommon.Infrastructures.Enums; +using StructureHelperCommon.Models.Materials.Libraries; +using StructureHelperLogics.Models.Materials; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class ElasticMaterialDTO : IElasticMaterial + { + [JsonProperty("Id")] + public Guid Id { get; set; } + [JsonProperty("Modulus")] + public double Modulus { get; set; } + [JsonProperty("CompressiveStrength")] + public double CompressiveStrength { get; set; } + [JsonProperty("TensileStrength")] + public double TensileStrength { get; set; } + [JsonProperty("SafetyFactors")] + public List SafetyFactors { get; } = new(); + + + public object Clone() + { + throw new NotImplementedException(); + } + + public IMaterial GetCrackedLoaderMaterial(LimitStates limitState, CalcTerms calcTerm) + { + throw new NotImplementedException(); + } + + public IMaterial GetLoaderMaterial(LimitStates limitState, CalcTerms calcTerm) + { + throw new NotImplementedException(); + } + } +} diff --git a/DataAccess/DTOs/FRMaterialDTO.cs b/DataAccess/DTOs/FRMaterialDTO.cs new file mode 100644 index 0000000..47368b3 --- /dev/null +++ b/DataAccess/DTOs/FRMaterialDTO.cs @@ -0,0 +1,49 @@ +using LoaderCalculator.Data.Materials; +using Newtonsoft.Json; +using StructureHelperCommon.Infrastructures.Enums; +using StructureHelperCommon.Models.Materials.Libraries; +using StructureHelperLogics.Models.Materials; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class FRMaterialDTO : IFRMaterial + { + [JsonProperty("Id")] + public Guid Id { get; set; } + [JsonProperty("ULSConcreteStrength")] + public double ULSConcreteStrength { get; set; } + [JsonProperty("SunThickness")] + public double SumThickness { get; set; } + [JsonIgnore] + public double GammaF2 { get; } + [JsonProperty("Modulus")] + public double Modulus { get; set; } + [JsonProperty("CompressiveStrength")] + public double CompressiveStrength { get; set; } + [JsonProperty("TensileStrength")] + public double TensileStrength { get; set; } + [JsonProperty("SafetyFactors")] + public List SafetyFactors { get; } = new(); + + + public object Clone() + { + throw new NotImplementedException(); + } + + public IMaterial GetCrackedLoaderMaterial(LimitStates limitState, CalcTerms calcTerm) + { + throw new NotImplementedException(); + } + + public IMaterial GetLoaderMaterial(LimitStates limitState, CalcTerms calcTerm) + { + throw new NotImplementedException(); + } + } +} diff --git a/DataAccess/DTOs/ReinforcementLibMaterialDTO.cs b/DataAccess/DTOs/ReinforcementLibMaterialDTO.cs new file mode 100644 index 0000000..d6de36a --- /dev/null +++ b/DataAccess/DTOs/ReinforcementLibMaterialDTO.cs @@ -0,0 +1,70 @@ +using LoaderCalculator.Data.Materials; +using Newtonsoft.Json; +using StructureHelperCommon.Infrastructures.Enums; +using StructureHelperCommon.Infrastructures.Settings; +using StructureHelperCommon.Models.Materials; +using StructureHelperCommon.Models.Materials.Libraries; +using StructureHelperLogics.Models.Materials; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataAccess.DTOs +{ + public class ReinforcementLibMaterialDTO : IReinforcementLibMaterial + { + const MaterialTypes materialType = MaterialTypes.Reinforcement; + [JsonProperty("Id")] + public Guid Id { get; set; } + [JsonProperty("MaterialEntityId")] + public Guid MaterialEntityId + { + get => MaterialEntity.Id; + set + { + MaterialEntity = ProgramSetting.MaterialRepository.Repository.Single(x => x.Id == value); + } + } + [JsonIgnore] + public ILibMaterialEntity MaterialEntity { get; set; } + [JsonProperty("SafetyFactors")] + public List SafetyFactors { get; set; } = new(); + [JsonProperty("MaterialLogicId")] + public Guid MaterialLogicId + { + get => MaterialLogic.Id; + set + { + MaterialLogic = MaterialLogics.Single(x => x.Id == value); + } + } + [JsonIgnore] + public IMaterialLogic MaterialLogic { get; set; } + + [JsonIgnore] + public List MaterialLogics { get; } = ProgramSetting.MaterialLogics.Where(x => x.MaterialType == materialType).ToList(); + + + public object Clone() + { + throw new NotImplementedException(); + } + + public IMaterial GetCrackedLoaderMaterial(LimitStates limitState, CalcTerms calcTerm) + { + throw new NotImplementedException(); + } + + public IMaterial GetLoaderMaterial(LimitStates limitState, CalcTerms calcTerm) + { + throw new NotImplementedException(); + } + + public (double Compressive, double Tensile) GetStrength(LimitStates limitState, CalcTerms calcTerm) + { + throw new NotImplementedException(); + } + } +} diff --git a/DataAccess/DTOs/TypeBinderListFactory.cs b/DataAccess/DTOs/TypeBinderListFactory.cs index 1c2c141..18f04fe 100644 --- a/DataAccess/DTOs/TypeBinderListFactory.cs +++ b/DataAccess/DTOs/TypeBinderListFactory.cs @@ -57,6 +57,7 @@ namespace DataAccess.DTOs { (typeof(List), "ListOfPartialFactor") }, { (typeof(List), "ListOfIVisualAnalysis") }, { (typeof(ProjectDTO), "Project") }, + { (typeof(ReinforcementLibMaterialDTO), "ReinforcementLibMaterial") }, { (typeof(MaterialPartialFactorDTO), "MaterialPartialFactor") }, { (typeof(VersionProcessorDTO), "VersionProcessor") }, { (typeof(VisualAnalysisDTO), "VisualAnalysis") }, diff --git a/StructureHelperLogics/Models/Materials/Logics/ReinforcementLibUpdateStrategy.cs b/StructureHelperLogics/Models/Materials/Logics/ReinforcementLibUpdateStrategy.cs index 3b1934e..90dbd59 100644 --- a/StructureHelperLogics/Models/Materials/Logics/ReinforcementLibUpdateStrategy.cs +++ b/StructureHelperLogics/Models/Materials/Logics/ReinforcementLibUpdateStrategy.cs @@ -21,7 +21,8 @@ namespace StructureHelperLogics.Models.Materials } public void Update(IReinforcementLibMaterial targetObject, IReinforcementLibMaterial sourceObject) { - CheckObject.CompareTypes(targetObject, sourceObject); + CheckObject.IsNull(sourceObject); + CheckObject.IsNull(targetObject); if (ReferenceEquals(targetObject, sourceObject)) { return; } libUpdateStrategy.Update(targetObject, sourceObject); }