Add ElasticMaterial DTOs

This commit is contained in:
Evgeny Redikultsev
2024-10-06 22:18:50 +05:00
parent 018a989ba6
commit 2c5c5db43a
10 changed files with 288 additions and 47 deletions

View File

@@ -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<ConcreteLibMaterialDTO, IConcreteLibMaterial>
public class ConcreteLibMaterialToDTOConvertStrategy : LibMaterialToDTOConvertStrategy<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 override IUpdateStrategy<IConcreteLibMaterial> 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<ConcreteLibMaterialDTO, IConcreteLibMaterial>();
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check();
}
}
}

View File

@@ -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<IHelperMaterial, IHelperMaterial>
{
private IConvertStrategy<ConcreteLibMaterialDTO, IConcreteLibMaterial> concreteConvertStrategy;
private LibMaterialToDTOConvertStrategy<ConcreteLibMaterialDTO, IConcreteLibMaterial> concreteConvertStrategy;
private LibMaterialToDTOConvertStrategy<ReinforcementLibMaterialDTO, IReinforcementLibMaterial> reinforcementConvertStrategy;
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public HelperMaterialToDTOConvertStrategy(
IConvertStrategy<ConcreteLibMaterialDTO, IConcreteLibMaterial> concreteConvertStrategy)
LibMaterialToDTOConvertStrategy<ConcreteLibMaterialDTO, IConcreteLibMaterial> concreteConvertStrategy,
LibMaterialToDTOConvertStrategy<ReinforcementLibMaterialDTO, IReinforcementLibMaterial> 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
{

View File

@@ -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<ILibMaterial>
{
@@ -28,6 +28,7 @@ namespace DataAccess.DTOs.Converters
}
/// <inheritdoc/>
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;
}
}
}

View File

@@ -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<T,V> : IConvertStrategy<T, V>
where T : V
where V : ILibMaterial
{
public abstract IUpdateStrategy<V> UpdateStrategy { get; }
public abstract T GetMaterialDTO(V source);
private IUpdateStrategy<ILibMaterial> 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<T, V>();
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check();
}
}
}

View File

@@ -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<ReinforcementLibMaterialDTO, IReinforcementLibMaterial>
{
public override IUpdateStrategy<IReinforcementLibMaterial> UpdateStrategy { get; } = new ReinforcementLibUpdateStrategy();
public override ReinforcementLibMaterialDTO GetMaterialDTO(IReinforcementLibMaterial source)
{
ReinforcementLibMaterialDTO newItem = new()
{
Id = source.Id
};
return newItem;
}
}
}

View File

@@ -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<IMaterialSafetyFactor> 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();
}
}
}

View File

@@ -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<IMaterialSafetyFactor> 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();
}
}
}

View File

@@ -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<IMaterialSafetyFactor> 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<IMaterialLogic> 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();
}
}
}

View File

@@ -57,6 +57,7 @@ namespace DataAccess.DTOs
{ (typeof(List<IPartialFactor>), "ListOfPartialFactor") },
{ (typeof(List<IVisualAnalysis>), "ListOfIVisualAnalysis") },
{ (typeof(ProjectDTO), "Project") },
{ (typeof(ReinforcementLibMaterialDTO), "ReinforcementLibMaterial") },
{ (typeof(MaterialPartialFactorDTO), "MaterialPartialFactor") },
{ (typeof(VersionProcessorDTO), "VersionProcessor") },
{ (typeof(VisualAnalysisDTO), "VisualAnalysis") },

View File

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