Files
mapo-core/MP.SPEC/Pages/Test.razor.cs
T
2022-12-02 17:05:07 +01:00

68 lines
2.1 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.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<string>(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;
}
}
}