124 lines
3.4 KiB
C#
124 lines
3.4 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using MP.Data;
|
|
using MP.SPEC.Data;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace MP.SPEC.Pages
|
|
{
|
|
public partial class Test : IDisposable
|
|
{
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
#if false
|
|
MMDataService.BroadastMsgPipe.EA_NewMessage += BroadCastMsg_EA_NewMessage;
|
|
#endif
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
protected DateTime lastRec = DateTime.Now.AddMinutes(-1);
|
|
|
|
protected string messaggio = "0";
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected DisplayAction CurrAction { get; set; } = new DisplayAction();
|
|
|
|
[Inject]
|
|
protected MpDataService MMDataService { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected async void clearMessage()
|
|
{
|
|
//CurrAction.IsActive = false;
|
|
//await MMDataService.ActionSetReq(CurrAction);
|
|
MMDataService.ActionSetReq(null);
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await Task.Delay(1);
|
|
var rawAction = await MMDataService.ActionGetReq();
|
|
if (rawAction != null)
|
|
{
|
|
CurrAction = rawAction;
|
|
}
|
|
else
|
|
{
|
|
CurrAction = new DisplayAction()
|
|
{
|
|
Topic = "Chiusura ODL",
|
|
Message = "Rilevato possibile fine operazioni, Vuoi chiudere la commessa?",
|
|
ShowCancel = true,
|
|
ShowClose = true,
|
|
ShowConfirm = true,
|
|
CancelAction = "DisableAction",
|
|
ConfirmAction = "CloseODL",
|
|
DtReq = DateTime.Now,
|
|
IsActive = true
|
|
};
|
|
}
|
|
#if false
|
|
MMDataService.BroadastMsgPipe.EA_NewMessage += BroadCastMsg_EA_NewMessage;
|
|
#endif
|
|
}
|
|
|
|
protected void sendMessage()
|
|
{
|
|
CurrAction.DtReq = DateTime.Now;
|
|
CurrAction.IsActive= true;
|
|
MMDataService.ActionSetReq(CurrAction);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Methods
|
|
|
|
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();
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
private async Task reloadData()
|
|
{
|
|
var rawAction = await MMDataService.ActionGetReq();
|
|
if (rawAction != null)
|
|
{
|
|
CurrAction = rawAction;
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |