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 { private const string AnalysisIs = "Analysis type is"; private IConvertStrategy 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(this, crossSectionConvertStrategy); ICrossSection newItem = convertLogic.Convert(source); TraceLogger?.AddMessage("Cross-Section converting has been finished successfully", TraceLogStatuses.Service); return newItem; } } }