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; // 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() { var alarmList = await MMDataService.getAlarms(); 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(); } } }