using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Models; using StructureHelperCommon.Models.Forces; using StructureHelperCommon.Models.Forces.Logics; using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Models.Shapes; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DataAccess.DTOs.Converters { public class ForceCombinationByFactorToDTOConvertStrategy : IConvertStrategy { private IUpdateStrategy updateStrategy; private IConvertStrategy pointUpdateStrategy; private IConvertStrategy forceTupleConvertStrategy; private IUpdateStrategy baseUpdateStrategy; public ForceCombinationByFactorToDTOConvertStrategy(IUpdateStrategy updateStrategy, IConvertStrategy pointUpdateStrategy, IConvertStrategy convertStrategy, IUpdateStrategy baseUpdateStrategy) { this.baseUpdateStrategy = baseUpdateStrategy; this.updateStrategy = updateStrategy; this.forceTupleConvertStrategy = convertStrategy; this.pointUpdateStrategy = pointUpdateStrategy; } public ForceCombinationByFactorToDTOConvertStrategy() : this ( new ForceCombinationByFactorUpdateStrategy(), new Point2DToDTOConvertStrategy(), new ForceTupleToDTOConvertStrategy(), new ForceActionBaseUpdateStrategy()) { } public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } public IShiftTraceLogger TraceLogger { get; set; } public ForceCombinationByFactorDTO Convert(IForceCombinationByFactor source) { Check(); try { ForceCombinationByFactorDTO newItem = GetNewForceTuple(source); TraceLogger.AddMessage($"Force combination by factor, name = {newItem.Name} was converted", TraceLogStatuses.Debug); return newItem; } catch (Exception ex) { TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Debug); TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error); throw; } } private ForceCombinationByFactorDTO GetNewForceTuple(IForceCombinationByFactor source) { ForceCombinationByFactorDTO newItem = new() { Id = source.Id }; baseUpdateStrategy.Update(newItem, source); updateStrategy.Update(newItem, source); GetNewForcePoint(source, newItem); GetNewFullSLSForces(source, newItem); return newItem; } private void GetNewFullSLSForces(IForceCombinationByFactor source, ForceCombinationByFactorDTO newItem) { if (source.FullSLSForces is not null) { forceTupleConvertStrategy.ReferenceDictionary = ReferenceDictionary; forceTupleConvertStrategy.TraceLogger = TraceLogger; var convertForceTupleLogic = new DictionaryConvertStrategy(this, forceTupleConvertStrategy); newItem.FullSLSForces = convertForceTupleLogic.Convert(source.FullSLSForces); } } private void GetNewForcePoint(IForceCombinationByFactor source, ForceCombinationByFactorDTO newItem) { if (source.ForcePoint is not null) { pointUpdateStrategy.ReferenceDictionary = ReferenceDictionary; pointUpdateStrategy.TraceLogger = TraceLogger; var convertLogic = new DictionaryConvertStrategy(this, pointUpdateStrategy); newItem.ForcePoint = convertLogic.Convert(source.ForcePoint); } } private void Check() { var checkLogic = new CheckConvertLogic(this); checkLogic.Check(); } } }