Add Safety FactorConverter

This commit is contained in:
Evgeny Redikultsev
2024-10-06 17:53:49 +05:00
parent 58b6e0eb8b
commit 018a989ba6
21 changed files with 387 additions and 86 deletions

View File

@@ -1,12 +1,14 @@
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.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
@@ -14,6 +16,8 @@ namespace DataAccess.DTOs
{
public class ConcreteLibMaterialDTO : IConcreteLibMaterial
{
const MaterialTypes materialType = MaterialTypes.Concrete;
[JsonProperty("Id")]
public Guid Id { get; set; }
[JsonProperty("RelativeHumidity")]
@@ -22,19 +26,36 @@ namespace DataAccess.DTOs
public double MinAge { get; set; }
[JsonProperty("MaxAge")]
public double MaxAge { get; set; }
[JsonProperty("MaterialEntity")]
[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<IMaterialSafetyFactor> SafetyFactors { get; set; }
public List<IMaterialSafetyFactor> SafetyFactors { get; set; } = new();
[JsonProperty("TensionForULS")]
public bool TensionForULS { get; set; }
[JsonProperty("TensionForSLS")]
public bool TensionForSLS { get; set; }
public IMaterialLogic MaterialLogic { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public List<IMaterialLogic> MaterialLogics => throw new NotImplementedException();
[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<IMaterialLogic> MaterialLogics { get; } = ProgramSetting.MaterialLogics.Where(x => x.MaterialType == materialType).ToList();
public object Clone()
{

View File

@@ -1,5 +1,6 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Loggers;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.Models.Materials;
using System;
@@ -12,13 +13,30 @@ namespace DataAccess.DTOs.Converters
{
public class ConcreteLibMaterialToDTOConvertStrategy : IConvertStrategy<ConcreteLibMaterialDTO, IConcreteLibMaterial>
{
private IUpdateStrategy<IConcreteLibMaterial> updateStrategy = new ConcreteLibUpdateStrategy();
private IUpdateStrategy<ILibMaterial> libMaterialUpdateStrategy = new LibMaterialDTOUpdateStrategy();
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public ConcreteLibMaterialDTO Convert(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()

View File

@@ -1,6 +1,7 @@
using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
@@ -13,13 +14,18 @@ namespace DataAccess.DTOs.Converters
public class HeadMaterialToDTOConvertStrategy : IConvertStrategy<HeadMaterialDTO, IHeadMaterial>
{
private IUpdateStrategy<IHeadMaterial> updateStrategy;
private IConvertStrategy<IHelperMaterial, IHelperMaterial> convertStrategy;
public HeadMaterialToDTOConvertStrategy(IUpdateStrategy<IHeadMaterial> updateStrategy)
public HeadMaterialToDTOConvertStrategy(IUpdateStrategy<IHeadMaterial> updateStrategy,
IConvertStrategy<IHelperMaterial, IHelperMaterial> convertStrategy)
{
this.updateStrategy = updateStrategy;
this.convertStrategy = convertStrategy;
}
public HeadMaterialToDTOConvertStrategy() : this (new HeadMaterialUpdateStrategy())
public HeadMaterialToDTOConvertStrategy() : this (
new HeadMaterialUpdateStrategy(),
new HelperMaterialToDTOConvertStrategy())
{
}
@@ -29,8 +35,20 @@ namespace DataAccess.DTOs.Converters
public HeadMaterialDTO Convert(IHeadMaterial source)
{
HeadMaterialDTO newItem = new() { Id = source.Id};
TraceLogger?.AddMessage($"Convert material Id={source.Id}, name is {source.Name}");
HeadMaterialDTO newItem = new()
{
Id = source.Id
};
updateStrategy.Update(newItem, source);
convertStrategy.ReferenceDictionary = ReferenceDictionary;
var convertLogic = new DictionaryConvertStrategy<IHelperMaterial, IHelperMaterial>()
{
ReferenceDictionary = ReferenceDictionary,
ConvertStrategy = convertStrategy,
TraceLogger = TraceLogger
};
newItem.HelperMaterial = convertLogic.Convert(source.HelperMaterial);
return newItem;
}
}

View File

@@ -1,4 +1,5 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.Models.Materials;
@@ -12,12 +13,38 @@ namespace DataAccess.DTOs.Converters
{
internal class HelperMaterialToDTOConvertStrategy : IConvertStrategy<IHelperMaterial, IHelperMaterial>
{
private IConvertStrategy<ConcreteLibMaterialDTO, IConcreteLibMaterial> concreteConvertStrategy;
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public HelperMaterialToDTOConvertStrategy(
IConvertStrategy<ConcreteLibMaterialDTO, IConcreteLibMaterial> concreteConvertStrategy)
{
this.concreteConvertStrategy = concreteConvertStrategy;
}
public HelperMaterialToDTOConvertStrategy() : this (new ConcreteLibMaterialToDTOConvertStrategy())
{
}
public IHelperMaterial Convert(IHelperMaterial source)
{
Check();
if (source is IConcreteLibMaterial concreteLibMaterial)
{
concreteConvertStrategy.ReferenceDictionary = ReferenceDictionary;
concreteConvertStrategy.TraceLogger = TraceLogger;
return concreteConvertStrategy.Convert(concreteLibMaterial);
}
if (source is IReinforcementLibMaterial reinforcementMaterial)
{
return source;
}
else
{
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(source));
}
}
private void Check()

View File

@@ -0,0 +1,55 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Materials.Libraries;
using StructureHelperCommon.Services;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs.Converters
{
public class LibMaterialDTOUpdateStrategy : IUpdateStrategy<ILibMaterial>
{
private IUpdateStrategy<IMaterialSafetyFactor> safetyFactorUpdateStrategy;
private IUpdateStrategy<IMaterialPartialFactor> partialFactorUpdateStrategy;
public LibMaterialDTOUpdateStrategy(IUpdateStrategy<IMaterialSafetyFactor> safetyFactorUpdateStrategy,
IUpdateStrategy<IMaterialPartialFactor> partialFactorUpdateStrategy)
{
this.safetyFactorUpdateStrategy = safetyFactorUpdateStrategy;
this.partialFactorUpdateStrategy = partialFactorUpdateStrategy;
}
public LibMaterialDTOUpdateStrategy() : this (new MaterialSafetyFactorUpdateStrategy(),
new MaterialPartialFactorUpdateStrategy())
{
}
public void Update(ILibMaterial targetObject, ILibMaterial sourceObject)
{
CheckObject.IsNull(sourceObject);
CheckObject.IsNull(targetObject);
if (ReferenceEquals(targetObject, sourceObject)) { return; }
if (sourceObject.SafetyFactors is not null)
{
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);
}
targetObject.SafetyFactors.Add(newSafetyFactor);
}
}
}
}
}

View File

@@ -0,0 +1,28 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
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 MaterialSafetyFactorToDTOConvertStrategy : IConvertStrategy<MaterialSafetyFactorDTO, IMaterialSafetyFactor>
{
private IUpdateStrategy<IMaterialSafetyFactor> updateStrategy;
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public MaterialSafetyFactorToDTOConvertStrategy(IUpdateStrategy<IMaterialSafetyFactor> updateStrategy)
{
this.updateStrategy = updateStrategy;
}
public MaterialSafetyFactorDTO Convert(IMaterialSafetyFactor source)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,24 @@
using StructureHelperCommon.Infrastructures.Enums;
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 MaterialPartialFactorDTO : IMaterialPartialFactor
{
public Guid Id { get; set; }
public double FactorValue { get; set; }
public StressStates StressState { get; set; }
public CalcTerms CalcTerm { get; set; }
public LimitStates LimitState { get; set; }
public object Clone()
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,36 @@
using Newtonsoft.Json;
using StructureHelperCommon.Infrastructures.Enums;
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 MaterialSafetyFactorDTO : IMaterialSafetyFactor
{
[JsonProperty("Id")]
public Guid Id { get; set; }
[JsonProperty("Name")]
public string Name { get; set; } = string.Empty;
[JsonProperty("Take")]
public bool Take { get; set; }
[JsonProperty("Description")]
public string Description { get; set; } = string.Empty;
[JsonProperty("PartialFactors")]
public List<IMaterialPartialFactor> PartialFactors { get; } = new();
public object Clone()
{
throw new NotImplementedException();
}
public double GetFactor(StressStates stressState, CalcTerms calcTerm, LimitStates limitStates)
{
throw new NotImplementedException();
}
}
}

View File

@@ -3,6 +3,7 @@ using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Models.Analyses;
using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Materials.Libraries;
using StructureHelperLogics.NdmCalculations.Primitives;
using System;
using System.Collections.Generic;
@@ -43,15 +44,20 @@ namespace DataAccess.DTOs
{ (typeof(DateVersionDTO), "DateVersion") },
{ (typeof(FileVersionDTO), "FileVersion") },
{ (typeof(HeadMaterialDTO), "HeadMaterial") },
{ (typeof(MaterialSafetyFactorDTO), "MaterialSafetyFactor") },
{ (typeof(NdmPrimitiveDTO), "NdmPrimitive") },
{ (typeof(IVisualAnalysis), "IVisualAnalysis") },
{ (typeof(List<ICalculator>), "ListOfICalculator") },
{ (typeof(List<IDateVersion>), "ListOfIDateVersion") },
{ (typeof(List<IForceAction>), "ListOfIForceAction") },
{ (typeof(List<IHeadMaterial>), "ListOfIHeadMaterial") },
{ (typeof(List<IMaterialSafetyFactor>), "ListOfMaterialSafetyFactor") },
{ (typeof(List<IMaterialPartialFactor>), "ListOfMaterialPartialFactor") },
{ (typeof(List<INdmPrimitive>), "ListOfINdmPrimitive") },
{ (typeof(List<IPartialFactor>), "ListOfPartialFactor") },
{ (typeof(List<IVisualAnalysis>), "ListOfIVisualAnalysis") },
{ (typeof(ProjectDTO), "Project") },
{ (typeof(MaterialPartialFactorDTO), "MaterialPartialFactor") },
{ (typeof(VersionProcessorDTO), "VersionProcessor") },
{ (typeof(VisualAnalysisDTO), "VisualAnalysis") },
};

View File

@@ -2,6 +2,7 @@
using LoaderCalculator.Data.Materials.MaterialBuilders;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Exceptions;
using System;
namespace StructureHelperCommon.Models.Materials
{
@@ -12,6 +13,7 @@ namespace StructureHelperCommon.Models.Materials
private ConcreteLogicOptions options;
public Guid Id { get; private set; }
public string Name { get; set; }
public IMaterialLogicOptions Options
{
@@ -29,6 +31,11 @@ namespace StructureHelperCommon.Models.Materials
public MaterialTypes MaterialType { get; set; }
public DiagramType DiagramType { get; set; }
public ConcreteCurveLogic(Guid id)
{
Id = id;
}
public IMaterial GetLoaderMaterial()
{
GetLoaderOptions();

View File

@@ -15,9 +15,24 @@ namespace StructureHelperCommon.Models.Materials
{
var items = new List<IMaterialLogic>()
{
new ReinforcementByBuilderLogic() { MaterialType = MaterialTypes.Reinforcement, Name="Bilinear", DiagramType = DiagramType.Bilinear},
new ReinforcementByBuilderLogic() { MaterialType = MaterialTypes.Reinforcement, Name="Triplelinear", DiagramType = DiagramType.TripleLinear},
new ConcreteCurveLogic() { MaterialType = MaterialTypes.Concrete, Name = "Curve", DiagramType = DiagramType.Curve},
new ReinforcementByBuilderLogic(Guid.Parse("54c4fe40-8f82-4995-8930-81e65e97edb9"))
{
MaterialType = MaterialTypes.Reinforcement,
Name="Bilinear",
DiagramType = DiagramType.Bilinear
},
new ReinforcementByBuilderLogic(Guid.Parse("c658b71d-13b1-458c-a1b0-c93d1324acad"))
{
MaterialType = MaterialTypes.Reinforcement,
Name="Triplelinear",
DiagramType = DiagramType.TripleLinear
},
new ConcreteCurveLogic(Guid.Parse("b97e8168-76a1-4e24-ae98-9aa38edd1e9a"))
{
MaterialType = MaterialTypes.Concrete,
Name = "Curve",
DiagramType = DiagramType.Curve
},
};
return items;
}

View File

@@ -1,6 +1,7 @@
using LoaderCalculator.Data.Materials;
using LoaderCalculator.Data.Materials.MaterialBuilders;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -9,7 +10,7 @@ using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Materials
{
public interface IMaterialLogic
public interface IMaterialLogic : ISaveable
{
string Name { get; set; }
IMaterialLogicOptions Options { get; set; }

View File

@@ -1,4 +1,5 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Services;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -7,10 +8,12 @@ using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Materials.Libraries
{
internal class MaterialPartialFactorUpdateStrategy : IUpdateStrategy<IMaterialPartialFactor>
public class MaterialPartialFactorUpdateStrategy : IUpdateStrategy<IMaterialPartialFactor>
{
public void Update(IMaterialPartialFactor targetObject, IMaterialPartialFactor sourceObject)
{
CheckObject.IsNull(sourceObject);
CheckObject.IsNull(targetObject);
if (ReferenceEquals(targetObject, sourceObject)) { return; }
targetObject.LimitState = sourceObject.LimitState;
targetObject.StressState = sourceObject.StressState;

View File

@@ -1,4 +1,5 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Services;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -7,10 +8,12 @@ using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Materials.Libraries
{
internal class MaterialSafetyFactorUpdateStrategy : IUpdateStrategy<IMaterialSafetyFactor>
public class MaterialSafetyFactorUpdateStrategy : IUpdateStrategy<IMaterialSafetyFactor>
{
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;

View File

@@ -1,5 +1,6 @@
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using System;
namespace StructureHelperCommon.Models.Materials.Libraries
@@ -7,10 +8,12 @@ namespace StructureHelperCommon.Models.Materials.Libraries
public class MaterialPartialFactor : IMaterialPartialFactor
{
private double factorValue;
private IUpdateStrategy<IMaterialPartialFactor> updateStrategy = new MaterialPartialFactorUpdateStrategy();
public Guid Id { get; }
public StressStates StressState { get; set; }
public CalcTerms CalcTerm { get; set; }
public LimitStates LimitState { get; set; }
public StressStates StressState { get; set; } = StressStates.Compression;
public CalcTerms CalcTerm { get; set; } = CalcTerms.LongTerm;
public LimitStates LimitState { get; set; } = LimitStates.ULS;
public double FactorValue
{
get => factorValue;
@@ -28,9 +31,6 @@ namespace StructureHelperCommon.Models.Materials.Libraries
public MaterialPartialFactor(Guid id)
{
Id = id;
StressState = StressStates.Compression;
LimitState = LimitStates.ULS;
CalcTerm = CalcTerms.LongTerm;
FactorValue = 1d;
}
@@ -40,7 +40,6 @@ namespace StructureHelperCommon.Models.Materials.Libraries
public object Clone()
{
var newItem = new MaterialPartialFactor();
var updateStrategy = new MaterialPartialFactorUpdateStrategy();
updateStrategy.Update(newItem, this);
return newItem;
}

View File

@@ -3,6 +3,7 @@ using LoaderCalculator.Data.Materials.MaterialBuilders;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Services;
using System;
namespace StructureHelperCommon.Models.Materials
{
@@ -12,6 +13,7 @@ namespace StructureHelperCommon.Models.Materials
private ReinforcementOptions materialOptions;
private IMaterialOptionLogic optionLogic;
public Guid Id { get; private set; }
public string Name { get; set; }
public DiagramType DiagramType { get; set; }
public IMaterialLogicOptions Options
@@ -26,6 +28,10 @@ namespace StructureHelperCommon.Models.Materials
public MaterialTypes MaterialType { get; set; }
public ReinforcementByBuilderLogic(Guid id)
{
Id = id;
}
public IMaterial GetLoaderMaterial()
{
GetLoaderOptions();

View File

@@ -1,6 +1,7 @@
using LoaderCalculator.Data.Materials;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Models.Materials;
using StructureHelperCommon.Models.Materials.Libraries;
@@ -18,6 +19,7 @@ namespace StructureHelperLogics.Models.Materials
private IMaterialOptionLogic optionLogic;
private IFactorLogic factorLogic => new FactorLogic(SafetyFactors);
private LMLogic.ITrueStrengthLogic strengthLogic;
private IUpdateStrategy<IConcreteLibMaterial> updateStrategy = new ConcreteLibUpdateStrategy();
/// <inheritdoc/>
public Guid Id { get; }
@@ -64,7 +66,6 @@ namespace StructureHelperLogics.Models.Materials
public object Clone()
{
var newItem = new ConcreteLibMaterial();
var updateStrategy = new ConcreteLibUpdateStrategy();
updateStrategy.Update(newItem, this);
return newItem;
}

View File

@@ -21,12 +21,15 @@ namespace StructureHelperLogics.Models.Materials
}
public void Update(IConcreteLibMaterial targetObject, IConcreteLibMaterial sourceObject)
{
CheckObject.CompareTypes(targetObject, sourceObject);
CheckObject.IsNull(sourceObject);
CheckObject.IsNull(targetObject);
if (ReferenceEquals(targetObject, sourceObject)) { return; }
libUpdateStrategy.Update(targetObject, sourceObject);
targetObject.TensionForULS = sourceObject.TensionForULS;
targetObject.TensionForSLS = sourceObject.TensionForSLS;
targetObject.RelativeHumidity = sourceObject.RelativeHumidity;
targetObject.MinAge = sourceObject.MinAge;
targetObject.MaxAge = sourceObject.MaxAge;
}
}
}

View File

@@ -1,5 +1,4 @@
using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Services;
@@ -7,27 +6,13 @@ namespace StructureHelperLogics.Models.Materials
{
public class HeadMaterialUpdateStrategy : IUpdateStrategy<IHeadMaterial>
{
private IUpdateStrategy<IElasticMaterial> elasticStrategy;
private IUpdateStrategy<IFRMaterial> frStrategy;
private IUpdateStrategy<IConcreteLibMaterial> concreteStrategy;
private IUpdateStrategy<IReinforcementLibMaterial> reinforcementStrategy;
public HeadMaterialUpdateStrategy(IUpdateStrategy<IElasticMaterial> elasticStrategy,
IUpdateStrategy<IFRMaterial> frStrategy,
IUpdateStrategy<IConcreteLibMaterial> concreteStrategy,
IUpdateStrategy<IReinforcementLibMaterial> reinforcementStrategy
)
private IUpdateStrategy<IHelperMaterial> helperMaterialUpdateStrategy;
public HeadMaterialUpdateStrategy(IUpdateStrategy<IHelperMaterial> helperMaterialUpdateStrategy)
{
this.elasticStrategy = elasticStrategy;
this.frStrategy = frStrategy;
this.concreteStrategy = concreteStrategy;
this.reinforcementStrategy= reinforcementStrategy;
this.helperMaterialUpdateStrategy = helperMaterialUpdateStrategy;
}
public HeadMaterialUpdateStrategy() : this(
new ElasticUpdateStrategy(),
new FRUpdateStrategy(),
new ConcreteLibUpdateStrategy(),
new ReinforcementLibUpdateStrategy()
) { }
public HeadMaterialUpdateStrategy() : this(new HelperMaterialUpdateStrategy()) { }
public void Update(IHeadMaterial targetObject, IHeadMaterial sourceObject)
{
@@ -37,44 +22,9 @@ namespace StructureHelperLogics.Models.Materials
targetObject.Name = sourceObject.Name;
targetObject.Color = sourceObject.Color;
targetObject.HelperMaterial = sourceObject.HelperMaterial.Clone() as IHelperMaterial;
UpdateHelperMaterial(targetObject.HelperMaterial, sourceObject.HelperMaterial);
helperMaterialUpdateStrategy.Update(targetObject.HelperMaterial, sourceObject.HelperMaterial);
}
private void UpdateHelperMaterial(IHelperMaterial targetObject, IHelperMaterial sourceObject)
{
CheckObject.CompareTypes(targetObject, sourceObject);
if (sourceObject is ILibMaterial)
{
UpdateLibMaterial(targetObject, sourceObject);
}
else if (sourceObject is IElasticMaterial)
{
elasticStrategy.Update(targetObject as IElasticMaterial, sourceObject as IElasticMaterial);
}
else if (sourceObject is IFRMaterial)
{
frStrategy.Update(targetObject as IFRMaterial, sourceObject as IFRMaterial);
}
else
{
ErrorCommonProcessor.ObjectTypeIsUnknown(typeof(IHelperMaterial), sourceObject.GetType());
}
}
private void UpdateLibMaterial(IHelperMaterial targetObject, IHelperMaterial sourceObject)
{
if (sourceObject is IConcreteLibMaterial)
{
concreteStrategy.Update(targetObject as IConcreteLibMaterial, sourceObject as IConcreteLibMaterial);
}
else if (sourceObject is IReinforcementLibMaterial)
{
reinforcementStrategy.Update(targetObject as IReinforcementLibMaterial, sourceObject as IReinforcementLibMaterial);
}
else
{
ErrorCommonProcessor.ObjectTypeIsUnknown(typeof(ILibMaterial), sourceObject.GetType());
}
}
}
}

View File

@@ -0,0 +1,75 @@
using StructureHelperCommon.Infrastructures.Exceptions;
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 HelperMaterialUpdateStrategy : IUpdateStrategy<IHelperMaterial>
{
private IUpdateStrategy<IElasticMaterial> elasticStrategy;
private IUpdateStrategy<IFRMaterial> frStrategy;
private IUpdateStrategy<IConcreteLibMaterial> concreteStrategy;
private IUpdateStrategy<IReinforcementLibMaterial> reinforcementStrategy;
public HelperMaterialUpdateStrategy(IUpdateStrategy<IElasticMaterial> elasticStrategy,
IUpdateStrategy<IFRMaterial> frStrategy,
IUpdateStrategy<IConcreteLibMaterial> concreteStrategy,
IUpdateStrategy<IReinforcementLibMaterial> reinforcementStrategy
)
{
this.elasticStrategy = elasticStrategy;
this.frStrategy = frStrategy;
this.concreteStrategy = concreteStrategy;
this.reinforcementStrategy = reinforcementStrategy;
}
public HelperMaterialUpdateStrategy() : this(
new ElasticUpdateStrategy(),
new FRUpdateStrategy(),
new ConcreteLibUpdateStrategy(),
new ReinforcementLibUpdateStrategy()
)
{ }
public void Update(IHelperMaterial targetObject, IHelperMaterial sourceObject)
{
CheckObject.IsNull(sourceObject);
CheckObject.IsNull(targetObject);
if (sourceObject is ILibMaterial)
{
UpdateLibMaterial(targetObject, sourceObject);
}
else if (sourceObject is IElasticMaterial)
{
elasticStrategy.Update(targetObject as IElasticMaterial, sourceObject as IElasticMaterial);
}
else if (sourceObject is IFRMaterial)
{
frStrategy.Update(targetObject as IFRMaterial, sourceObject as IFRMaterial);
}
else
{
ErrorCommonProcessor.ObjectTypeIsUnknown(typeof(IHelperMaterial), sourceObject.GetType());
}
}
private void UpdateLibMaterial(IHelperMaterial targetObject, IHelperMaterial sourceObject)
{
if (sourceObject is IConcreteLibMaterial)
{
concreteStrategy.Update(targetObject as IConcreteLibMaterial, sourceObject as IConcreteLibMaterial);
}
else if (sourceObject is IReinforcementLibMaterial)
{
reinforcementStrategy.Update(targetObject as IReinforcementLibMaterial, sourceObject as IReinforcementLibMaterial);
}
else
{
ErrorCommonProcessor.ObjectTypeIsUnknown(typeof(ILibMaterial), sourceObject.GetType());
}
}
}
}

View File

@@ -13,11 +13,16 @@ namespace StructureHelperLogics.Models.Materials
{
public void Update(ILibMaterial targetObject, ILibMaterial sourceObject)
{
CheckObject.CompareTypes(targetObject, sourceObject);
CheckObject.IsNull(sourceObject);
CheckObject.IsNull(targetObject);
if (ReferenceEquals(targetObject, sourceObject)) { return; }
targetObject.MaterialEntity = sourceObject.MaterialEntity;
if (targetObject.SafetyFactors is not null & sourceObject.SafetyFactors is not null)
if (sourceObject.SafetyFactors is not null)
{
if (targetObject.SafetyFactors is null)
{
targetObject.SafetyFactors = new();
}
targetObject.SafetyFactors.Clear();
foreach (var item in sourceObject.SafetyFactors)
{