using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Components; using System.Net.Http; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Forms; using Microsoft.AspNetCore.Components.Routing; using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.Web.Virtualization; using Microsoft.JSInterop; using MP.MONO.Core.DTO; using MP.MONO.Data; using MP.MONO.UI; using MP.MONO.UI.Shared; using MP.MONO.UI.Components; using MP.MONO.UI.Data; using Newtonsoft.Json; using MP.MONO.Core.CONF; namespace MP.MONO.UI.Components { public partial class CmpTop { private MachineDTO? currStatus { get; set; } = null; private List statusList = new List(); private List modeList = new List(); private MachineStatus? selStatus = null; private MachineMode? selMode = null; [Inject] protected CurrentDataService MMDataService { get; set; } = null!; protected override async Task OnInitializedAsync() { await ReloadData(); MMDataService.statusPipe.EA_NewMessage += StatusPipe_EA_NewMessage; } private void StatusPipe_EA_NewMessage(object? sender, EventArgs e) { PubSubEventArgs currArgs = (PubSubEventArgs)e; if (!string.IsNullOrEmpty(currArgs.newMessage)) { try { currStatus = JsonConvert.DeserializeObject(currArgs.newMessage); // recupero status e mode corrente... if (currStatus != null) { selStatus = statusList.Where(x => x.MStatusID == currStatus.StatusId).FirstOrDefault(); selMode = modeList.Where(x => x.MModeID == currStatus.ModeId).FirstOrDefault(); } } catch { } } InvokeAsync(() => { StateHasChanged(); }); } protected async Task ReloadData() { statusList = await MMDataService.getStatusList(); modeList = await MMDataService.getModesList(); currStatus = await MMDataService.getStatus(); if (currStatus != null) { selStatus = statusList.Where(x => x.MStatusID == currStatus.StatusId).FirstOrDefault(); selMode = modeList.Where(x => x.MModeID == currStatus.ModeId).FirstOrDefault(); } } protected string statusDesc { get => selStatus != null ? selStatus.Description : "ND"; } protected string statusCss { get => selStatus != null ? selStatus.Css : "ND"; } protected string modeDesc { get => selMode != null ? selMode.Description : "ND"; } protected string modeCss { get => selMode != null ? selMode.Css : "ND"; } } }