Files
Samuele Locatelli bec5a56df2 DB overload:
Fix problema eventi moltiplicati x subscript
2022-10-24 15:00:45 +02:00

70 lines
1.7 KiB
C#

using MP.MONO.Core.DTO;
using MP.MONO.Data;
using Newtonsoft.Json;
namespace MP.MONO.UI.Components
{
public partial class ProdOverview : IDisposable
{
#region Public Methods
public void Dispose()
{
MMDataService.alarmPipe.EA_NewMessage -= ProductionPipe_EA_NewMessage;
}
#endregion Public Methods
#region Protected Methods
protected override async Task OnInitializedAsync()
{
await ReloadData();
MMDataService.productionPipe.EA_NewMessage += ProductionPipe_EA_NewMessage;
}
protected string percProgress(int num, int den)
{
string answ = "width: 0%;";
den = den != 0 ? den : 1;
double ratio = ((double)num) / den;
answ = $"width: {ratio:P0};";
return answ;
}
protected async Task ReloadData()
{
currProd = await MMDataService.getProd();
}
#endregion Protected Methods
#region Private Properties
private ProductionDTO? currProd { get; set; } = null;
#endregion Private Properties
#region Private Methods
private void ProductionPipe_EA_NewMessage(object? sender, EventArgs e)
{
PubSubEventArgs currArgs = (PubSubEventArgs)e;
if (!string.IsNullOrEmpty(currArgs.newMessage))
{
try
{
currProd = JsonConvert.DeserializeObject<ProductionDTO>(currArgs.newMessage);
}
catch
{ }
}
InvokeAsync(() =>
{
StateHasChanged();
});
}
#endregion Private Methods
}
}