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 rieschiesti (SE non nulli) /// /// /// /// /// /// Valore serializzato con le modifiche richieste public static string MassUpdate(string currSer, string? newFamilyHardware, Hardware? newHardware, string? newColorMaterial, string? newMaterial, string? newGlass, string? newProfile) { string outVal = 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); } } } }