using EgwCoreLib.Lux.Data.Services; using Microsoft.AspNetCore.Components; using Newtonsoft.Json; using NLog; using WebWindowConfigurator; using WebWindowConfigurator.DTO; namespace Test.UI.Components.Pages { public partial class TestComponent { #region Public Properties public Template SelTemplate { get; set; } = new Template(0, "---SELECT---", "", ""); #endregion Public Properties #region Protected Fields protected string currJwd = "..."; #endregion Protected Fields #region Protected Properties protected List AvailTemplateList { get; set; } = new List(); protected MarkupString JsonSer { get => (MarkupString)currJwd.Replace(Environment.NewLine, "
").Replace(" ", " "); } #endregion Protected Properties #region Protected Methods protected override async Task OnInitializedAsync() { ConfInit(); await ReloadData(); } [Inject] protected IConfiguration Config { get; set; } = null!; [Inject] protected ImageCacheService ImgService { get; set; } = null!; private string imgBasePath = ""; private string imgTag = ""; private void ConfInit() { imgBasePath = Config.GetValue("ServerConf:ImageBaseUrl") ?? ""; imgTag = Config.GetValue("ServerConf:ImageFileTag") ?? ""; } /// /// 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 = ImgService.ImageUrl(imgBasePath, false, item.SVGFileName); AvailTemplateList.Add(item); } } } #endregion Protected Methods #region Private Fields private string cFile = "Data/Setup.json"; #endregion Private Fields #region Private Methods private void SaveJWD(string newSerial) { currJwd = newSerial; } private void SetTemplate(TemplateSelectDTO selTemp) { string rawVal = ""; // brutale,d a rivedere... if (File.Exists(selTemp.JwdFileName)) { rawVal = File.ReadAllText(selTemp.JwdFileName); } SelTemplate = new Template(selTemp.Index, selTemp.Description, selTemp.SVGFileName, rawVal); } #endregion Private Methods } }