using Egw.Window.Data; using EgwCoreLib.Lux.Core; using EgwCoreLib.Lux.Core.RestPayload; using EgwCoreLib.Lux.Data.DbModel.Config; using EgwCoreLib.Lux.Data.DbModel.Utils; using EgwCoreLib.Lux.Data.Services; using EgwCoreLib.Lux.Data.Services.Config; using EgwCoreLib.Lux.Data.Services.Utils; using Microsoft.AspNetCore.Components; using Newtonsoft.Json; using WebWindowComplex; using WebWindowComplex.DTO; using static WebWindowComplex.LayoutConst; namespace Test.UI.Components.Pages { public partial class EditJWD : IDisposable { #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; DLService.PipeProfElement.EA_NewMessage -= PipeProfElement_EA_NewMessage; } #endregion Public Methods #region Protected Fields /// /// Configurazione elenchi anagrafiche /// protected BaseListPayload SetupList = new BaseListPayload(); /// /// Dizionario richieste pendenti /// protected Dictionary DictPendReq = new(); /// /// Livello di accesso /// -- true: utente base (versione semplificata) /// -- false: utente avanzato (versione completa) /// protected bool User = false; #endregion Protected Fields #region Protected Properties protected MarkupString JsonSer { get => (MarkupString)currJwd.Replace(Environment.NewLine, "
").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 async Task OnInitializedAsync() { ConfInit(); await ReloadBaseList(); User = false; Random random = new Random(); CalcUid = Convert.ToString(random.Next(1000, 10000)); windowUid = CalcUid; currJwd = initialJwd; // rileggo altri dati //await ReloadData(); // converto i profili nel nuovo formato x payload... var profList = AvailProfileList.Select(x => new ProfilePayload() { ProfileName = x.Code, ThresholdList = x.ThresholdList, ParameterDict = x.ProfileDataDict }).ToList(); // preparo conf oggetti x controllo SetupList = new BaseListPayload() { ColorMaterial = AvailColorMaterialList, FamilyHardware = AvailFamilyHardwareList, Glass = AvailGlassList, Hardware = AvailHardwareList, Wood = AvailWoodList, ProfileList = profList }; CurrData = new LivePayload() { CurrJwd = currJwd, SvgPreview = currSvg, DictShape = currGroupShape, DictOptionsXml = currHwOption }; DescriptionProfileList = profList.Select(x => x.ProfileName).ToList(); DLService.PipeSvg.EA_NewMessage += PipeSvg_EA_NewMessage; DLService.PipeShape.EA_NewMessage += PipeShape_EA_NewMessage; DLService.PipeHwOpt.EA_NewMessage += PipeHwOption_EA_NewMessage; DLService.PipeProfElement.EA_NewMessage += PipeProfElement_EA_NewMessage; } #endregion Protected Methods #region Private Properties [Inject] private ConfigDataService CDService { get; set; } = default!; [Inject] private IConfGlassService CGService { get; set; } = null!; [Inject] private IConfProfileService CPService { get; set; } = null!; [Inject] private IConfWoodService CWService { get; set; } = null!; [Inject] private IGenValService GVService { get; set; } = default!; [Inject] private IConfiguration Config { get; set; } = null!; [Inject] private DataLayerServices DLService { get; set; } = null!; [Inject] private ImageCacheService ICService { get; set; } = null!; private string SelColorMaterial { get; set; } = ""; private string SelFamilyHardware { get; set; } = ""; private string SelGlass { get; set; } = ""; private string SelWood { get; set; } = ""; #endregion Private Properties #region Private Fields private List AllConfGlass = new(); private List AllColors = new(); private List AllConfHardware = new(); private List AllConfWood = new(); private List AvailColorMaterialList = new List(); private List AvailFamilyHardwareList = new List(); private List AvailGlassList = new List(); private List AvailHardwareList = new(); private List AvailWoodList = new List(); private List AvailProfileList = new(); private List DescriptionProfileList = new(); private EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS cEnvir = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW; /// /// Predisposizione valori live SVG/JWD /// private LivePayload CurrData = new LivePayload(); private List currElement = new List(); private Dictionary currGroupShape = new Dictionary(); private Dictionary currHwOption = new Dictionary(); private string currJwd = "..."; private Dictionary m_CurrArgs = new Dictionary(); private string prevJwd = ""; private string apiUrl = ""; ///// ///// Lista profili da DB ///// //private List AvailProfileList = new List(); private string calcTag = ""; private string CalcUid = "CurrWindow"; private string cFileHardware = "Hardware/Setup.json"; private string channelHwOpt = ""; private string channelProfElem = ""; private string channelProfList = ""; private string channelShape = ""; private string channelSvg = ""; private string currSvg = ""; private bool doEdit = false; private string GenericBasePath = ""; private string imgBasePath = ""; /// /// Semaforo x definire se sia già in modalità ionterattiva o di prerendering /// private bool isInteractive = false; private string colorMassUpdate; private string familyHWMassUpdate; private string glassMassUpdate; private Hardware hardwareMassUpdate; private string woodMassUpdate; private string profileMassUpdate; private string outClose = ""; private string outSave = ""; private bool startEmpty = true; private string windowUid = "CurrWindow"; #endregion Private Fields #region Private Properties private string initialJwd { get { if (startEmpty) { return "{}"; } else { string fullPath = Path.Combine("Data", "AntaDoppia.jwd"); return File.ReadAllText(fullPath); //return File.ReadAllText("Data\\AntaDoppiaInglesine.jwd"); } } } #endregion Private Properties #region Private Methods /// /// Init classi configurazione /// /// private async Task ReloadBaseList() { // lettura config setup varie da DB/Cache Redis AllConfGlass = await CGService.GetAllAsync(); AvailProfileList = await CPService.GetAllAsync(); // FixMe Todo: eliminare da REDIS e usare elenco DB solamente... var rawProfiles = CDService.ProfileList(cEnvir, "Default"); // se fosse vuoto chiamo update... if (rawProfiles == null || rawProfiles.Count == 0) { rawProfiles = CDService.ProfileList(cEnvir, "Default"); } var rawHw = CDService.HwModelList(cEnvir, "HW.AGB"); // hw filtro solo validi... AllConfHardware = rawHw .Where(x => !x.FamilyName.Equals(x.Description, StringComparison.OrdinalIgnoreCase)) .ToList(); AllConfWood = await CWService.GetAllAsync(); AllColors = await GVService.GetFiltAsync("WoodCol"); // conversione tipi AvailGlassList = AllConfGlass .Select(x => x.Description) .ToList(); AvailFamilyHardwareList = AllConfHardware .DistinctBy(x => x.FamilyName) .OrderBy(x => x.FamilyName) .Select(x => x.FamilyName) .ToList(); AvailHardwareList = AllConfHardware .Select(x => new Egw.Window.Data.Hardware(x.Id, x.FamilyName, x.Description, x.OpeningType, x.Shape, x.SashQty, x.SashPosition)) .ToList(); AvailWoodList = AllConfWood .Select(x => x.Description) .ToList(); AvailColorMaterialList = AllColors .OrderBy(x => x.Index) .Select(x => x.ValString) .ToList(); } /// /// Effettua chiusura oggetto con eventuale save /// /// private void CloseObj(DataSave reqSave) { currJwd = reqSave.ForceSave ? reqSave.currJwd : initialJwd; outClose = !reqSave.ForceSave ? "Richiesto Close!" : ""; outSave = reqSave.ForceSave ? "Richiesto Close + Save!" : ""; doEdit = false; } private void PendAction(Dictionary args) { } private void ConfInit() { apiUrl = Config.GetValue("ServerConf:Prog.ApiUrl") ?? ""; imgBasePath = Config.GetValue("ServerConf:ImageBaseUrl") ?? ""; GenericBasePath = Config.GetValue("ServerConf:GenericBaseUrl") ?? ""; calcTag = Config.GetValue("ServerConf:CalcTag") ?? ""; channelSvg = Config.GetValue("ServerConf:ChannelSvg") ?? ""; channelShape = Config.GetValue("ServerConf:ChannelShape") ?? ""; channelHwOpt = Config.GetValue("ServerConf:ChannelHwOpt") ?? ""; channelProfElem = Config.GetValue("ServerConf:ChannelProfElem") ?? ""; channelProfList = Config.GetValue("ServerConf:ChannelProfList") ?? ""; } /// /// Esecuzione azione richiesta /// /// Azione richiesta private void DoAction(DataAction actReq) { switch (actReq) { case DataAction.None: break; case DataAction.ResetDictShape: CurrData.DictShape = new Dictionary(); break; case DataAction.ResetHwOpt: CurrData.DictOptionsXml = new Dictionary(); break; case DataAction.ResetDimElem: CurrData.ProfElementList = new List(); break; default: break; } } /// /// Esecuzione richiesta /// /// /// private async Task ExecRequest(Dictionary 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 rawDict = JsonConvert.DeserializeObject>(currArgs.newMessage) ?? new Dictionary(); if (rawDict.Count > 0) currHwOption = rawDict; } else { currHwOption = new Dictionary(); } CurrData.DictOptionsXml = currHwOption; await InvokeAsync(StateHasChanged); } await Task.Delay(1); } private async void PipeProfElement_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($"{channelProfElem}:{windowUid}")) { // deserializzo il dizionario delle risposte... var rawDict = JsonConvert.DeserializeObject>(currArgs.newMessage); currElement = rawDict ?? new List(); CurrData.ProfElementList = currElement; } 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>(currArgs.newMessage); currGroupShape = rawDict ?? new Dictionary(); CurrData.DictShape = currGroupShape; } 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 void SetEdit(Microsoft.AspNetCore.Components.Web.MouseEventArgs args) { doEdit = true; } private Task ToggleJwd() { startEmpty = !startEmpty; currJwd = initialJwd; currSvg = ""; CurrData.CurrJwd = currJwd; CurrData.SvgPreview = currSvg; return InvokeAsync(StateHasChanged); } private async Task UpdateInfoJwdAsync(string currSer, string? newFamilyHardware, string? newColorMaterial, string? newWood, string? newGlass, string? newProfile) { Dictionary DictParam = new Dictionary(); if (!string.IsNullOrEmpty(newFamilyHardware)) DictParam.Add("FamilyHardware", newFamilyHardware!); if (!string.IsNullOrEmpty(newColorMaterial)) DictParam.Add("Color", newColorMaterial!); if (!string.IsNullOrEmpty(newWood)) DictParam.Add("Wood", newWood!); if (!string.IsNullOrEmpty(newGlass)) DictParam.Add("Glass", newGlass!); if (!string.IsNullOrEmpty(newProfile)) DictParam.Add("Profile", newProfile!); var dp = SerialMan.MassUpdate(currSer, DictParam); CurrData.CurrJwd = dp.serializeStruct; if (dp.DictParameter.Count > 0) DictPendReq = DictParam; //var newJwd = SerialMan.MassUpdate(currSer, newFamilyHardware, newHardware, newColorMaterial, newMaterial, newGlass, newProfile); //CurrData.CurrJwd = newJwd; } #endregion Private Methods } }