using Egw.Window.Data;
using EgwCoreLib.Lux.Core;
using EgwCoreLib.Lux.Core.RestPayload;
using EgwCoreLib.Lux.Data.Services;
using Microsoft.AspNetCore.Components;
using Newtonsoft.Json;
using WebWindowTest.DTO;
using static WebWindowTest.LayoutConst;
namespace Test.UI.Components.Pages
{
public partial class SimpleEditOld : IDisposable
{
#region Public Fields
public string InitialJwd = "";
#endregion Public Fields
#region Public Methods
public void Dispose()
{
DLService.PipeSvg.EA_NewMessage -= PipeSvg_EA_NewMessage;
DLService.PipeShape.EA_NewMessage -= PipeShape_EA_NewMessage;
DLService.PipeHwOpt.EA_NewMessage -= PipeHwOption_EA_NewMessage;
}
#endregion Public Methods
#region Protected Fields
///
/// Predisposizione valori live SVG/JWD
///
protected LivePayload CurrData = new LivePayload();
protected Dictionary currGroupShape = new Dictionary();
protected Dictionary currHwOption = new Dictionary();
protected string currJwd = "...";
protected Dictionary m_CurrArgs = new Dictionary();
protected string prevJwd = "";
///
/// Configurazione elenchi anagrafiche
///
protected BaseListPayload SetupList = new BaseListPayload();
#endregion Protected Fields
#region Protected Properties
protected List AvailColorMaterialList { get; set; } = new List()
{
new string("White"),
new string("Wood"),
new string("Black"),
new string("Blu")
};
protected List AvailFamilyHardwareList { get; set; } = new List()
{
new string("ArTech"),
new string("ArTechPlana")
};
protected List AvailGlassList { get; set; } = new List()
{
new string("Vetro BE 2S 4/12/4"),
new string("Vetro BE 2S 4/16/4"),
new string("Vetro BE 3S 4/12/4/12/4"),
new string("Vetro BE 3S 4/16/4/16/4"),
new string("Vetro BE 2S 4T/12/4T"),
new string("Vetro BE 2S 4T/16/4T")
};
protected List AvailHardwareList { get; set; } = new List();
protected List AvailMaterialList { get; set; } = new List()
{
new string("Pino"),
new string("Abete")
};
protected List AvailProfileList { get; set; } = new List()
{
new string("Profilo78"),
new string("ProfiloSaomad")
};
protected Dictionary> AvailThreshold { get; set; } = new Dictionary>()
{
{"Profilo78", new List() { new Threshold(3, "Bottom"), new Threshold(1, "Threshold")}},
{"ProfiloSaomad", new List(){ new Threshold(3, "Bottom"), new Threshold(2, "BottomWaterdrip"), new Threshold(1, "Threshold")}}
};
[Inject]
protected IConfiguration Config { get; set; } = null!;
[Inject]
protected DataLayerServices DLService { get; set; } = null!;
[Inject]
protected ImageCacheService ICService { get; set; } = null!;
protected MarkupString JsonSer
{
get => (MarkupString)currJwd.Replace(Environment.NewLine, "
").Replace(" ", " ");
}
protected string SelColorMaterial { get; set; } = "";
protected string SelFamilyHardware { get; set; } = "";
protected string SelGlass { get; set; } = "";
protected string SelMaterial { get; set; } = "";
#endregion Protected Properties
#region Protected Methods
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
// JS interop or data fetches go here
isInteractive = true;
}
}
protected override async Task OnInitializedAsync()
{
ConfInit();
Random random = new Random();
CalcUid = Convert.ToString(random.Next(1000, 10000));
windowUid = CalcUid;
InitialJwd = File.ReadAllText("Data\\FinestraSplitGrid.jwd");
//initialJwd = File.ReadAllText("Data\\AntaDoppia.jwd");
currJwd = InitialJwd;
// rileggo altri dati
await ReloadData();
// preparo conf oggetti x controllo
SetupList = new BaseListPayload()
{
ColorMaterial = AvailColorMaterialList,
FamilyHardware = AvailFamilyHardwareList,
Glass = AvailGlassList,
Hardware = AvailHardwareList,
Material = AvailMaterialList,
Profile = AvailProfileList,
Threshold = AvailThreshold
};
CurrData = new LivePayload()
{
CurrJwd = InitialJwd,
SvgPreview = currSvg,
DictShape = currGroupShape,
DictOptionsXml = currHwOption
};
DLService.PipeSvg.EA_NewMessage += PipeSvg_EA_NewMessage;
DLService.PipeShape.EA_NewMessage += PipeShape_EA_NewMessage;
DLService.PipeHwOpt.EA_NewMessage += PipeHwOption_EA_NewMessage;
}
#endregion Protected Methods
#region Private Fields
private string apiUrl = "";
private string calcTag = "";
private string CalcUid = "CurrWindow";
private string windowUid = "CurrWindow";
private string cFileHardware = "Hardware/Setup.json";
private string currSvg = "";
private string GenericBasePath = "";
///
/// Semaforo x definire se sia già in modalità ionterattiva o di prerendering
///
private bool isInteractive = false;
private string outClose = "";
private string outSave = "";
private string imgBasePath = "";
private string channelHwOpt = "";
private string channelShape = "";
private string channelSvg = "";
#endregion Private Fields
#region Private Methods
///
/// Effettua chiusura oggetto con eventuale save
///
///
private void CloseObj(bool reqSave)
{
outClose = !reqSave ? "Richiesto chiusura!" : "";
outSave = reqSave ? "Richiesto salvataggio!" : "";
}
private void ConfInit()
{
apiUrl = Config.GetValue("ServerConf:Prog.ApiUrl") ?? "";
imgBasePath = Config.GetValue("ServerConf:ImageBaseUrl") ?? "";
GenericBasePath = Config.GetValue("ServerConf:GenericBaseUrl") ?? "";
calcTag = Config.GetValue("ServerConf:CalcTag") ?? "";
channelSvg = Config.GetValue("ServerConf:ChannelSvg") ?? "";
channelShape = Config.GetValue("ServerConf:ChannelShape") ?? "";
channelHwOpt = Config.GetValue("ServerConf:ChannelHwOpt") ?? "";
}
///
/// Esecuzione azione richiesta
///
/// Azione richiesta
private void DoAction(DataAction actReq)
{
switch (actReq)
{
case DataAction.None:
break;
case DataAction.ResetDictShape:
CurrData.DictShape = new Dictionary();
break;
case DataAction.ResetHwOpt:
CurrData.DictOptionsXml = new Dictionary();
break;
default:
break;
}
}
///
/// Esecuzione richiesta
///
///
///
private async Task ExecRequest(Dictionary CurrArgs)
{
// Proseguo solo se sono in interattivo (NO prerender pagina)
if (isInteractive)
{
outClose = "";
outSave = "";
// verifico se contiene JWD, lo aggiorno
if (CurrArgs.ContainsKey("SerializedData"))
{
currJwd = CurrArgs["SerializedData"];
CurrData.CurrJwd = currJwd;
}
// se il SSE variato --> invio
if (!currJwd.Equals(prevJwd) || !EgwCoreLib.Utils.DictUtils.DictAreEqual(m_CurrArgs, CurrArgs))
{
m_CurrArgs = CurrArgs;
prevJwd = currJwd;
CalcRequestDTO calcRequestDTO = new CalcRequestDTO();
calcRequestDTO.EnvType = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW;
calcRequestDTO.DictExec = m_CurrArgs;
// chiamo la chiamata POST alla API, che manda la richiesta via REDIS
await ICService.CallRestPost($"{apiUrl}/{GenericBasePath}", $"{calcTag}/{CalcUid}", calcRequestDTO);
}
}
}
private async void PipeHwOption_EA_NewMessage(object? sender, EventArgs e)
{
// aggiorno visualizzazione
PubSubEventArgs currArgs = (PubSubEventArgs)e;
// conversione on-the-fly SVG da mostrare
if (!string.IsNullOrEmpty(currArgs.newMessage))
{
if (currArgs.msgUid.StartsWith($"{channelHwOpt}:{windowUid}") && currArgs.newMessage.Length > 2)
{
// deserializzo il dizionario delle risposte...
Dictionary rawDict = JsonConvert.DeserializeObject>(currArgs.newMessage) ?? new Dictionary();
if (rawDict.Count > 0)
{
currHwOption = rawDict;
CurrData.DictOptionsXml = currHwOption;
}
}
await InvokeAsync(StateHasChanged);
}
await Task.Delay(1);
}
private async void PipeShape_EA_NewMessage(object? sender, EventArgs e)
{
// aggiorno visualizzazione
PubSubEventArgs currArgs = (PubSubEventArgs)e;
// conversione on-the-fly SVG da mostrare
if (!string.IsNullOrEmpty(currArgs.newMessage) && currArgs.newMessage.Length > 2)
{
if (currArgs.msgUid.StartsWith($"{channelShape}:{windowUid}"))
{
// deserializzo il dizionario delle risposte...
var rawDict = JsonConvert.DeserializeObject>(currArgs.newMessage);
currGroupShape = rawDict ?? new Dictionary();
CurrData.DictShape = currGroupShape;
}
await InvokeAsync(StateHasChanged);
}
await Task.Delay(1);
}
private async void PipeSvg_EA_NewMessage(object? sender, EventArgs e)
{
// aggiorno visualizzazione
PubSubEventArgs currArgs = (PubSubEventArgs)e;
// conversione on-the-fly SVG da mostrare
if (!string.IsNullOrEmpty(currArgs.newMessage))
{
if (currArgs.msgUid.Equals($"{channelSvg}:{windowUid}"))
{
currSvg = currArgs.newMessage;
CurrData.SvgPreview = currArgs.newMessage;
}
await InvokeAsync(StateHasChanged);
}
await Task.Delay(1);
}
///
/// Rilettura dati
///
///
private Task ReloadData()
{
//return base.OnInitializedAsync();
AvailHardwareList = new List();
if (File.Exists(cFileHardware))
{
string rawValHW = File.ReadAllText(cFileHardware);
var rawListHW = JsonConvert.DeserializeObject>(rawValHW) ?? new List();
foreach (var item in rawListHW)
{
AvailHardwareList.Add(item);
}
}
return Task.Delay(100);
}
#endregion Private Methods
}
}