Files
mapo-core/MP.Stats/Pages/StatusChecks.razor.cs
T
2026-05-04 09:51:40 +02:00

108 lines
2.7 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Configuration;
using MP.Data.DbModels.Energy;
using MP.Stats.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MP.Stats.Pages
{
public partial class StatusChecks
{
#region Protected Properties
[Inject]
protected IConfiguration ConfMan { get; set; } = null!;
[Inject]
protected MpStatsService StatService { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected override void OnInitialized()
{
timeoutMin = ConfMan.GetValue<int>("SpecialConf:TimeoutEnergyFlux");
}
protected override async Task OnParametersSetAsync()
{
await ReloadDataAsync();
UpdateTable();
}
#endregion Protected Methods
#region Private Fields
private List<MacchineEnergyCheckModel> AllRecord = new();
private List<MacchineEnergyCheckModel> ListPaged = new();
private int numRecPage = 10;
private int pageNum = 1;
private int timeoutMin = 30;
private int totalCount = 0;
#endregion Private Fields
#region Private Methods
/// <summary>
/// Scadute se evento > 5 minuti
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
private string CheckScadute(MacchineEnergyCheckModel item)
{
DateTime adesso = DateTime.Now;
var dataAge = adesso.Subtract(item.dtEvento).TotalMinutes;
string status = "";
// se supero limite
if (dataAge >= timeoutMin)
{
// se doppio del limite danger sennò warning...
status = dataAge <= 2 * timeoutMin ? "table-warning" : "table-danger";
}
return status;
}
private async Task ReloadDataAsync()
{
AllRecord = await StatService.MacchineEnergyCheckGetAll();
totalCount = AllRecord.Count;
}
private void SaveNumRec(int newNum)
{
numRecPage = newNum;
UpdateTable();
}
private void SavePage(int newNum)
{
pageNum = newNum;
UpdateTable();
}
private void UpdateTable()
{
// esegue paginazione
if (totalCount > numRecPage)
{
ListPaged = AllRecord.Skip((pageNum - 1) * numRecPage).Take(numRecPage).ToList();
}
else
{
ListPaged = AllRecord;
}
}
#endregion Private Methods
}
}