using DataAccess.DTOs.Converters; using StructureHelper.Models.Materials; using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Models; using StructureHelperCommon.Models.Analyses; using StructureHelperLogics.Models.CrossSections; using StructureHelperLogics.Models.Materials; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DataAccess.DTOs { public class CrossSectionRepositoryToDTOConvertStrategy : IConvertStrategy { private IConvertStrategy materialConvertStrategy; public CrossSectionRepositoryToDTOConvertStrategy(IConvertStrategy materialConvertStrategy) { this.materialConvertStrategy = materialConvertStrategy; } public CrossSectionRepositoryToDTOConvertStrategy() : this( new HeadMaterialToDTOConvertStrategy()) { } public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } public IShiftTraceLogger TraceLogger { get; set; } public CrossSectionRepositoryDTO Convert(ICrossSectionRepository source) { Check(); CrossSectionRepositoryDTO newItem = new() { Id = source.Id }; List materials = ProcessMaterials(source); newItem.HeadMaterials.AddRange(materials); return newItem; } private List ProcessMaterials(ICrossSectionRepository source) { materialConvertStrategy.ReferenceDictionary = ReferenceDictionary; materialConvertStrategy.TraceLogger = TraceLogger; var convertLogic = new DictionaryConvertStrategy() { ReferenceDictionary = ReferenceDictionary, ConvertStrategy = materialConvertStrategy, TraceLogger = TraceLogger }; List materials = new(); foreach (var item in source.HeadMaterials) { materials.Add(convertLogic.Convert(item)); } return materials; } private void Check() { var checkLogic = new CheckConvertLogic(); checkLogic.ConvertStrategy = this; checkLogic.TraceLogger = TraceLogger; checkLogic.Check(); } } }