From 35ce8e8066a91d30caf1bb16389eeb48a998cbc0 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 20 Mar 2025 18:38:56 +0100 Subject: [PATCH] MON: - correzioni x gestione reconnect + stabile - fix vari x condizioni errori visti in Jetco 8da aggiornare anche script PI) --- MP.MON.Client/wwwroot/lib/boot.js | 59 +++++++++++++++++++ MP.MON/Components/App.razor | 70 ++++++++++++++++++++++- MP.MON/Components/Layout/MainLayout.razor | 10 ++-- MP.MON/Components/Pages/Index.razor.cs | 21 +++++-- MP.MON/MP.MON.csproj | 2 +- MP.MON/Resources/ChangeLog.html | 2 +- MP.MON/Resources/VersNum.txt | 2 +- MP.MON/Resources/manifest.xml | 2 +- 8 files changed, 152 insertions(+), 16 deletions(-) create mode 100644 MP.MON.Client/wwwroot/lib/boot.js diff --git a/MP.MON.Client/wwwroot/lib/boot.js b/MP.MON.Client/wwwroot/lib/boot.js new file mode 100644 index 00000000..b00823da --- /dev/null +++ b/MP.MON.Client/wwwroot/lib/boot.js @@ -0,0 +1,59 @@ +(() => { + const maximumRetryCount = 3; + const retryIntervalMilliseconds = 5000; + const reconnectModal = document.getElementById('reconnect-modal'); + + const startReconnectionProcess = () => { + reconnectModal.style.display = 'block'; + + let isCanceled = false; + + (async () => { + for (let i = 0; i < maximumRetryCount; i++) { + reconnectModal.innerText = `Attempting to reconnect: ${i + 1} of ${maximumRetryCount}`; + + await new Promise(resolve => setTimeout(resolve, retryIntervalMilliseconds)); + + if (isCanceled) { + return; + } + + try { + const result = await Blazor.reconnect(); + if (!result) { + // The server was reached, but the connection was rejected; reload the page. + location.reload(); + return; + } + + // Successfully reconnected to the server. + return; + } catch { + // Didn't reach the server; try again. + } + } + + // Retried too many times; reload the page. + location.reload(); + })(); + + return { + cancel: () => { + isCanceled = true; + reconnectModal.style.display = 'none'; + }, + }; + }; + + let currentReconnectionProcess = null; + + Blazor.start({ + reconnectionHandler: { + onConnectionDown: () => currentReconnectionProcess ??= startReconnectionProcess(), + onConnectionUp: () => { + currentReconnectionProcess?.cancel(); + currentReconnectionProcess = null; + } + } + }); +})(); \ No newline at end of file diff --git a/MP.MON/Components/App.razor b/MP.MON/Components/App.razor index a74296d3..e87468c5 100644 --- a/MP.MON/Components/App.razor +++ b/MP.MON/Components/App.razor @@ -20,6 +20,74 @@ @* *@ + @* *@ + @* + *@ diff --git a/MP.MON/Components/Layout/MainLayout.razor b/MP.MON/Components/Layout/MainLayout.razor index db14a94e..ae1ae3c4 100644 --- a/MP.MON/Components/Layout/MainLayout.razor +++ b/MP.MON/Components/Layout/MainLayout.razor @@ -22,7 +22,7 @@ Reload 🗙 -@code{ +@code { [Inject] protected NavigationManager NavMan { get; set; } = null!; @@ -32,17 +32,17 @@ protected override void OnInitialized() { + var currAssembly = typeof(Program).Assembly.GetName(); + version = currAssembly.Version != null ? currAssembly.Version : new Version(); // controllo URL x riscrivere se non fosse /MP/MON finale... string baseUrl = config.GetValue("ServerConf:BaseAppPath") ?? "/MP/MON/"; string wrongEnd = baseUrl.Substring(0, baseUrl.Length - 1); string currUrl = NavMan.Uri; - if(currUrl.EndsWith(wrongEnd)) + if (currUrl.EndsWith(wrongEnd)) { NavMan.NavigateTo(baseUrl, true); } - // base.OnInitialized(); - var currAssembly = typeof(Program).Assembly.GetName(); - version = currAssembly.Version != null ? currAssembly.Version : new Version(); + base.OnInitialized(); } /// diff --git a/MP.MON/Components/Pages/Index.razor.cs b/MP.MON/Components/Pages/Index.razor.cs index 1ca0c0a2..86b29895 100644 --- a/MP.MON/Components/Pages/Index.razor.cs +++ b/MP.MON/Components/Pages/Index.razor.cs @@ -10,6 +10,7 @@ using System; using static Org.BouncyCastle.Math.EC.ECCurve; using MP.Core.DTO; using MP.Data.Translate; +using Microsoft.AspNetCore.Components.Forms; namespace MP.MON.Components.Pages { @@ -24,14 +25,12 @@ namespace MP.MON.Components.Pages disposeTimers(); } - public async void ElapsedSlowTimer(object? source, System.Timers.ElapsedEventArgs e) + public void ElapsedSlowTimer(object? source, System.Timers.ElapsedEventArgs e) { ListMSE = null; - await Task.Delay(10); Log.Info("Elapsed Slow Timer --> full page reload"); // dispongo i vari timers... disposeTimers(); - await Task.Delay(10); // reload pagina intera NavManager.NavigateTo(NavManager.Uri, true); } @@ -233,9 +232,15 @@ namespace MP.MON.Components.Pages MMDataService.blinkPipe.EA_NewMessage += BlinkPipe_EA_NewMessage; Random rnd = new Random(); cssOverlayOff = config.GetValue("ServerConf:cssOverlayOff") ?? ""; - //maxChar4Scroll = config.GetValue("ServerConf:maxChar4Scroll"); - await Task.Delay(rnd.Next(50, 150)); - StartTimer(); + } + + protected override void OnAfterRender(bool firstRender) + { + if (firstRender) + { + StartTimer(); + } + //base.OnAfterRender(firstRender); } #endregion Protected Methods @@ -392,7 +397,11 @@ namespace MP.MON.Components.Pages scrollText = rawData.ToLower() == "true"; getConfVal("MON_showTC", ref rawData); showTC = rawData.ToLower() == "true"; +#if DEBUG + slowRefreshSec = 20; +#else getConfValInt("pageRefreshSec", ref slowRefreshSec); +#endif getConfVal("sART", ref showArt); // con luminosità, dimensione carattere e num char x andare a capo x gestione specifica in caso di "allargamento componenti" getConfValInt("MON_maxChar4Scroll", ref maxChar4Scroll); diff --git a/MP.MON/MP.MON.csproj b/MP.MON/MP.MON.csproj index c2c431c0..2ba79b11 100644 --- a/MP.MON/MP.MON.csproj +++ b/MP.MON/MP.MON.csproj @@ -6,7 +6,7 @@ enable MP.MON $(AssemblyName.Replace(' ', '_')) - 6.16.2503.1911 + 6.16.2503.2018 diff --git a/MP.MON/Resources/ChangeLog.html b/MP.MON/Resources/ChangeLog.html index 1df1e4ae..4f846809 100644 --- a/MP.MON/Resources/ChangeLog.html +++ b/MP.MON/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

Versione: 6.16.2503.1911

+

Versione: 6.16.2503.2018


Note di rilascio:
  • diff --git a/MP.MON/Resources/VersNum.txt b/MP.MON/Resources/VersNum.txt index 78a7bce2..ae934ac0 100644 --- a/MP.MON/Resources/VersNum.txt +++ b/MP.MON/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2503.1911 +6.16.2503.2018 diff --git a/MP.MON/Resources/manifest.xml b/MP.MON/Resources/manifest.xml index 5b41dde9..78fd0f14 100644 --- a/MP.MON/Resources/manifest.xml +++ b/MP.MON/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2503.1911 + 6.16.2503.2018 https://nexus.steamware.net/repository/SWS/MP-MON/stable/LAST/MP.MON.zip https://nexus.steamware.net/repository/SWS/MP-MON/stable/LAST/ChangeLog.html false