353 lines
13 KiB
C#
353 lines
13 KiB
C#
using EgwCoreLib.Lux.Core;
|
|
using EgwCoreLib.Lux.Core.RestPayload;
|
|
using EgwCoreLib.Lux.Data.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Newtonsoft.Json;
|
|
using WebWindowConfigurator;
|
|
using WebWindowComplex;
|
|
using Egw.Window.Data;
|
|
using WebWindowComplex.DTO;
|
|
using WebWindowConfigurator.DTO;
|
|
|
|
namespace Test.UI.Components.Pages
|
|
{
|
|
public partial class Home : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
public Template SelTemplate { get; set; } = new Template(0, "", "", "") ;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
DLService.PipeSvg.EA_NewMessage -= PipeSvg_EA_NewMessage;
|
|
DLService.PipeShape.EA_NewMessage -= PipeShape_EA_NewMessage;
|
|
DLService.PipeHwOpt.EA_NewMessage -= PipeHwOption_EA_NewMessage;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
protected Dictionary<int, string> currGroupShape = new Dictionary<int, string>();
|
|
protected Dictionary<int, string> currHwOption = new Dictionary<int, string>();
|
|
protected string currJwd = "";
|
|
protected Dictionary<string, string> m_CurrArgs = new Dictionary<string, string>();
|
|
protected string prevJwd = "";
|
|
|
|
/// <summary>
|
|
/// Configurazione elenchi anagrafiche
|
|
/// </summary>
|
|
protected BaseListPayload SetupList = new BaseListPayload();
|
|
|
|
/// <summary>
|
|
/// Predisposizione valori live SVG/JWD
|
|
/// </summary>
|
|
protected LivePayload CurrData = new LivePayload();
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected List<TemplateSelectDTO> AvailTemplateList { get; set; } = new List<TemplateSelectDTO>();
|
|
|
|
protected List<string> AvailColorMaterialList { get; set; } = new List<string>()
|
|
{
|
|
new string("White"),
|
|
new string("Black"),
|
|
new string("Blu")
|
|
};
|
|
|
|
protected List<string> AvailFamilyHardwareList { get; set; } = new List<string>()
|
|
{
|
|
new string("ArTech"),
|
|
new string("ArTechPlana")
|
|
};
|
|
|
|
protected List<string> AvailGlassList { get; set; } = new List<string>()
|
|
{
|
|
new string("Vetro BE 2S 4/12/4"),
|
|
new string("Vetro BE 2S 4/16/4"),
|
|
new string("Vetro BE 3S 4/12/4/12/4"),
|
|
new string("Vetro BE 3S 4/16/4/16/4"),
|
|
new string("Vetro BE 2S 4T/12/4T"),
|
|
new string("Vetro BE 2S 4T/16/4T")
|
|
};
|
|
|
|
protected List<Hardware> AvailHardwareList { get; set; } = new List<Hardware>();
|
|
|
|
protected List<string> AvailMaterialList { get; set; } = new List<string>()
|
|
{
|
|
new string("Pino"),
|
|
new string("Abete")
|
|
};
|
|
|
|
[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, "<br/>").Replace(" ", " ");
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override void OnAfterRender(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
// JS interop or data fetches go here
|
|
isInteractive = true;
|
|
}
|
|
}
|
|
protected override Task OnInitializedAsync()
|
|
{
|
|
ConfInit();
|
|
Random random = new Random();
|
|
CalcUid = Convert.ToString(random.Next(1000, 10000));
|
|
windowUid = CalcUid;
|
|
DLService.PipeSvg.EA_NewMessage += PipeSvg_EA_NewMessage;
|
|
DLService.PipeShape.EA_NewMessage += PipeShape_EA_NewMessage;
|
|
DLService.PipeHwOpt.EA_NewMessage += PipeHwOption_EA_NewMessage;
|
|
return ReloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private string apiUrl = "";
|
|
private string calcTag = "";
|
|
private string CalcUid = "CurrWindow";
|
|
private string cFileTemplate = "Data/Setup.json";
|
|
private TemplateSelectDTO? currSel = null;
|
|
private string currSvg = "";
|
|
private string channelHwOpt = "";
|
|
private string channelShape = "";
|
|
private string channelSvg = "";
|
|
|
|
private string imgBasePath = "";
|
|
private string GenericBasePath = "";
|
|
|
|
private string cFileHardware = "Hardware/Setup.json";
|
|
|
|
private string outClose = "";
|
|
private string outSave = "";
|
|
|
|
private string windowUid = "CurrWindow";
|
|
|
|
/// <summary>
|
|
/// Semaforo x definire se sia già in modalità ionterattiva o di prerendering
|
|
/// </summary>
|
|
private bool isInteractive = false;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Effettua chiusura oggetto con eventuale save
|
|
/// </summary>
|
|
/// <param name="reqSave"></param>
|
|
private void CloseObj(DataSave reqSave)
|
|
{
|
|
currJwd = reqSave.currJwd;
|
|
outClose = !reqSave.ForceSave ? "Richiesto chiusura!" : "";
|
|
outSave = reqSave.ForceSave ? "Richiesto salvataggio!" : "";
|
|
}
|
|
|
|
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") ?? "";
|
|
channelSvg = Config.GetValue<string>("ServerConf:ChannelSvg") ?? "";
|
|
channelShape = Config.GetValue<string>("ServerConf:ChannelShape") ?? "";
|
|
channelHwOpt = Config.GetValue<string>("ServerConf:ChannelHwOpt") ?? "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esecuzione azione richiesta
|
|
/// </summary>
|
|
/// <param name="actReq">Azione richiesta</param>
|
|
private void DoAction(LayoutConst.DataAction actReq)
|
|
{
|
|
switch (actReq)
|
|
{
|
|
case LayoutConst.DataAction.None:
|
|
break;
|
|
|
|
case LayoutConst.DataAction.ResetDictShape:
|
|
CurrData.DictShape = new Dictionary<int, string>();
|
|
break;
|
|
|
|
case LayoutConst.DataAction.ResetHwOpt:
|
|
CurrData.DictOptionsXml = new Dictionary<int, string>();
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
private async Task ExecRequest(Dictionary<string, string> CurrArgs)
|
|
{
|
|
// Proseguo solo se sono in interattivo (NO prerender pagina)
|
|
if (isInteractive)
|
|
{
|
|
outClose = "";
|
|
outSave = "";
|
|
// verifico se contiene JWD, lo aggiorno
|
|
if (CurrArgs.ContainsKey("SerializedData"))
|
|
{
|
|
currJwd = CurrArgs["SerializedData"];
|
|
CurrData.CurrJwd = currJwd;
|
|
}
|
|
// se il SSE variato --> invio
|
|
if (!currJwd.Equals(prevJwd) || !EgwCoreLib.Utils.DictUtils.DictAreEqual(m_CurrArgs, CurrArgs))
|
|
{
|
|
m_CurrArgs = CurrArgs;
|
|
prevJwd = currJwd;
|
|
CalcRequestDTO calcRequestDTO = new CalcRequestDTO();
|
|
calcRequestDTO.EnvType = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW;
|
|
calcRequestDTO.DictExec = m_CurrArgs;
|
|
// chiamo la chiamata POST alla API, che manda la richiesta via REDIS
|
|
await ICService.CallRestPost($"{apiUrl}/{GenericBasePath}", $"{calcTag}/{CalcUid}", calcRequestDTO);
|
|
}
|
|
}
|
|
}
|
|
|
|
private async void PipeHwOption_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.StartsWith($"{channelHwOpt}:{windowUid}") && currArgs.newMessage.Length > 2)
|
|
{
|
|
// deserializzo il dizionario delle risposte...
|
|
Dictionary<int, string> rawDict = JsonConvert.DeserializeObject<Dictionary<int, string>>(currArgs.newMessage) ?? new Dictionary<int, string>();
|
|
if (rawDict.Count > 0)
|
|
{
|
|
currHwOption = rawDict;
|
|
CurrData.DictOptionsXml = currHwOption;
|
|
}
|
|
}
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
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($"{channelSvg}:{windowUid}"))
|
|
{
|
|
currSvg = currArgs.newMessage;
|
|
CurrData.SvgPreview = currArgs.newMessage;
|
|
}
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
private async void PipeShape_EA_NewMessage(object? sender, EventArgs e)
|
|
{
|
|
// aggiorno visualizzazione
|
|
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
|
// conversione on-the-fly SVG da mostrare
|
|
if (!string.IsNullOrEmpty(currArgs.newMessage) && currArgs.newMessage.Length > 2)
|
|
{
|
|
if (currArgs.msgUid.StartsWith($"{channelShape}:{windowUid}"))
|
|
{
|
|
// deserializzo il dizionario delle risposte...
|
|
var rawDict = JsonConvert.DeserializeObject<Dictionary<int, string>>(currArgs.newMessage);
|
|
currGroupShape = rawDict ?? new Dictionary<int, string>();
|
|
CurrData.DictShape = currGroupShape;
|
|
}
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Rilettura dati
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task ReloadData()
|
|
{
|
|
// Caricamento lista Template
|
|
AvailTemplateList = new List<TemplateSelectDTO>();
|
|
await Task.Delay(100);
|
|
// brutale, da rivedere...
|
|
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);
|
|
//item.ImageUrl = ICService.ImageUrl(imgBasePath, false, item.SVGFileName);
|
|
AvailTemplateList.Add(item);
|
|
}
|
|
}
|
|
// Caricamento lista hardware
|
|
AvailHardwareList = new List<Hardware>();
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
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);
|
|
CurrData.CurrJwd = rawVal;
|
|
SetupList = new BaseListPayload()
|
|
{
|
|
ColorMaterial = AvailColorMaterialList,
|
|
FamilyHardware = AvailFamilyHardwareList,
|
|
Glass = AvailGlassList,
|
|
Hardware = AvailHardwareList,
|
|
Wood = AvailMaterialList
|
|
};
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |