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; namespace MP.MONO.UI.Components { public partial class AlarmsOverview { private List? ListRecords { get; set; } = new List(); protected override async Task OnInitializedAsync() { await ReloadData(); MMDataService.alarmPipe.EA_NewMessage += AlarmPipe_EA_NewMessage; } private void AlarmPipe_EA_NewMessage(object? sender, EventArgs e) { PubSubEventArgs currArgs = (PubSubEventArgs)e; #if false if (currArgs.newMessage == "reset") { ListRecords = new List(); } else { DisplayDataDTO newRec = new DisplayDataDTO() { Title = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}", Value = currArgs.newMessage, IsNumeric = false, Order = ListRecords == null ? 0 : ListRecords.Count }; if (ListRecords == null) { ListRecords = new List(); } ListRecords.Add(newRec); ListRecords = ListRecords.OrderByDescending(x => x.Order).ToList(); } #endif // conversione on-the-fly List --> allarmi if (!string.IsNullOrEmpty(currArgs.newMessage)) { try { var alarmList = JsonConvert.DeserializeObject>(currArgs.newMessage); ListRecords = alarmList.Select(x => new DisplayDataDTO() { IsNumeric = false, Title = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}", Value = x, Order = ListRecords == null ? 0 : ListRecords.Count }).ToList(); } catch { } } InvokeAsync(() => { StateHasChanged(); }); } protected async Task ReloadData() { //await Task.Delay(10); //ListRecords = await MMDataService.MachineDisplay(); await Task.Delay(500); } } }