using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Models; using StructureHelperCommon.Models.Forces; using StructureHelperCommon.Models.Forces.BeamShearActions; namespace DataAccess.DTOs { public class BeamShearActionConvertStrategy : ConvertStrategy { private IUpdateStrategy updateStrategy; private IConvertStrategy factoredTupleConvertStrategy; private IConvertStrategy axisActionConvertStrategy; public BeamShearActionConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy) { } public BeamShearActionConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger) : base(referenceDictionary, traceLogger) { } public override BeamShearActionDTO GetNewItem(IBeamShearAction source) { try { GetNewBeamAction(source); return NewItem; } catch (Exception ex) { TraceErrorByEntity(this, ex.Message); throw; } } private void GetNewBeamAction(IBeamShearAction source) { TraceLogger?.AddMessage($"Converting of beam shear action Id = {source.Id} has been started", TraceLogStatuses.Debug); InitializeStrategies(); NewItem = new(source.Id); updateStrategy.Update(NewItem, source); NewItem.ExternalForce = factoredTupleConvertStrategy.Convert(source.ExternalForce); NewItem.SupportAction = axisActionConvertStrategy.Convert(source.SupportAction); TraceLogger?.AddMessage($"Converting of beam shear action Id = {NewItem.Id} has been finished", TraceLogStatuses.Debug); } private void InitializeStrategies() { updateStrategy ??= new BeamShearActionUpdateStrategy(); factoredTupleConvertStrategy = new DictionaryConvertStrategy (this, new FactoredForceTupleToDTOConvertStrategy(this)); axisActionConvertStrategy = new DictionaryConvertStrategy (this, new BeamShearAxisActionToDTOConvertStrategy(this)); } } }