From 78cb17d8fc7eb801fde27feeb5d61470cb711b92 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 12 Jul 2022 19:05:30 +0200 Subject: [PATCH] Cleanup MP/MON --- MP.Mon/Components/DetailMSE.razor.cs | 51 +++---- MP.Mon/Data/MpDataService.cs | 125 +++++++++--------- MP.Mon/MP.Mon.csproj | 2 +- MP.Mon/NLog.config | 2 +- MP.Mon/Pages/Index.razor.cs | 66 +-------- MP.Mon/Resources/ChangeLog.html | 2 +- MP.Mon/Resources/VersNum.txt | 2 +- MP.Mon/Resources/manifest.xml | 2 +- .../Client/Components/DetailMSE.razor.cs | 10 -- MP.WASM.Mon/Client/Pages/Index.razor.cs | 8 +- 10 files changed, 84 insertions(+), 186 deletions(-) diff --git a/MP.Mon/Components/DetailMSE.razor.cs b/MP.Mon/Components/DetailMSE.razor.cs index 11f58d24..baaee191 100644 --- a/MP.Mon/Components/DetailMSE.razor.cs +++ b/MP.Mon/Components/DetailMSE.razor.cs @@ -12,11 +12,6 @@ namespace MP.Mon.Components [Parameter] public MappaStatoExpl? CurrRecord { get; set; } = null; - /// - /// Valore precedente x calcolo variazione - /// - private MappaStatoExpl? OldRecord { get; set; } = null; - [Parameter] public List? currTagConf { get; set; } = null; @@ -26,37 +21,22 @@ namespace MP.Mon.Components [Parameter] public bool doAnimate { get; set; } = true; + [Parameter] + public bool doBlink { get; set; } = false; + [Parameter] public int keepAliveMin { get; set; } = 5; [Parameter] public string showArt { get; set; } = ""; - - [Parameter] - public bool doBlink { get; set; } = false; - //{ - // set - // { - // // se true --> ricarica - // if (value) - // { - // var pUpd = Task.Run(async () => - // { - // await InvokeAsync(() => StateHasChanged()); - // }); - // pUpd.Wait(); - // } - // } - //} - #endregion Public Properties #region Public Methods public void Dispose() { - //aTimer.Elapsed -= ElapsedTimer; + aTimer.Elapsed -= ElapsedTimer; aTimer.Stop(); aTimer.Dispose(); } @@ -114,6 +94,7 @@ namespace MP.Mon.Components #region Protected Fields protected string baseCss = "sem"; + protected int kaFactor = 60 / 2; #endregion Protected Fields @@ -209,11 +190,21 @@ namespace MP.Mon.Components #region Private Fields - private static System.Timers.Timer aTimer { get; set; } = null!; private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); #endregion Private Fields + #region Private Properties + + private static System.Timers.Timer aTimer { get; set; } = null!; + + /// + /// Valore precedente x calcolo variazione + /// + private MappaStatoExpl? OldRecord { get; set; } = null; + + #endregion Private Properties + #region Private Methods private string cssComStatus(string semaforo, DateTime? lastUpdateN) @@ -246,16 +237,6 @@ namespace MP.Mon.Components string answ = $"{baseCss}{codColore}"; if (doAnimate && codColore != "Ve") { -#if false - // blink se secondo pari... - DateTime adesso = DateTime.Now; - int resto = 0; - Math.DivRem(adesso.Second, 2, out resto); - if (resto == 0) - { - answ += "_b"; - } -#endif if (doBlink) { answ += "_b"; diff --git a/MP.Mon/Data/MpDataService.cs b/MP.Mon/Data/MpDataService.cs index a72b6f2a..11036e53 100644 --- a/MP.Mon/Data/MpDataService.cs +++ b/MP.Mon/Data/MpDataService.cs @@ -36,7 +36,6 @@ namespace MP.Mon.Data dbController = new MP.Data.Controllers.MpMonController(configuration); StringBuilder sb = new StringBuilder(); sb.AppendLine($"DbController OK"); - //sb.AppendLine($"CST: {dbController.CustomersCount()} | CNT: {dbController.CountersCount()} | BSK: {dbController.BasketsCount()} | NGT: {dbController.NegotiationsCount()} | DOC: {dbController.DocsCount()} | ITM: {dbController.ItemsCount()} | RES: {dbController.ResourcesCount()}"); _logger.LogInformation(sb.ToString()); } @@ -47,75 +46,21 @@ namespace MP.Mon.Data startTimers(); } - private void startTimers() - { - fastTimer = new System.Timers.Timer(fastRefreshMs); - fastTimer.Elapsed += ElapsedFastTimer; - fastTimer.Enabled = true; - fastTimer.Start(); - } - - private void ElapsedFastTimer(object? source, System.Timers.ElapsedEventArgs e) - { - var pUpd = Task.Run(async () => - { - // secondi pari --> blink, secondi dispari --> ricarica - DateTime adesso = DateTime.Now; - int resto = 0; - Math.DivRem(adesso.Second, 2, out resto); - if (resto == 0) - { - // invio in channel blink il segnale - blinkPipe.sendMessage("true"); - Log.Trace("Elapsed Fast Timer Blink"); - } - else - { - // invio in channel blink segnale false - blinkPipe.sendMessage("false"); - // rileggo dati ed invio - await ReloadData(); - Log.Trace("Elapsed Fast Timer reload"); - } - }); - pUpd.Wait(); - } - - private async Task ReloadData() - { - // legge i dati e li invia tramite redis channels - var newData = await MseGetAll(); - // invio tramite la pipe... - dataPipe.sendMessage(JsonConvert.SerializeObject(newData)); - - } - - /// - /// Limite in formato data-ora per inviare dati rapidamente (incrementato come now + 1 min ad ogni chiamata client) - /// - private DateTime fastLimit = DateTime.Now; - private int fastRefreshMs = 1000; - private static System.Timers.Timer fastTimer = new System.Timers.Timer(4000); - - /// - /// Richiesta attivazione --> sposto avanti 1 minuto il periodo limite x fast running - /// - public void doActivate() - { - fastLimit = DateTime.Now.AddMinutes(1); - } - #endregion Public Constructors #region Public Properties public static MP.Data.Controllers.MpMonController dbController { get; set; } = null!; + public MessagePipe blinkPipe { get; set; } = null!; + /// /// Dizionario dei tag configurati per IOB /// public Dictionary> currTagConf { get; set; } = new Dictionary>(); + public MessagePipe dataPipe { get; set; } = null!; + #endregion Public Properties #region Public Methods @@ -131,6 +76,14 @@ namespace MP.Mon.Data dbController.Dispose(); } + /// + /// Richiesta attivazione --> sposto avanti 1 minuto il periodo limite x fast running + /// + public void doActivate() + { + fastLimit = DateTime.Now.AddMinutes(1); + } + /// /// Elenco setup dei tag conf correnti /// @@ -174,7 +127,7 @@ namespace MP.Mon.Data result = JsonConvert.DeserializeObject>(rawData); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Trace($"Read from REDIS: {ts.TotalMilliseconds}ms"); + Log.Debug($"Read from REDIS: {ts.TotalMilliseconds}ms"); } else { @@ -184,7 +137,7 @@ namespace MP.Mon.Data await redisDb.StringSetAsync(redisMseKey, rawData, TimeSpan.FromSeconds(2)); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Trace($"Read from DB: {ts.TotalMilliseconds}ms"); + Log.Debug($"Read from DB: {ts.TotalMilliseconds}ms"); } if (result == null) { @@ -195,16 +148,24 @@ namespace MP.Mon.Data #endregion Public Methods - public MessagePipe dataPipe { get; set; } = null!; - public MessagePipe blinkPipe { get; set; } = null!; - #region Private Fields private static IConfiguration _configuration = null!; + private static ILogger _logger = null!; + private static System.Timers.Timer fastTimer = new System.Timers.Timer(4000); + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + /// + /// Limite in formato data-ora per inviare dati rapidamente (incrementato come now + 1 min + /// ad ogni chiamata client) + /// + private DateTime fastLimit = DateTime.Now; + + private int fastRefreshMs = 1000; + /// /// Oggetto per connessione a REDIS /// @@ -222,6 +183,42 @@ namespace MP.Mon.Data #region Private Methods + private void ElapsedFastTimer(object? source, System.Timers.ElapsedEventArgs e) + { + var pUpd = Task.Run(async () => + { + // secondi pari --> blink, secondi dispari --> ricarica + DateTime adesso = DateTime.Now; + int resto = 0; + Math.DivRem(adesso.Second, 2, out resto); + if (resto == 0) + { + // invio in channel blink il segnale + blinkPipe.sendMessage("true"); + Log.Debug("Elapsed Fast Timer Blink"); + } + else + { + // invio in channel blink segnale false + blinkPipe.sendMessage("false"); + // rileggo dati... + var newData = await MseGetAll(); + // invio tramite la pipe... + dataPipe.sendMessage(JsonConvert.SerializeObject(newData)); + Log.Debug("Elapsed Fast Timer reload"); + } + }); + pUpd.Wait(); + } + + private void startTimers() + { + fastTimer = new System.Timers.Timer(fastRefreshMs); + fastTimer.Elapsed += ElapsedFastTimer; + fastTimer.Enabled = true; + fastTimer.Start(); + } + /// /// Prova a caricare da file la conf degli IOB se presente /// diff --git a/MP.Mon/MP.Mon.csproj b/MP.Mon/MP.Mon.csproj index 8bd12d2b..7884b444 100644 --- a/MP.Mon/MP.Mon.csproj +++ b/MP.Mon/MP.Mon.csproj @@ -4,7 +4,7 @@ net6.0 enable enable - 6.15.2207.1218 + 6.15.2207.1219 diff --git a/MP.Mon/NLog.config b/MP.Mon/NLog.config index b32ba10a..3e4185f4 100644 --- a/MP.Mon/NLog.config +++ b/MP.Mon/NLog.config @@ -39,7 +39,7 @@ Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f" --> - + diff --git a/MP.Mon/Pages/Index.razor.cs b/MP.Mon/Pages/Index.razor.cs index 92063d26..754220aa 100644 --- a/MP.Mon/Pages/Index.razor.cs +++ b/MP.Mon/Pages/Index.razor.cs @@ -14,42 +14,9 @@ namespace MP.Mon.Pages public void Dispose() { -#if false - fastTimer.Stop(); - fastTimer.Dispose(); -#endif - slowTimer.Stop(); - slowTimer.Dispose(); disposeTimers(); } -#if false - public void ElapsedFastTimer(object? source, System.Timers.ElapsedEventArgs e) - { - var pUpd = Task.Run(async () => - { - // 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"); - await Task.Delay(1); - await InvokeAsync(StateHasChanged); - } - else - { - doBlink = false; - await ReloadData(); - Log.Trace("Elapsed Fast Timer reload"); - } - }); - pUpd.Wait(); - } -#endif - public async void ElapsedSlowTimer(object? source, System.Timers.ElapsedEventArgs e) { listMSE = null; @@ -57,19 +24,13 @@ namespace MP.Mon.Pages Log.Info("Elapsed Slow Timer --> full page reload"); // dispongo i vari timers... disposeTimers(); + await Task.Delay(1); // reload pagina NavManager.NavigateTo(NavManager.Uri); } public void StartTimer() { -#if false - // timer veloce - fastTimer = new System.Timers.Timer(fastRefreshMs); - fastTimer.Elapsed += ElapsedFastTimer; - fastTimer.Enabled = true; - fastTimer.Start(); -#endif // timer lento slowTimer = new System.Timers.Timer(slowRefreshMs); slowTimer.Elapsed += ElapsedSlowTimer; @@ -285,36 +246,11 @@ namespace MP.Mon.Pages private void disposeTimers() { - //fastTimer.Elapsed -= ElapsedFastTimer; - //fastTimer.Stop(); - //fastTimer.Dispose(); slowTimer.Elapsed -= ElapsedSlowTimer; slowTimer.Stop(); slowTimer.Dispose(); } -#if false - private async Task ReloadData() - { - // legge i dati e li invia tramite redis channels - var newData = await MMDataService.MseGetAll(); - // invio tramite la pipe... - MMDataService.dataPipe.sendMessage(JsonConvert.SerializeObject(newData)); - - //#if DEBUG - // // hack: legge 4 volte i dati x stressare sistema - // var singleData = await MMDataService.MseGetAll(); - // listMSE = new List(); - // for (int i = 0; i < 4; i++) - // { - // listMSE.AddRange(singleData); - // } - //#else - // listMSE = await MMDataService.MseGetAll(); - //#endif - } -#endif - private async Task setupConf() { CurrConfig = await MMDataService.ConfigGetAll(); diff --git a/MP.Mon/Resources/ChangeLog.html b/MP.Mon/Resources/ChangeLog.html index f9de4f4a..bf88f821 100644 --- a/MP.Mon/Resources/ChangeLog.html +++ b/MP.Mon/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MON MAPO -

Versione: 6.15.2207.1218

+

Versione: 6.15.2207.1219


Note di rilascio:
  • diff --git a/MP.Mon/Resources/VersNum.txt b/MP.Mon/Resources/VersNum.txt index 97d4a6fd..46d049fe 100644 --- a/MP.Mon/Resources/VersNum.txt +++ b/MP.Mon/Resources/VersNum.txt @@ -1 +1 @@ -6.15.2207.1218 +6.15.2207.1219 diff --git a/MP.Mon/Resources/manifest.xml b/MP.Mon/Resources/manifest.xml index f9ff8551..283e348b 100644 --- a/MP.Mon/Resources/manifest.xml +++ b/MP.Mon/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.15.2207.1218 + 6.15.2207.1219 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 diff --git a/MP.WASM.Mon/Client/Components/DetailMSE.razor.cs b/MP.WASM.Mon/Client/Components/DetailMSE.razor.cs index 9aa2b634..02098d26 100644 --- a/MP.WASM.Mon/Client/Components/DetailMSE.razor.cs +++ b/MP.WASM.Mon/Client/Components/DetailMSE.razor.cs @@ -246,16 +246,6 @@ namespace MP.WASM.Mon.Client.Components string answ = $"{baseCss}{codColore}"; if (doAnimate && codColore != "Ve") { -#if false - // blink se secondo pari... - DateTime adesso = DateTime.Now; - int resto = 0; - Math.DivRem(adesso.Second, 2, out resto); - if (resto == 0) - { - answ += "_b"; - } -#endif if (doBlink) { answ += "_b"; diff --git a/MP.WASM.Mon/Client/Pages/Index.razor.cs b/MP.WASM.Mon/Client/Pages/Index.razor.cs index 4c076aa1..30b1bc7b 100644 --- a/MP.WASM.Mon/Client/Pages/Index.razor.cs +++ b/MP.WASM.Mon/Client/Pages/Index.razor.cs @@ -11,12 +11,6 @@ namespace MP.WASM.Mon.Client.Pages public void Dispose() { -#if false - fastTimer.Stop(); - fastTimer.Dispose(); - slowTimer.Stop(); - slowTimer.Dispose(); -#endif disposeTimers(); } @@ -222,7 +216,7 @@ namespace MP.WASM.Mon.Client.Pages { // leggo stato server... fastTimer.Interval = fastRefreshMs * 3; - var res = await Http.GetAsync("/api/MSE/checkAlive"); + var res = await Http.GetAsync("api/MSE/checkAlive"); Console.WriteLine("GetAsync end"); if (res.IsSuccessStatusCode) {