using DataAccess.DTOs.Converters; using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Models; using StructureHelperCommon.Models.WorkPlanes; using StructureHelperLogics.Models.CrossSections; namespace DataAccess.DTOs { public class CrossSectionToDTOConvertStrategy : ConvertStrategy { private IUpdateStrategy updateStrategy; //don't use since CrossSection does not have any properties private IConvertStrategy convertRepositoryStrategy; private DictionaryConvertStrategy convertLogic; private ICheckConvertLogic checkLogic; private IConvertStrategy workPlanePropertyConvertStrategy; public CrossSectionToDTOConvertStrategy(IUpdateStrategy updateStrategy, IConvertStrategy convertRepositoryStrategy, ICheckConvertLogic checkLogic, IConvertStrategy workPlanePropertyConvertStrategy) { this.updateStrategy = updateStrategy; this.convertRepositoryStrategy = convertRepositoryStrategy; this.checkLogic = checkLogic; this.workPlanePropertyConvertStrategy = workPlanePropertyConvertStrategy; } public CrossSectionToDTOConvertStrategy() { } private void Check() { checkLogic.ConvertStrategy = this; checkLogic.TraceLogger = TraceLogger; checkLogic.Check(); } public override CrossSectionDTO GetNewItem(ICrossSection source) { InitializeStrategies(); try { GetNewItemBySource(source); return NewItem; } catch (Exception ex) { TraceErrorByEntity(this, ex.Message); throw; } } private void InitializeStrategies() { updateStrategy ??= new CrossSectionUpdateStrategy(); convertRepositoryStrategy ??= new CrossSectionRepositoryToDTOConvertStrategy(ReferenceDictionary, TraceLogger); checkLogic ??= new CheckConvertLogic(); workPlanePropertyConvertStrategy ??= new WorkPlanePropertyToDTOConvertStrategy(ReferenceDictionary, TraceLogger); } private void GetNewItemBySource(ICrossSection source) { Check(); NewItem = new() { Id = source.Id }; convertLogic = new DictionaryConvertStrategy(this, convertRepositoryStrategy); NewItem.SectionRepository = convertLogic.Convert(source.SectionRepository); NewItem.WorkPlaneProperty = workPlanePropertyConvertStrategy.Convert(source.WorkPlaneProperty); } } }