Complto review WASM client
This commit is contained in:
@@ -3,10 +3,12 @@
|
||||
@using MP.Data
|
||||
@using MP.Data.DatabaseModels
|
||||
@inject HttpClient Http
|
||||
@inject NavigationManager NavManager
|
||||
|
||||
<PageTitle>MP MON</PageTitle>
|
||||
|
||||
<div class="row statusMap mx-1 my-1">
|
||||
|
||||
@if (listMSE == null)
|
||||
{
|
||||
<div class="col-12">
|
||||
@@ -26,7 +28,7 @@
|
||||
int currIdx = 0;
|
||||
foreach (var recordIob in listMSE)
|
||||
{
|
||||
<DetailMSE CurrRecord="@recordIob" currTagConf="@getIobTag(recordIob.IdxMacchina)" currTagVal="@getTagVal(recordIob.IdxMacchina)" doAnimate="@doAnimate" keepAliveMin="@keepAliveMin" showArt="@showArt"></DetailMSE>
|
||||
<DetailMSE CurrRecord="@recordIob" currTagConf="@getIobTag(recordIob.IdxMacchina)" currTagVal="@getTagVal(recordIob.IdxMacchina)" doAnimate="@doAnimate" keepAliveMin="@keepAliveMin" showArt="@showArt" doBlink="@doBlink"></DetailMSE>
|
||||
currIdx++;
|
||||
if (currIdx >= maxCol)
|
||||
{
|
||||
@@ -38,13 +40,9 @@
|
||||
int currNum = (currIdx % maxCol);
|
||||
while (currNum < (maxCol))
|
||||
{
|
||||
@((MarkupString)"<div class=\"col machBlock\"> </div>")
|
||||
;
|
||||
@((MarkupString)"<div class=\"col machBlock\"> </div>");
|
||||
currNum++;
|
||||
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@@ -12,22 +12,34 @@ namespace MP.WASM.Mon.Client.Pages
|
||||
public void Dispose()
|
||||
{
|
||||
#if false
|
||||
//fastTimer.Elapsed -= ElapsedFastTimer;
|
||||
fastTimer.Stop();
|
||||
fastTimer.Dispose();
|
||||
//slowTimer.Elapsed -= ElapsedSlowTimer;
|
||||
slowTimer.Stop();
|
||||
slowTimer.Dispose();
|
||||
slowTimer.Dispose();
|
||||
#endif
|
||||
disposeTimers();
|
||||
}
|
||||
|
||||
public void ElapsedFastTimer(object? source, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
var pUpd = Task.Run(async () =>
|
||||
{
|
||||
await ReloadData();
|
||||
// secondi pari --> blink, secondi dispari --> ricarica
|
||||
DateTime adesso = DateTime.Now;
|
||||
int resto = 0;
|
||||
Math.DivRem(adesso.Second, 2, out resto);
|
||||
if (resto == 0)
|
||||
{
|
||||
doBlink = true;
|
||||
Log.Trace("Elapsed Fast Timer Blink");
|
||||
}
|
||||
else
|
||||
{
|
||||
doBlink = false;
|
||||
await ReloadData();
|
||||
Log.Trace("Elapsed Fast Timer reload");
|
||||
}
|
||||
await Task.Delay(1);
|
||||
Log.Trace("Elapsed Fast Timer");
|
||||
await InvokeAsync(StateHasChanged);
|
||||
});
|
||||
pUpd.Wait();
|
||||
@@ -37,10 +49,11 @@ namespace MP.WASM.Mon.Client.Pages
|
||||
{
|
||||
listMSE = null;
|
||||
await Task.Delay(1);
|
||||
Log.Trace("Elapsed Slow Timer");
|
||||
#if false
|
||||
Log.Info("Elapsed Slow Timer --> full page reload");
|
||||
// dispongo i vari timers...
|
||||
disposeTimers();
|
||||
// reload pagina
|
||||
NavManager.NavigateTo(NavManager.Uri);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void StartTimer()
|
||||
@@ -62,7 +75,7 @@ namespace MP.WASM.Mon.Client.Pages
|
||||
#region Protected Fields
|
||||
|
||||
protected bool doAnimate = true;
|
||||
protected int fastRefreshSec = 2;
|
||||
protected int fastRefreshMs = 1000;
|
||||
protected int keepAliveMin = 1;
|
||||
protected int maxCol = 6;
|
||||
protected string showArt = "";
|
||||
@@ -72,11 +85,6 @@ namespace MP.WASM.Mon.Client.Pages
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
protected int fastRefreshMs
|
||||
{
|
||||
get => 1000 * fastRefreshSec;
|
||||
}
|
||||
|
||||
protected int slowRefreshMs
|
||||
{
|
||||
get => 1000 * slowRefreshSec;
|
||||
@@ -193,25 +201,52 @@ namespace MP.WASM.Mon.Client.Pages
|
||||
private static System.Timers.Timer fastTimer = new System.Timers.Timer(4000);
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private static System.Timers.Timer slowTimer = new System.Timers.Timer(300000);
|
||||
private bool doBlink = false;
|
||||
private List<MappaStatoExpl>? listMSE = null;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void disposeTimers()
|
||||
{
|
||||
fastTimer.Elapsed -= ElapsedFastTimer;
|
||||
fastTimer.Stop();
|
||||
fastTimer.Dispose();
|
||||
slowTimer.Elapsed -= ElapsedSlowTimer;
|
||||
slowTimer.Stop();
|
||||
slowTimer.Dispose();
|
||||
}
|
||||
|
||||
private async Task ReloadData()
|
||||
{
|
||||
#if DEBUG
|
||||
// hack: legge 4 volte i dati x stressare sistema
|
||||
var singleData = await Http.GetFromJsonAsync<List<MappaStatoExpl>>("api/MSE");
|
||||
listMSE = new List<MappaStatoExpl>();
|
||||
for (int i = 0; i < 4; i++)
|
||||
// leggo stato server...
|
||||
fastTimer.Interval = fastRefreshMs * 3;
|
||||
var res = await Http.GetAsync("/api/MSE/checkAlive");
|
||||
Console.WriteLine("GetAsync end");
|
||||
if (res.IsSuccessStatusCode)
|
||||
{
|
||||
listMSE.AddRange(singleData);
|
||||
}
|
||||
#if DEBUG
|
||||
// hack: legge 4 volte i dati x stressare sistema
|
||||
var singleData = await Http.GetFromJsonAsync<List<MappaStatoExpl>>("api/MSE");
|
||||
listMSE = new List<MappaStatoExpl>();
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
listMSE.AddRange(singleData);
|
||||
}
|
||||
#else
|
||||
listMSE = await Http.GetFromJsonAsync<List<MappaStatoExpl>>("api/MSE");
|
||||
#endif
|
||||
fastTimer.Interval = fastRefreshMs;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Error in request");
|
||||
listMSE = null;
|
||||
await Task.Delay(100);
|
||||
await InvokeAsync(() => StateHasChanged());
|
||||
}
|
||||
Console.WriteLine("ReloadData end");
|
||||
}
|
||||
|
||||
private async Task setupConf()
|
||||
@@ -227,9 +262,9 @@ namespace MP.WASM.Mon.Client.Pages
|
||||
getConfValInt("doAnimate", ref intDoAnim);
|
||||
doAnimate = intDoAnim == 1;
|
||||
getConfValInt("pageRefreshSec", ref slowRefreshSec);
|
||||
getConfValInt("MSE_cacheDuration", ref fastRefreshSec);
|
||||
getConfVal("sART", ref showArt);
|
||||
Log.Info($"Effettuato setup parametri | keepAlive: {keepAliveMin} | MaxCol: {maxCol} | doAnimate: {doAnimate} | slowRefreshSec: {slowRefreshSec} | fastRefreshSec: {fastRefreshSec}");
|
||||
|
||||
Log.Info($"Effettuato setup parametri | keepAlive: {keepAliveMin} | MaxCol: {maxCol} | doAnimate: {doAnimate} | slowRefreshSec: {slowRefreshSec} | fastRefreshMs: {fastRefreshMs}");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
||||
builder.RootComponents.Add<App>("#app");
|
||||
builder.RootComponents.Add<HeadOutlet>("head::after");
|
||||
|
||||
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
|
||||
builder.Services.AddScoped(sp => new HttpClient {
|
||||
BaseAddress = new Uri(builder.HostEnvironment.BaseAddress),
|
||||
Timeout = TimeSpan.FromMilliseconds(900)
|
||||
});
|
||||
|
||||
await builder.Build().RunAsync();
|
||||
|
||||
Reference in New Issue
Block a user