215 lines
7.3 KiB
C#
215 lines
7.3 KiB
C#
using EgwCoreLib.Lux.Core;
|
|
using EgwCoreLib.Lux.Core.RestPayload;
|
|
using EgwCoreLib.Lux.Data.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
using System.Diagnostics;
|
|
using System.Security.AccessControl;
|
|
using Egw.Window.Data;
|
|
using WebWindowTest;
|
|
using WebWindowTest.DTO;
|
|
|
|
namespace Test.UI.Components.Pages
|
|
{
|
|
public partial class TestComponentTemplate : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
public string InitialJwd = "";
|
|
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<string, string> m_CurrArgs = new Dictionary<string, string>();
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected List<TemplateSelectDTO> AvailTemplateList { get; set; } = new List<TemplateSelectDTO>();
|
|
protected List<Hardware> AvailHardwareList { get; set; } = new List<Hardware>();
|
|
protected List<string> AvailFamilyHardwareList { get; set; } = new List<string>()
|
|
{
|
|
new string("Natura"),
|
|
new string("Optima")
|
|
};
|
|
protected List<string> AvailColorMaterialList { get; set; } = new List<string>()
|
|
{
|
|
new string("White"),
|
|
new string("Black"),
|
|
new string("Blu")
|
|
};
|
|
protected List<string> AvailMaterialList { get; set; } = new List<string>()
|
|
{
|
|
new string("Pine"),
|
|
new string("Fir")
|
|
};
|
|
protected List<string> AvailGlassList { get; set; } = new List<string>()
|
|
{
|
|
new string("4/12/4"),
|
|
new string("4/16/4"),
|
|
new string("4/12/4/12/4"),
|
|
new string("4/16/4/16/4"),
|
|
new string("4T/12/4T"),
|
|
new string("4T/16/4T")
|
|
};
|
|
protected string SelFamilyHardware { get; set; } = "";
|
|
protected string SelColorMaterial { get; set; } = "";
|
|
protected string SelMaterial { get; set; } = "";
|
|
protected string SelGlass { get; set; } = "";
|
|
|
|
[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, "<br/>").Replace(" ", " ");
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
ConfInit();
|
|
SelFamilyHardware = "Natura";
|
|
SelColorMaterial = "Black";
|
|
SelMaterial = "Pine";
|
|
SelGlass = "4T/16/4T";
|
|
DLService.PipeSvg.EA_NewMessage += PipeSvg_EA_NewMessage;
|
|
await ReloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private string apiUrl = "";
|
|
private string calcTag = "";
|
|
private string CalcUid = "CurrWindow";
|
|
private string cFileTemplate = "Data/Setup.json";
|
|
private string cFileHardware = "Hardware/Setup.json";
|
|
private TemplateSelectDTO? currSel = null;
|
|
private string currSvg = "";
|
|
|
|
private string imgBasePath = "";
|
|
private string GenericBasePath = "";
|
|
|
|
private string subChannel = "";
|
|
|
|
private string windowUid = "CurrWindow";
|
|
|
|
#endregion Private Fields
|
|
|
|
#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<string>("ServerConf:Prog.ApiUrl") ?? "";
|
|
imgBasePath = Config.GetValue<string>("ServerConf:ImageBaseUrl") ?? "";
|
|
GenericBasePath = Config.GetValue<string>("ServerConf:GenericBaseUrl") ?? "";
|
|
calcTag = Config.GetValue<string>("ServerConf:CalcTag") ?? "";
|
|
subChannel = Config.GetValue<string>("ServerConf:SvgChannel") ?? "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Rilettura dati
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task ReloadData()
|
|
{
|
|
//return base.OnInitializedAsync();
|
|
AvailTemplateList = new List<TemplateSelectDTO>();
|
|
AvailHardwareList = new List<Hardware>();
|
|
// brutale, da rivedere...
|
|
if(string.IsNullOrEmpty(InitialJwd))
|
|
{
|
|
if (File.Exists(cFileTemplate))
|
|
{
|
|
string rawVal = File.ReadAllText(cFileTemplate);
|
|
var rawList = JsonConvert.DeserializeObject<List<TemplateSelectDTO>>(rawVal) ?? new List<TemplateSelectDTO>();
|
|
|
|
// calcolo URL immagini... DTO interno da rivedere?
|
|
foreach (var item in rawList)
|
|
{
|
|
item.ImageUrl = ICService.ImageUrl($"{apiUrl}/{imgBasePath}", false, item.SVGFileName);
|
|
AvailTemplateList.Add(item);
|
|
}
|
|
}
|
|
}
|
|
if (File.Exists(cFileHardware))
|
|
{
|
|
string rawValHW = File.ReadAllText(cFileHardware);
|
|
var rawListHW = JsonConvert.DeserializeObject<List<Hardware>>(rawValHW) ?? new List<Hardware>();
|
|
foreach (var item in rawListHW)
|
|
{
|
|
AvailHardwareList.Add(item);
|
|
}
|
|
}
|
|
await Task.Delay(100);
|
|
}
|
|
|
|
private async Task SaveJWD(Dictionary<string, string> CurrArgs)
|
|
{
|
|
m_CurrArgs = CurrArgs;
|
|
// chiamo la chiamata POST alla API, che manda la richiesta via REDIS
|
|
if (currJwd != 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,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
|
|
}
|
|
} |