Files
mapo-mono/MP.MONO.UI/Components/CmpTop.razor.cs
T
2022-03-07 12:06:41 +01:00

58 lines
1.7 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 CmpTop
{
private MachineDTO? currStatus { 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<MachineDTO>(currArgs.newMessage);
}
catch
{ }
}
InvokeAsync(() =>
{
StateHasChanged();
});
}
protected async Task ReloadData()
{
await Task.Delay(1);
currStatus = await MMDataService.MachineStatus();
await Task.Delay(1);
}
}
}