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.SPEC; using MP.SPEC.Shared; using MP.SPEC.Components; using MP.Data; using Newtonsoft.Json; using MP.SPEC.Data; namespace MP.SPEC.Pages { public partial class Test : IDisposable { [Inject] protected MpDataService MMDataService { get; set; } = null!; protected string messaggio = "0"; protected DateTime lastRec = DateTime.Now.AddMinutes(-1); private void BroadCastMsg_EA_NewMessage(object? sender, EventArgs e) { DateTime adesso = DateTime.Now; if (lastRec.AddSeconds(2) < adesso) { PubSubEventArgs currArgs = (PubSubEventArgs)e; if (!string.IsNullOrEmpty(currArgs.newMessage)) { lastRec = adesso; try { var result = JsonConvert.DeserializeObject(currArgs.newMessage); if(result != null) { messaggio = result; } } catch { } InvokeAsync(() => { StateHasChanged(); }); } } } public void Dispose() { MMDataService.BroadastMsgPipe.EA_NewMessage += BroadCastMsg_EA_NewMessage; } protected override async Task OnInitializedAsync() { await Task.Delay(1); MMDataService.BroadastMsgPipe.EA_NewMessage += BroadCastMsg_EA_NewMessage; } } }