using EgwCoreLib.Lux.Core;
using EgwCoreLib.Lux.Core.RestPayload;
using EgwCoreLib.Lux.Data.Services;
using Microsoft.AspNetCore.Components;
using Newtonsoft.Json;
namespace Test.UI.Components.Pages
{
public partial class Aedifica : IDisposable
{
private string channelSub = "";
private string CalcUid = "TestBeam";
private string currSvg = "";
private string apiUrl = "";
private string calcTag = "";
private string GenericBasePath = "";
[Inject]
protected IConfiguration Config { get; set; } = null!;
[Inject]
protected DataLayerServices DLService { get; set; } = null!;
[Inject]
protected ImageCacheService ICService { get; set; } = null!;
public void Dispose()
{
DLService.PipeSvg.EA_NewMessage -= PipeSvg_EA_NewMessage;
}
protected MarkupString JsonSer
{
get => (MarkupString)currSvg.Replace(Environment.NewLine, "
").Replace(" ", " ");
}
protected Dictionary m_CurrArgs = new Dictionary();
protected override Task OnInitializedAsync()
{
ConfInit();
DLService.PipeSvg.EA_NewMessage += PipeSvg_EA_NewMessage;
//await ReloadData();
return Task.Delay(1);
}
private void ConfInit()
{
apiUrl = Config.GetValue("ServerConf:Prog.ApiUrl") ?? "";
GenericBasePath = Config.GetValue("ServerConf:GenericBaseUrl") ?? "";
//imgTag = Config.GetValue("ServerConf:ImageFileTag") ?? "";
calcTag = Config.GetValue("ServerConf:CalcTag") ?? "";
channelSub = Config.GetValue("ServerConf:ChannelSvg") ?? "";
}
private async Task SendBtlRequest(Dictionary CurrArgs)
{
m_CurrArgs = CurrArgs;
// chiamo la chiamata POST alla API, che manda la richiesta via REDIS
if (m_CurrArgs != null)
{
CalcRequestDTO calcRequestDTO = new CalcRequestDTO();
calcRequestDTO.EnvType = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.BEAM;
calcRequestDTO.DictExec = m_CurrArgs;
await ICService.CallRestPost($"{apiUrl}/{GenericBasePath}", $"{calcTag}/{CalcUid}", calcRequestDTO);
}
}
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($"{channelSub}:{CalcUid}"))
{
currSvg = currArgs.newMessage;
}
await InvokeAsync(StateHasChanged);
}
await Task.Delay(1);
}
}
}