Fix time blink x errore C101

This commit is contained in:
Samuele Locatelli
2022-04-13 16:48:47 +02:00
parent d3e7c224d3
commit fd63226051
7 changed files with 89 additions and 26 deletions
-9
View File
@@ -81,15 +81,6 @@ namespace MP.Data.Controllers
List<DatabaseModels.MappaStatoExpl> dbResult = new List<DatabaseModels.MappaStatoExpl>();
using (var dbCtx = new MoonProContext(_configuration))
{
//dbResult = dbCtx
//.DbSetMSE
//.OrderBy(x => x.RowNum)
//.ToList();
var maxAgeSec = new SqlParameter("@maxAgeSec", maxAge);
dbResult = dbCtx
+9 -9
View File
@@ -1,10 +1,10 @@
@if (CurrRecord == null)
{
<LoadingData></LoadingData>
}
else
{
<div class="col machBlock">
<div class="col machBlock">
@if (CurrRecord == null || !dataLoaded)
{
<LoadingDataSmall></LoadingDataSmall>
}
else
{
<div class="@cssStatus(CurrRecord.Semaforo) p-1">
<div class="d-flex mb-1 ui-title justify-content-center align-items-center text-uppercase">
@CurrRecord.Nome
@@ -48,5 +48,5 @@ else
</div>
</div>
</div>
</div>
}
}
</div>
+35 -2
View File
@@ -22,6 +22,8 @@ namespace MP.Mon.Components
{
protected string baseCss = "";
protected bool dataLoaded { get; set; } = false;
protected int kaFactor = 60 / 2;
[Parameter]
public bool doAnimate { get; set; } = true;
@@ -40,7 +42,7 @@ namespace MP.Mon.Components
{
DateTime lastUpdate = lastUpdateN.HasValue ? (DateTime)lastUpdateN : DateTime.Now.AddHours(-1);
string answ = cssStatus(semaforo);
if (DateTime.Now.Subtract(lastUpdate).TotalSeconds > (keepAliveMin * 60 / 2))
if (DateTime.Now.Subtract(lastUpdate).TotalSeconds > (keepAliveMin * kaFactor))
{
answ = $"{baseCss}Ro";
}
@@ -48,6 +50,10 @@ namespace MP.Mon.Components
}
protected override async Task OnInitializedAsync()
{
StartTimer();
Random rnd = new Random();
//await Task.Delay(rnd.Next(500));
dataLoaded = true;
setupConf();
}
private void setupConf()
@@ -58,7 +64,7 @@ namespace MP.Mon.Components
{
DateTime lastUpdate = lastUpdateN.HasValue ? (DateTime)lastUpdateN : DateTime.Now.AddHours(-1);
bool answ = false;
if (DateTime.Now.Subtract(lastUpdate).TotalSeconds > (keepAliveMin * 60 / 2))
if (DateTime.Now.Subtract(lastUpdate).TotalSeconds > (keepAliveMin * kaFactor))
{
answ = true;
}
@@ -78,5 +84,32 @@ namespace MP.Mon.Components
{ }
return answ;
}
public void Dispose()
{
aTimer.Stop();
aTimer.Dispose();
}
private static System.Timers.Timer aTimer = new System.Timers.Timer(60 * 1000);
public void StartTimer()
{
int tOutPeriod = 4000;
//int.TryParse(Configuration["ReloadStatusTimer"], out tOutPeriod);
aTimer = new System.Timers.Timer(tOutPeriod);
aTimer.Elapsed += ElapsedTimer;
aTimer.Enabled = true;
aTimer.Start();
}
public void ElapsedTimer(Object source, System.Timers.ElapsedEventArgs e)
{
var pUpd = Task.Run(async () =>
{
await Task.Delay(1);
await InvokeAsync(StateHasChanged);
});
pUpd.Wait();
}
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
<div class="row p-5 m-5">
<div class="row p-5 m-5 bg-light">
<div class="col-12 text-center mt-5 py-5 alert alert-primary">
<h3>loading data</h3>
<i class="fas fa-spinner fa-spin fa-5x"></i>
+6
View File
@@ -0,0 +1,6 @@
<div class="row p-2 m-2">
<div class="col-12 text-center mt-2 py-2 alert alert-primary">
<b>loading data</b>
<i class="fas fa-spinner fa-spin"></i>
</div>
</div>
+6 -1
View File
@@ -44,7 +44,12 @@ namespace MP.Mon.Data
public Task<List<MP.Data.DatabaseModels.MappaStatoExpl>> MseGetAll()
{
return Task.FromResult(dbController.MseGetAll().ToList());
var dbResult = dbController.MseGetAll();
if (dbResult == null)
{
dbResult = new List<MP.Data.DatabaseModels.MappaStatoExpl>();
}
return Task.FromResult(dbResult);
}
}
}
+32 -4
View File
@@ -20,7 +20,7 @@ using MP.Mon.Data;
namespace MP.Mon.Pages
{
public partial class Index
public partial class Index : IDisposable
{
protected List<MappaStatoExpl>? ListMSE = null;
@@ -32,17 +32,45 @@ namespace MP.Mon.Pages
protected override async Task OnInitializedAsync()
{
await reloadData();
await ReloadData();
}
[Inject]
protected MpDataService MMDataService { get; set; }
protected MpDataService MMDataService { get; set; } = null!;
private async Task reloadData()
private async Task ReloadData()
{
ListMSE = await MMDataService.MseGetAll();
}
public void Dispose()
{
aTimer.Stop();
aTimer.Dispose();
}
private static System.Timers.Timer aTimer;
public void StartTimer()
{
int tOutPeriod = 2000;
//int.TryParse(Configuration["ReloadStatusTimer"], out tOutPeriod);
aTimer = new System.Timers.Timer(tOutPeriod);
aTimer.Elapsed += ElapsedTimer;
aTimer.Enabled = true;
aTimer.Start();
}
public void ElapsedTimer(Object source, System.Timers.ElapsedEventArgs e)
{
var pUpd = Task.Run(async () =>
{
await ReloadData();
//await Task.Delay(1);
await InvokeAsync(StateHasChanged);
});
pUpd.Wait();
}
}
}