using Egw.Window.Data; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WebWindowComplex.Json; using WebWindowComplex.Models; using static WebWindowComplex.Json.WindowConst; namespace WebWindowComplex { public class SerialMan { /// /// Riceve un JWD in ingresso e effettua una sostituzione dei parametri richiesti (SE non nulli) /// /// /// /// /// /// Valore serializzato con le modifiche richieste public static GeneralData MassUpdate(string currSer, Dictionary DictParameter) { if (string.IsNullOrEmpty(currSer) || currSer == "{}") { GeneralData dp = new GeneralData() { serializeStruct = currSer, DictParameter = DictParameter }; return dp; } // serializzazione JWD --> window JsonWindow WindowFromJson = JsonConvert.DeserializeObject(currSer, new PolymorphicJsonConverter()) ?? new JsonWindow("", "", "", ""); Window currWindow = WindowFromJson.Deserialize(); if (!string.IsNullOrEmpty(DictParameter.GetValueOrDefault("Color"))) { currWindow.sColorMaterial = DictParameter.GetValueOrDefault("Color")!; DictParameter.Remove("Color"); } if (!string.IsNullOrEmpty(DictParameter.GetValueOrDefault("Wood"))) { currWindow.sWood = DictParameter.GetValueOrDefault("Wood")!; DictParameter.Remove("Wood"); } if (!string.IsNullOrEmpty(DictParameter.GetValueOrDefault("Glass"))) { currWindow.sGlass = DictParameter.GetValueOrDefault("Glass")!; DictParameter.Remove("Glass"); } if (!string.IsNullOrEmpty(DictParameter.GetValueOrDefault("Profile")) && currWindow.sProfilePath.Equals(DictParameter.GetValueOrDefault("Profile"))) { DictParameter.Remove("Profile"); } var CurrJwd = JsonConvert.SerializeObject(currWindow.Serialize(), Formatting.Indented); GeneralData datap = new GeneralData() { serializeStruct = CurrJwd, DictParameter = DictParameter }; return datap; } //public static string MassUpdate(string currSer, string? newFamilyHardware, Hardware? newHardware, string? newColorMaterial, string? newMaterial, string? newGlass, string? newProfile) //{ // if(string.IsNullOrEmpty(currSer) || currSer == "{}") // { // return currSer; // } // // serializzazione JWD --> window // JsonWindow WindowFromJson = JsonConvert.DeserializeObject(currSer, new PolymorphicJsonConverter()) ?? new JsonWindow("", "", "", ""); // Window currWindow = WindowFromJson.Deserialize(); // // verifica 1:1 delle richieste // if (!string.IsNullOrEmpty(newFamilyHardware)) // { // SearchSash(currWindow.AreaList.First(), newFamilyHardware, null); // } // if (newHardware != null) // { // SearchSash(currWindow.AreaList.First(), null, newHardware); // } // if (!string.IsNullOrEmpty(newColorMaterial)) // { // currWindow.sColorMaterial = newColorMaterial; // } // if (!string.IsNullOrEmpty(newMaterial)) // { // currWindow.sMaterial = newMaterial; // } // if (!string.IsNullOrEmpty(newGlass)) // { // currWindow.sGlass = newGlass; // } // if (!string.IsNullOrEmpty(newProfile)) // { // currWindow.sProfilePath = newProfile; // } // var CurrJwd = JsonConvert.SerializeObject(currWindow.Serialize(), Formatting.Indented); // return CurrJwd; //} //internal static void SearchSash(Area currentArea, string? newFamilyHw, Hardware? newHardware) //{ // if (currentArea.AreaType.Equals(AreaTypes.SASH)) // { // Sash s = (Sash)currentArea; // if (!string.IsNullOrEmpty(newFamilyHw)) // { // s.SelFamilyHardware = newFamilyHw; // } // if (newHardware != null) // { // s.SelHardware = newHardware; // } // } // foreach (Area child in currentArea.AreaList) // { // SearchSash(child, newFamilyHw, newHardware); // } //} } }