Files
StructureHelper/DataAccess/DTOs/Converters/VersionItemFromDTOConvertStrategy.cs
2025-06-08 20:02:56 +05:00

64 lines
2.6 KiB
C#

using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.BeamShears;
using StructureHelperLogics.Models.CrossSections;
namespace DataAccess.DTOs
{
public class VersionItemFromDTOConvertStrategy : ConvertStrategy<ISaveable, ISaveable>
{
private const string AnalysisIs = "Analysis type is";
private IConvertStrategy<ICrossSection, ICrossSection> crossSectionConvertStrategy;
public VersionItemFromDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
{
}
public override ISaveable GetNewItem(ISaveable source)
{
ChildClass = this;
return GetNewAnalysis(source);
}
private ISaveable GetNewAnalysis(ISaveable source)
{
ISaveable newItem;
if (source is ICrossSection crossSection)
{
newItem = ProcessCrossSection(crossSection);
}
else if (source is IBeamShear beamShear)
{
newItem = ProcessBeamShear(beamShear);
}
else
{
string errorString = ErrorStrings.ObjectTypeIsUnknownObj(source);
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
throw new StructureHelperException(errorString);
}
TraceLogger?.AddMessage($"Object of type <<{newItem.GetType()}>> was obtained", TraceLogStatuses.Service);
return newItem;
}
private ISaveable ProcessBeamShear(IBeamShear beamShear)
{
throw new NotImplementedException();
}
private ICrossSection ProcessCrossSection(ICrossSection source)
{
TraceLogger?.AddMessage(AnalysisIs + " Cross-Section", TraceLogStatuses.Service);
TraceLogger?.AddMessage("Cross-Section converting is started", TraceLogStatuses.Service);
crossSectionConvertStrategy ??= new CrossSectionFromDTOConvertStrategy();
crossSectionConvertStrategy.ReferenceDictionary = ReferenceDictionary;
crossSectionConvertStrategy.TraceLogger = TraceLogger;
var convertLogic = new DictionaryConvertStrategy<ICrossSection, ICrossSection>(this, crossSectionConvertStrategy);
ICrossSection newItem = convertLogic.Convert(source);
TraceLogger?.AddMessage("Cross-Section converting has been finished successfully", TraceLogStatuses.Service);
return newItem;
}
}
}