From 7a8e05462cd0b7d7baaebcb3e7fb5ebf3c9c833d Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 4 Jun 2022 18:09:29 +0200 Subject: [PATCH] Da testare: metodi redis da mostrare --- MP.Mon/Components/DetailMSE.razor.cs | 187 +++++++++++++-------- MP.Mon/Data/MpDataService.cs | 12 +- MP.Mon/MP.Mon.csproj | 2 +- MP.Mon/Pages/Index.razor | 7 +- MP.Mon/Pages/Index.razor.cs | 242 ++++++++++++++++----------- MP.Mon/Resources/ChangeLog.html | 2 +- MP.Mon/Resources/VersNum.txt | 2 +- MP.Mon/Resources/manifest.xml | 2 +- 8 files changed, 273 insertions(+), 183 deletions(-) diff --git a/MP.Mon/Components/DetailMSE.razor.cs b/MP.Mon/Components/DetailMSE.razor.cs index 6444aec3..df218e2f 100644 --- a/MP.Mon/Components/DetailMSE.razor.cs +++ b/MP.Mon/Components/DetailMSE.razor.cs @@ -15,26 +15,129 @@ using MP.Mon; using MP.Mon.Shared; using MP.Mon.Components; using MP.Data.DatabaseModels; +using MP.Data.Conf; namespace MP.Mon.Components { public partial class DetailMSE { + #region Protected Fields protected string baseCss = "sem"; - protected bool dataLoaded { get; set; } = false; protected int kaFactor = 60 / 2; + #endregion Protected Fields + + #region Private Fields + + private static System.Timers.Timer aTimer = new System.Timers.Timer(60 * 1000); + + #endregion Private Fields + + #region Public Properties + + [Parameter] + public MappaStatoExpl? CurrRecord { get; set; } = null; + + [Parameter] + public List? currTagConf { get; set; } = null; + + [Parameter] + public Dictionary currTagVal { get; set; } = new Dictionary(); + [Parameter] public bool doAnimate { get; set; } = true; [Parameter] - public string showArt { get; set; } = ""; + public int keepAliveMin { get; set; } = 5; [Parameter] - public int keepAliveMin { get; set; } = 5; - [Parameter] - public MappaStatoExpl? CurrRecord { get; set; } = null; + public string showArt { get; set; } = ""; + + #endregion Public Properties + + #region Protected Properties + + protected string codIOB + { + get + { + string answ = ""; + if (CurrRecord != null) + { + answ = CurrRecord.IdxMacchina; + } + return answ; + } + } + + protected bool dataLoaded { get; set; } = false; + + #endregion Protected Properties + + #region Public Methods + + public void Dispose() + { + aTimer.Stop(); + aTimer.Dispose(); + } + + public void ElapsedTimer(Object source, System.Timers.ElapsedEventArgs e) + { + var pUpd = Task.Run(async () => + { + await Task.Delay(1); + await InvokeAsync(StateHasChanged); + }); + pUpd.Wait(); + } + + public void StartTimer() + { + int tOutPeriod = 1000; + //int.TryParse(Configuration["ReloadStatusTimer"], out tOutPeriod); + aTimer = new System.Timers.Timer(tOutPeriod); + aTimer.Elapsed += ElapsedTimer; + aTimer.Enabled = true; + aTimer.Start(); + } + + #endregion Public Methods + + #region Protected Methods + + protected override async Task OnInitializedAsync() + { + StartTimer(); + Random rnd = new Random(); + //await Task.Delay(rnd.Next(500)); + dataLoaded = true; + setupConf(); + } + + #endregion Protected Methods + + #region Private Methods + + private string cssComStatus(string semaforo, DateTime? lastUpdateN) + { + DateTime lastUpdate = lastUpdateN.HasValue ? (DateTime)lastUpdateN : DateTime.Now.AddHours(-1); + string answ = cssStatus(semaforo); + if (DateTime.Now.Subtract(lastUpdate).TotalSeconds > (keepAliveMin * kaFactor)) + { + answ = $"{baseCss}Ro"; + // blink se secondo pari... + DateTime adesso = DateTime.Now; + int resto = 0; + Math.DivRem(adesso.Second, 2, out resto); + if (resto == 0) + { + answ += "_b"; + } + } + return answ; + } private string cssStatus(string codSemaforo) { @@ -59,47 +162,6 @@ namespace MP.Mon.Components return answ; } - private string cssComStatus(string semaforo, DateTime? lastUpdateN) - { - DateTime lastUpdate = lastUpdateN.HasValue ? (DateTime)lastUpdateN : DateTime.Now.AddHours(-1); - string answ = cssStatus(semaforo); - if (DateTime.Now.Subtract(lastUpdate).TotalSeconds > (keepAliveMin * kaFactor)) - { - answ = $"{baseCss}Ro"; - // blink se secondo pari... - DateTime adesso = DateTime.Now; - int resto = 0; - Math.DivRem(adesso.Second, 2, out resto); - if (resto == 0) - { - answ += "_b"; - } - } - return answ; - } - protected override async Task OnInitializedAsync() - { - StartTimer(); - Random rnd = new Random(); - //await Task.Delay(rnd.Next(500)); - dataLoaded = true; - setupConf(); - } - private void setupConf() - { - //baseCss = doAnimate ? "semBlink" : "sem"; - } - private bool showComErr(DateTime? lastUpdateN) - { - DateTime lastUpdate = lastUpdateN.HasValue ? (DateTime)lastUpdateN : DateTime.Now.AddHours(-1); - bool answ = false; - if (DateTime.Now.Subtract(lastUpdate).TotalSeconds > (keepAliveMin * kaFactor)) - { - answ = true; - } - return answ; - } - private string getMinSec(decimal? currTimeMin) { string answ = "nd"; @@ -113,32 +175,23 @@ namespace MP.Mon.Components { } return answ; } - public void Dispose() + + private void setupConf() { - aTimer.Stop(); - aTimer.Dispose(); + //baseCss = doAnimate ? "semBlink" : "sem"; } - private static System.Timers.Timer aTimer = new System.Timers.Timer(60 * 1000); - - public void StartTimer() + private bool showComErr(DateTime? lastUpdateN) { - int tOutPeriod = 1000; - //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 () => + DateTime lastUpdate = lastUpdateN.HasValue ? (DateTime)lastUpdateN : DateTime.Now.AddHours(-1); + bool answ = false; + if (DateTime.Now.Subtract(lastUpdate).TotalSeconds > (keepAliveMin * kaFactor)) { - await Task.Delay(1); - await InvokeAsync(StateHasChanged); - }); - pUpd.Wait(); + answ = true; + } + return answ; } + + #endregion Private Methods } } \ No newline at end of file diff --git a/MP.Mon/Data/MpDataService.cs b/MP.Mon/Data/MpDataService.cs index ed18d200..cea45977 100644 --- a/MP.Mon/Data/MpDataService.cs +++ b/MP.Mon/Data/MpDataService.cs @@ -69,14 +69,14 @@ namespace MP.Mon.Data #endregion Public Constructors - #region Protected Properties + #region Public Properties /// /// Dizionario dei tag configurati per IOB /// - protected Dictionary> currTagConf { get; set; } = new Dictionary>(); + public Dictionary> currTagConf { get; set; } = new Dictionary>(); - #endregion Protected Properties + #endregion Public Properties #region Public Methods @@ -96,16 +96,16 @@ namespace MP.Mon.Data /// /// Chiave in cui cercare il valore /// - public async Task getTagConf(string redKey) + public string getTagConf(string redKey) { string outVal = ""; // cerco in REDIS la conf x l'IOB - string rawData = await redisDb.StringGetAsync(redKey); + string rawData = redisDb.StringGet(redKey); if (!string.IsNullOrEmpty(rawData)) { outVal = rawData; } - return await Task.FromResult(outVal); + return outVal; } public Task> MacchineGetAll() diff --git a/MP.Mon/MP.Mon.csproj b/MP.Mon/MP.Mon.csproj index 67b21d52..1507350c 100644 --- a/MP.Mon/MP.Mon.csproj +++ b/MP.Mon/MP.Mon.csproj @@ -4,7 +4,7 @@ net6.0 enable enable - 6.15.2206.417 + 6.15.2206.418 diff --git a/MP.Mon/Pages/Index.razor b/MP.Mon/Pages/Index.razor index c3e49606..9a424e02 100644 --- a/MP.Mon/Pages/Index.razor +++ b/MP.Mon/Pages/Index.razor @@ -24,15 +24,14 @@ else { int currIdx = 0; - foreach (var macchina in ListMSE) + foreach (var recordIob in ListMSE) { - + currIdx++; if (currIdx >= maxCol) { currIdx = 0; - @((MarkupString)"
") - ; + @((MarkupString)"
"); } } // controllo se devo "chiudere riga... diff --git a/MP.Mon/Pages/Index.razor.cs b/MP.Mon/Pages/Index.razor.cs index 5c9f9033..e35a1aae 100644 --- a/MP.Mon/Pages/Index.razor.cs +++ b/MP.Mon/Pages/Index.razor.cs @@ -1,21 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Components; -using System.Net.Http; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Components.Authorization; -using Microsoft.AspNetCore.Components.Forms; -using Microsoft.AspNetCore.Components.Routing; -using Microsoft.AspNetCore.Components.Web; -using Microsoft.AspNetCore.Components.Web.Virtualization; -using Microsoft.JSInterop; -using MP.Mon; -using MP.Mon.Shared; -using MP.Mon.Components; +using MP.Data.Conf; using MP.Data.DatabaseModels; -using MP.Mon.Components; using MP.Mon.Data; using NLog; @@ -23,65 +8,112 @@ namespace MP.Mon.Pages { public partial class Index : IDisposable { - protected List? ListMSE = null; - List? CurrConfig = null; - - - private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - - protected int keepAliveMin = 1; - - protected int maxCol = 4; + #region Protected Fields protected bool doAnimate = true; - - protected string showArt = ""; - - protected int slowRefreshSec = 300; protected int fastRefreshSec = 10; + protected int keepAliveMin = 1; + protected List? ListMSE = null; + protected int maxCol = 4; + protected string showArt = ""; + protected int slowRefreshSec = 300; + #endregion Protected Fields + + #region Private Fields + + 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 List? CurrConfig = null; + + #endregion Private Fields + + #region Protected Properties - protected int slowRefreshMs - { - get => 1000 * slowRefreshSec; - } protected int fastRefreshMs { get => 1000 * fastRefreshSec; } - protected override async Task OnInitializedAsync() - { - await setupConf(); - await ReloadData(); - StartTimer(); - } - - [Inject] protected MpDataService MMDataService { get; set; } = null!; [Inject] protected NavigationManager NavManager { get; set; } = null!; - private async Task setupConf() + protected int slowRefreshMs { - CurrConfig = await MMDataService.ConfigGetAll(); + get => 1000 * slowRefreshSec; + } + + #endregion Protected Properties + + #region Public Methods + + public void Dispose() + { + fastTimer.Stop(); + fastTimer.Dispose(); + slowTimer.Stop(); + slowTimer.Dispose(); + } + + public void ElapsedFastTimer(Object source, System.Timers.ElapsedEventArgs e) + { + var pUpd = Task.Run(async () => + { + await ReloadData(); + //await Task.Delay(1); + await InvokeAsync(StateHasChanged); + }); + pUpd.Wait(); + } + + public async void ElapsedSlowTimer(Object source, System.Timers.ElapsedEventArgs e) + { + ListMSE = null; + NavManager.NavigateTo(NavManager.Uri); + } + + public void StartTimer() + { + // timer veloce + fastTimer = new System.Timers.Timer(fastRefreshMs); + fastTimer.Elapsed += ElapsedFastTimer; + fastTimer.Enabled = true; + fastTimer.Start(); + // timer lento + slowTimer = new System.Timers.Timer(slowRefreshMs); + slowTimer.Elapsed += ElapsedSlowTimer; + slowTimer.Enabled = true; + slowTimer.Start(); + } + + #endregion Public Methods + + #region Protected Methods + + /// + /// Recupera il valore e se trovato aggiorna + /// + /// Valore da cercare + /// String in cui salvare il valore se trovato + /// + protected bool getConfVal(string chiave, ref string varObj) + { + bool answ = false; if (CurrConfig != null && CurrConfig.Count > 0) { // sistemo i parametri opzionali... - - getConfValInt("keepAliveMin", ref keepAliveMin); - getConfValInt("MON_maxCol", ref maxCol); - int intDoAnim = 0; - 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}"); + ConfigModel? risultato = CurrConfig.FirstOrDefault(x => x.Chiave == chiave); + if (risultato != null) + { + varObj = risultato.Valore; + answ = !string.IsNullOrEmpty(risultato.Valore); + } } + return answ; } /// @@ -106,72 +138,78 @@ namespace MP.Mon.Pages } /// - /// Recupera il valore e se trovato aggiorna + /// Recupera da conf eventuale setup tag dell'IOB indicato /// - /// Valore da cercare - /// String in cui salvare il valore se trovato + /// /// - protected bool getConfVal(string chiave, ref string varObj) + protected List? getIobTag(string codIob) { - bool answ = false; - if (CurrConfig != null && CurrConfig.Count > 0) + List? answ = null; + if (MMDataService.currTagConf != null) { - // sistemo i parametri opzionali... - ConfigModel? risultato = CurrConfig.FirstOrDefault(x => x.Chiave == chiave); - if (risultato != null) + // cerco x chiave IOB... + if (MMDataService.currTagConf.ContainsKey(codIob)) { - varObj = risultato.Valore; - answ = !string.IsNullOrEmpty(risultato.Valore); + answ = MMDataService.currTagConf[codIob]; } } return answ; } + /// + /// Recupera da redis (in una chiamata soltanto) tutti i valori richiesti e compone un dizionario x ottimizzare visualizzazione + /// + /// + /// + protected Dictionary getTagVal(string codIob) + { + Dictionary answ = new Dictionary(); + // recupero conf tags... + var currTags = getIobTag(codIob); + if (currTags != null && currTags.Count > 0) + { + // FIXME TODO !!!! FARE !!!! - da verificare + Dictionary dictVal = currTags.ToDictionary(x => x.TagLocation, x => MMDataService.getTagConf(x.TagLocation)); + } + return answ; + } + + protected override async Task OnInitializedAsync() + { + await setupConf(); + await ReloadData(); + StartTimer(); + } + + #endregion Protected Methods + + #region Private Methods + private async Task ReloadData() { ListMSE = await MMDataService.MseGetAll(); } - public void Dispose() + private async Task setupConf() { - fastTimer.Stop(); - fastTimer.Dispose(); - slowTimer.Stop(); - slowTimer.Dispose(); - } - - private static System.Timers.Timer fastTimer = new System.Timers.Timer(4000); - private static System.Timers.Timer slowTimer = new System.Timers.Timer(300000); - - public void StartTimer() - { - // timer veloce - fastTimer = new System.Timers.Timer(fastRefreshMs); - fastTimer.Elapsed += ElapsedFastTimer; - fastTimer.Enabled = true; - fastTimer.Start(); - // timer lento - slowTimer = new System.Timers.Timer(slowRefreshMs); - slowTimer.Elapsed += ElapsedSlowTimer; - slowTimer.Enabled = true; - slowTimer.Start(); - } - - public void ElapsedFastTimer(Object source, System.Timers.ElapsedEventArgs e) - { - var pUpd = Task.Run(async () => + CurrConfig = await MMDataService.ConfigGetAll(); + if (CurrConfig != null && CurrConfig.Count > 0) { - await ReloadData(); - //await Task.Delay(1); - await InvokeAsync(StateHasChanged); - }); - pUpd.Wait(); + // sistemo i parametri opzionali... + + getConfValInt("keepAliveMin", ref keepAliveMin); + getConfValInt("MON_maxCol", ref maxCol); + int intDoAnim = 0; + 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}"); + } } - public async void ElapsedSlowTimer(Object source, System.Timers.ElapsedEventArgs e) - { - ListMSE = null; - NavManager.NavigateTo(NavManager.Uri); - } + #endregion Private Methods } } \ No newline at end of file diff --git a/MP.Mon/Resources/ChangeLog.html b/MP.Mon/Resources/ChangeLog.html index 22e8ca71..0a0853a2 100644 --- a/MP.Mon/Resources/ChangeLog.html +++ b/MP.Mon/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MON MAPO -

Versione: 6.15.2206.417

+

Versione: 6.15.2206.418


Note di rilascio:
  • diff --git a/MP.Mon/Resources/VersNum.txt b/MP.Mon/Resources/VersNum.txt index eefcbdd1..ba526264 100644 --- a/MP.Mon/Resources/VersNum.txt +++ b/MP.Mon/Resources/VersNum.txt @@ -1 +1 @@ -6.15.2206.417 +6.15.2206.418 diff --git a/MP.Mon/Resources/manifest.xml b/MP.Mon/Resources/manifest.xml index dd92f0a3..cda6bc9e 100644 --- a/MP.Mon/Resources/manifest.xml +++ b/MP.Mon/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.15.2206.417 + 6.15.2206.418 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