diff --git a/MP.WASM.Mon/Client/Pages/Index.razor b/MP.WASM.Mon/Client/Pages/Index.razor index 434c6780..1f8fa826 100644 --- a/MP.WASM.Mon/Client/Pages/Index.razor +++ b/MP.WASM.Mon/Client/Pages/Index.razor @@ -3,10 +3,12 @@ @using MP.Data @using MP.Data.DatabaseModels @inject HttpClient Http +@inject NavigationManager NavManager MP MON
+ @if (listMSE == null) {
@@ -26,7 +28,7 @@ int currIdx = 0; foreach (var recordIob in listMSE) { - + currIdx++; if (currIdx >= maxCol) { @@ -38,13 +40,9 @@ int currNum = (currIdx % maxCol); while (currNum < (maxCol)) { - @((MarkupString)"
 
") - ; + @((MarkupString)"
 
"); currNum++; } }
- - - \ No newline at end of file diff --git a/MP.WASM.Mon/Client/Pages/Index.razor.cs b/MP.WASM.Mon/Client/Pages/Index.razor.cs index f2218755..4c076aa1 100644 --- a/MP.WASM.Mon/Client/Pages/Index.razor.cs +++ b/MP.WASM.Mon/Client/Pages/Index.razor.cs @@ -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? 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>("api/MSE"); - listMSE = new List(); - 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>("api/MSE"); + listMSE = new List(); + for (int i = 0; i < 4; i++) + { + listMSE.AddRange(singleData); + } #else listMSE = await Http.GetFromJsonAsync>("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 } diff --git a/MP.WASM.Mon/Client/Program.cs b/MP.WASM.Mon/Client/Program.cs index cc4d48e2..05ac8b44 100644 --- a/MP.WASM.Mon/Client/Program.cs +++ b/MP.WASM.Mon/Client/Program.cs @@ -6,6 +6,9 @@ var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("#app"); builder.RootComponents.Add("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();