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