using Microsoft.EntityFrameworkCore.Metadata.Internal; using Newtonsoft.Json; using WebDoorCreator.Data.DbModels; using WebDoorCreator.Data.DTO; namespace WebDoorCreator.Data.DDF { public class Converter { #region Public Constructors /// /// Init del convertitore secondo impostazioni standard /// /// /// /// /// public Converter(string vers, bool remDoorOp, List headRows, List footRows) { FormatVers = vers; RemDoorOp = remDoorOp; HeadRows = headRows; FootRows = footRows; } #endregion Public Constructors #region Public Methods /// /// Fornisce il DDF corrispondente all'elenco OP inviato, seocndo la conf del convertitore /// /// /// public string GetSerialized(List listOp) { string outDdf = ""; try { DoorOpsDTO CurrentDoorOp = new DoorOpsDTO(); EdgesDto CurrentEdges = new EdgesDto(); SizeDto CurrentSize = new SizeDto(); SwingDto CurrentSwing = new SwingDto(); PropertiesDto CurrentProperties = new PropertiesDto(); FinishingDto CurrentFinishing = new FinishingDto(); DDFDto CurrentConf = new DDFDto(); ListValuesModel CurrentCompoOrder = new ListValuesModel(); Dictionary>> dictDoorOP = new Dictionary>>(); Dictionary> dictBaseDoorOp = new Dictionary>(); Dictionary> dictBaseSwing = new Dictionary>(); // per prima cosa popolo gli oggetti di appoggio... dictDoorOP = new Dictionary>>(); var i = 0; foreach (var item in listOp.Where(x => x.ObjectId != "Size" && x.ObjectId != "Profiles" && x.ObjectId != "Swing" && x.ObjectId != "Properties" && x.ObjectId != "Finishing")) { var deserialized = JsonConvert.DeserializeObject>(item.JsoncActVal!); if (deserialized != null) { if (dictDoorOP.ContainsKey(item.ObjectId)) { var actList = dictDoorOP[item.ObjectId]; actList.Add(deserialized.Where(x => x.Key != "Folder").ToDictionary(x => x.Key, x => x.Value)); //actList.Add(new Dictionary() { ["Separator"] = " "}); dictDoorOP[item.ObjectId] = actList; } else { var currList = new List>(); currList.Add(deserialized.Where(x => x.Key != "Folder").ToDictionary(x => x.Key, x => x.Value)); //currList.Add(new Dictionary() { ["Separator"] = " " }); dictDoorOP.Add(item.ObjectId, currList); var sep = new List>(); dictDoorOP.Add($"Separator_{i}", sep); } } i++; } CurrentDoorOp.hardware = dictDoorOP; string doorOpSer = CurrentDoorOp.GetSerialized(RemDoorOp); dictBaseDoorOp.Clear(); foreach (var item in listOp.Where(x => x.ObjectId == "Properties")) { var deserialized = JsonConvert.DeserializeObject>>(item.JsoncActVal!); if (deserialized != null) { dictBaseDoorOp = deserialized; } i++; } CurrentProperties.Properties = dictBaseDoorOp; string WTSer = CurrentProperties.GetSerialized(RemDoorOp); dictBaseDoorOp.Clear(); foreach (var item in listOp.Where(x => x.ObjectId == "Finishing")) { var deserialized = JsonConvert.DeserializeObject>>(item.JsoncActVal!); if (deserialized != null) { dictBaseDoorOp = deserialized; } i++; } CurrentFinishing.finishing = dictBaseDoorOp; string FinishingSer = CurrentFinishing.GetSerialized(RemDoorOp); dictBaseDoorOp.Clear(); foreach (var item in listOp.Where(x => x.ObjectId == "Profiles")) { var deserialized = JsonConvert.DeserializeObject>>(item.JsoncActVal!); if (deserialized != null) { dictBaseDoorOp = deserialized; } i++; } // ora popolo l'oggetto DTO principale CurrentEdges.profiles = dictBaseDoorOp; string edgesSer = CurrentEdges.GetSerialized(RemDoorOp); dictBaseDoorOp.Clear(); foreach (var item in listOp.Where(x => x.ObjectId == "Size")) { var deserialized = JsonConvert.DeserializeObject>>(item.JsoncActVal!); if (deserialized != null) { dictBaseDoorOp = deserialized; } i++; } CurrentSize.size = dictBaseDoorOp; string sizeSer = CurrentSize.GetSerialized(RemDoorOp); //dictBaseDoorOp.Clear(); foreach (var item in listOp.Where(x => x.ObjectId == "Swing")) { var deserialized = JsonConvert.DeserializeObject>>(item.JsoncActVal!); if (deserialized != null) { dictBaseSwing = deserialized; } i++; } CurrentSwing.swing = dictBaseSwing; string swingSer = CurrentSwing.GetSerialized(RemDoorOp); CurrentConf.version = FormatVers; outDdf = CurrentConf.GetSerialized(HeadRows, FootRows, doorOpSer, edgesSer, sizeSer, swingSer, WTSer, FinishingSer); } catch { } return outDdf; } #endregion Public Methods #region Protected Properties protected List FootRows { get; set; } = new List(); protected string FormatVers { get; set; } = "0"; protected List HeadRows { get; set; } = new List(); protected List> listDictDoorOP { get; set; } = new List>(); protected bool RemDoorOp { get; set; } = false; #endregion Protected Properties } }