82 lines
2.9 KiB
C#
82 lines
2.9 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// Riceve un JWD in ingresso e effettua una sostituzione dei parametri rieschiesti (SE non nulli)
|
|
/// </summary>
|
|
/// <param name="currSer"></param>
|
|
/// <param name="newFamilyHardware"></param>
|
|
/// <param name="newHardware"></param>
|
|
/// <param name="newColorMaterial"></param>
|
|
/// <returns>Valore serializzato con le modifiche richieste</returns>
|
|
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<JsonWindow>(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);
|
|
}
|
|
}
|
|
}
|
|
}
|