using EgwCoreLib.Lux.Core; using EgwCoreLib.Lux.Core.RestPayload; using EgwCoreLib.Lux.Data.Services; using Microsoft.AspNetCore.Components; using Newtonsoft.Json; using WebWindowConfigurator; using WebWindowConfigurator.DTO; namespace Test.UI.Components.Pages { public partial class Home : IDisposable { #region Public Properties public Template SelTemplate { get; set; } = new Template(0, "---SELECT---", "", ""); #endregion Public Properties #region Public Methods public void Dispose() { DLService.PipeSvg.EA_NewMessage -= PipeSvg_EA_NewMessage; } #endregion Public Methods #region Protected Fields protected string currJwd = ""; protected Dictionary m_CurrArgs = new Dictionary(); #endregion Protected Fields #region Protected Properties protected List AvailTemplateList { get; set; } = new List(); [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 { string outVal = currJwd; return (MarkupString)outVal.Replace(Environment.NewLine, "
").Replace(" ", " "); } } #endregion Protected Properties #region Protected Methods protected override async Task OnInitializedAsync() { isLoading = true; ConfInit(); DLService.PipeSvg.EA_NewMessage += PipeSvg_EA_NewMessage; await ReloadData(); } private bool isLoading = false; #endregion Protected Methods #region Private Fields private string apiUrl = ""; private string calcTag = ""; private string CalcUid = "CurrWindow"; private string cFile = "Data/Setup.json"; private TemplateSelectDTO? currSel = null; private string currSvg = ""; private string imgBasePath = ""; private string GenericBasePath = ""; private string subChannel = ""; #endregion Private Fields #region Private Properties private string windowUid = "CurrWindow"; //{ // get // { // string answ = ""; // if (currSel != null) // { // answ = currSel.SVGFileName.Replace(".svg", ""); // } // return answ; // } //} #endregion Private Properties #region Private Methods 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($"{subChannel}:{windowUid}")) { currSvg = currArgs.newMessage; } await InvokeAsync(StateHasChanged); } await Task.Delay(1); } private void ConfInit() { apiUrl = Config.GetValue("ServerConf:Prog.ApiUrl") ?? ""; imgBasePath = Config.GetValue("ServerConf:ImageBaseUrl") ?? ""; GenericBasePath = Config.GetValue("ServerConf:GenericBaseUrl") ?? ""; calcTag = Config.GetValue("ServerConf:CalcTag") ?? ""; subChannel = Config.GetValue("ServerConf:SvgChannel") ?? ""; } /// /// Rilettura dati /// /// private async Task ReloadData() { //return base.OnInitializedAsync(); AvailTemplateList = new List(); await Task.Delay(100); // brutale, da rivedere... if (File.Exists(cFile)) { string rawVal = File.ReadAllText(cFile); var rawList = JsonConvert.DeserializeObject>(rawVal) ?? new List(); // calcolo URL immagini... DTO interno da rivedere? foreach (var item in rawList) { item.ImageUrl = ICService.ImageUrl($"{apiUrl}/{imgBasePath}", false, item.SVGFileName); //item.ImageUrl = ICService.ImageUrl(imgBasePath, false, item.SVGFileName); AvailTemplateList.Add(item); } } isLoading = false; } private async Task SaveJWD(Dictionary CurrArgs) { m_CurrArgs = CurrArgs; // chiamo la chiamata POST alla API, che manda la richiesta via REDIS if (currSel != null) { CalcRequestDTO calcRequestDTO = new CalcRequestDTO(); calcRequestDTO.EnvType = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW; calcRequestDTO.DictExec = m_CurrArgs; await ICService.CallRestPost($"{apiUrl}/{GenericBasePath}", $"{calcTag}/{CalcUid}", calcRequestDTO); } } private void SetTemplate(TemplateSelectDTO selTemp) { string rawVal = ""; currSel = selTemp; // brutale, da rivedere... if (File.Exists(selTemp.JwdFileName)) { rawVal = File.ReadAllText(selTemp.JwdFileName); } SelTemplate = new Template(selTemp.Index, selTemp.Description, selTemp.SVGFileName, rawVal); } #endregion Private Methods } }