Add Safety FactorConverter
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
55
DataAccess/DTOs/Converters/LibMaterialDTOUpdateStrategy.cs
Normal file
55
DataAccess/DTOs/Converters/LibMaterialDTOUpdateStrategy.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user