162 lines
7.6 KiB
C#
162 lines
7.6 KiB
C#
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
|
|
|
|
/// <summary>
|
|
/// Init del convertitore secondo impostazioni standard
|
|
/// </summary>
|
|
/// <param name="vers"></param>
|
|
/// <param name="remDoorOp"></param>
|
|
/// <param name="headRows"></param>
|
|
/// <param name="footRows"></param>
|
|
public Converter(string vers, bool remDoorOp, List<string> headRows, List<string> footRows)
|
|
{
|
|
FormatVers = vers;
|
|
RemDoorOp = remDoorOp;
|
|
HeadRows = headRows;
|
|
FootRows = footRows;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Fornisce il DDF corrispondente all'elenco OP inviato, seocndo la conf del convertitore
|
|
/// </summary>
|
|
/// <param name="listOp"></param>
|
|
/// <returns></returns>
|
|
public string GetSerialized(List<DoorOpModel> 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<string, List<Dictionary<string, string>>> dictDoorOP = new Dictionary<string, List<Dictionary<string, string>>>();
|
|
Dictionary<string, Dictionary<string, string>> dictBaseDoorOp = new Dictionary<string, Dictionary<string, string>>();
|
|
Dictionary<string, Dictionary<string, string>> dictBaseSwing = new Dictionary<string, Dictionary<string, string>>();
|
|
// per prima cosa popolo gli oggetti di appoggio...
|
|
dictDoorOP = new Dictionary<string, List<Dictionary<string, string>>>();
|
|
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<Dictionary<string, string>>(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<string, string>() { ["Separator"] = " "});
|
|
dictDoorOP[item.ObjectId] = actList;
|
|
}
|
|
else
|
|
{
|
|
var currList = new List<Dictionary<string, string>>();
|
|
currList.Add(deserialized.Where(x => x.Key != "Folder").ToDictionary(x => x.Key, x => x.Value));
|
|
//currList.Add(new Dictionary<string, string>() { ["Separator"] = " " });
|
|
dictDoorOP.Add(item.ObjectId, currList);
|
|
var sep = new List<Dictionary<string, string>>();
|
|
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<Dictionary<string, Dictionary<string, string>>>(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<Dictionary<string, Dictionary<string, string>>>(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<Dictionary<string, Dictionary<string, string>>>(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<Dictionary<string, Dictionary<string, string>>>(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<Dictionary<string, Dictionary<string, string>>>(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<string> FootRows { get; set; } = new List<string>();
|
|
protected string FormatVers { get; set; } = "0";
|
|
protected List<string> HeadRows { get; set; } = new List<string>();
|
|
protected List<Dictionary<string, string>> listDictDoorOP { get; set; } = new List<Dictionary<string, string>>();
|
|
protected bool RemDoorOp { get; set; } = false;
|
|
|
|
#endregion Protected Properties
|
|
}
|
|
} |