Files
mapo-mono/MP.MONO.UI/Components/AlarmsOverview.razor.cs
T
2022-03-07 12:37:24 +01:00

88 lines
2.9 KiB
C#

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<DisplayDataDTO>? ListRecords { get; set; } = new List<DisplayDataDTO>();
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<DisplayDataDTO>();
}
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<DisplayDataDTO>();
}
ListRecords.Add(newRec);
ListRecords = ListRecords.OrderByDescending(x => x.Order).ToList();
}
#endif
// conversione on-the-fly List<string> --> allarmi
if (!string.IsNullOrEmpty(currArgs.newMessage))
{
try
{
var alarmList = JsonConvert.DeserializeObject<List<string>>(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);
}
}
}