Files
webwindowconfigurator/Test.UI/Components/Pages/TestComponent.razor.cs
T

111 lines
3.1 KiB
C#

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<TemplateSelectDTO> AvailTemplateList { get; set; } = new List<TemplateSelectDTO>();
protected MarkupString JsonSer
{
get => (MarkupString)currJwd.Replace(Environment.NewLine, "<br/>").Replace(" ", "&nbsp;");
}
#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<string>("ServerConf:ImageBaseUrl") ?? "";
imgTag = Config.GetValue<string>("ServerConf:ImageFileTag") ?? "";
}
/// <summary>
/// Rilettura dati
/// </summary>
/// <returns></returns>
private async Task ReloadData()
{
//return base.OnInitializedAsync();
AvailTemplateList = new List<TemplateSelectDTO>();
await Task.Delay(100);
// brutale, da rivedere...
if (File.Exists(cFile))
{
string rawVal = File.ReadAllText(cFile);
var rawList = JsonConvert.DeserializeObject<List<TemplateSelectDTO>>(rawVal) ?? new List<TemplateSelectDTO>();
// 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
}
}