From 1a019f1c72618da5d28fca905c983b908d3d7d9b Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 8 Jul 2022 19:51:24 +0200 Subject: [PATCH] refresh WASM --- MP.WASM.Mon/Client/Pages/Counter.razor | 18 -- MP.WASM.Mon/Client/Pages/FetchMSE.razor | 46 --- MP.WASM.Mon/Client/Pages/FetchMSE.razor.cs | 216 -------------- MP.WASM.Mon/Client/Pages/Index.razor.cs | 282 ++++++++++-------- MP.WASM.Mon/Client/Shared/NavMenu.razor | 39 --- MP.WASM.Mon/Client/Shared/NavMenu.razor.css | 62 ---- MP.WASM.Mon/Client/wwwroot/css/app.css | 1 - MP.WASM.Mon/Client/wwwroot/index.html | 5 +- .../Server/Controllers/MSEController.cs | 73 +---- 9 files changed, 157 insertions(+), 585 deletions(-) delete mode 100644 MP.WASM.Mon/Client/Pages/Counter.razor delete mode 100644 MP.WASM.Mon/Client/Pages/FetchMSE.razor delete mode 100644 MP.WASM.Mon/Client/Pages/FetchMSE.razor.cs delete mode 100644 MP.WASM.Mon/Client/Shared/NavMenu.razor delete mode 100644 MP.WASM.Mon/Client/Shared/NavMenu.razor.css diff --git a/MP.WASM.Mon/Client/Pages/Counter.razor b/MP.WASM.Mon/Client/Pages/Counter.razor deleted file mode 100644 index ef23cb31..00000000 --- a/MP.WASM.Mon/Client/Pages/Counter.razor +++ /dev/null @@ -1,18 +0,0 @@ -@page "/counter" - -Counter - -

Counter

- -

Current count: @currentCount

- - - -@code { - private int currentCount = 0; - - private void IncrementCount() - { - currentCount++; - } -} diff --git a/MP.WASM.Mon/Client/Pages/FetchMSE.razor b/MP.WASM.Mon/Client/Pages/FetchMSE.razor deleted file mode 100644 index 8ba48987..00000000 --- a/MP.WASM.Mon/Client/Pages/FetchMSE.razor +++ /dev/null @@ -1,46 +0,0 @@ -@page "/fetchmse" -@using MP.Data -@using MP.Data.DatabaseModels -@inject HttpClient Http - -MP MON - -
- @if (listMSE == null) - { -
- -
- } - else if (listMSE.Count == 0) - { -
-
- No data found -
-
- } - else - { - int currIdx = 0; - foreach (var recordIob in listMSE) - { - - currIdx++; - if (currIdx >= maxCol) - { - currIdx = 0; - @((MarkupString)"
"); - } - } - // controllo se devo "chiudere riga... - int currNum = (currIdx % maxCol); - while (currNum < (maxCol)) - { - @((MarkupString)"
 
") - ; - currNum++; - - } - } -
diff --git a/MP.WASM.Mon/Client/Pages/FetchMSE.razor.cs b/MP.WASM.Mon/Client/Pages/FetchMSE.razor.cs deleted file mode 100644 index 68d8a0a6..00000000 --- a/MP.WASM.Mon/Client/Pages/FetchMSE.razor.cs +++ /dev/null @@ -1,216 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Components; -using System.Net.Http; -using System.Net.Http.Json; -using Microsoft.AspNetCore.Components.Forms; -using Microsoft.AspNetCore.Components.Routing; -using Microsoft.AspNetCore.Components.Web; -using Microsoft.AspNetCore.Components.Web.Virtualization; -using Microsoft.AspNetCore.Components.WebAssembly.Http; -using Microsoft.JSInterop; -using MP.WASM.Mon.Client; -using MP.WASM.Mon.Client.Shared; -using MP.WASM.Mon.Client.Components; -using MP.Data; -using MP.Data.Conf; -using MP.Data.DatabaseModels; -using NLog; - -namespace MP.WASM.Mon.Client.Pages -{ - public partial class FetchMSE - { - private List? listMSE = null; - 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); - protected int fastRefreshMs - { - get => 1000 * fastRefreshSec; - } - protected int slowRefreshMs - { - get => 1000 * slowRefreshSec; - } - - protected bool doAnimate = true; - protected int fastRefreshSec = 2; - protected int keepAliveMin = 1; - protected int maxCol = 6; - protected string showArt = ""; - protected int slowRefreshSec = 300; - - public void ElapsedFastTimer(object? source, System.Timers.ElapsedEventArgs e) - { - var pUpd = Task.Run(async () => - { - await ReloadData(); - await Task.Delay(1); - Log.Trace("Elapsed Fast Timer"); - await InvokeAsync(StateHasChanged); - }); - pUpd.Wait(); - } - - public async void ElapsedSlowTimer(object? source, System.Timers.ElapsedEventArgs e) - { - listMSE = null; - await Task.Delay(1); - Log.Trace("Elapsed Slow Timer"); -#if false - NavManager.NavigateTo(NavManager.Uri); -#endif - } - - 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(); - } - - protected override async Task OnInitializedAsync() - { - await setupConf(); - await ReloadData(); - StartTimer(); - } - - 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++) - { - listMSE.AddRange(singleData); - } -#else - listMSE = await Http.GetFromJsonAsync>("api/MSE"); -#endif - } - - private async Task setupConf() - { -#if false - CurrConfig = await MMDataService.ConfigGetAll(); - 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}"); - } -#endif - } - - /// - /// 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 false - if (CurrConfig != null && CurrConfig.Count > 0) - { - // sistemo i parametri opzionali... - ConfigModel? risultato = CurrConfig.FirstOrDefault(x => x.Chiave == chiave); - if (risultato != null) - { - varObj = risultato.Valore; - answ = !string.IsNullOrEmpty(risultato.Valore); - } - } -#endif - - return answ; - } - - /// - /// Recupera il valore e se trovato aggiorna - /// - /// Valore da cercare - /// Int in cui salvare il valore se trovato - /// - protected bool getConfValInt(string chiave, ref int varObj) - { - bool answ = false; -#if false - if (CurrConfig != null && CurrConfig.Count > 0) - { - // sistemo i parametri opzionali... - ConfigModel? risultato = CurrConfig.FirstOrDefault(x => x.Chiave == chiave); - if (risultato != null) - { - answ = int.TryParse(risultato.Valore, out varObj); - } - } -#endif - - return answ; - } - - /// - /// Recupera da conf eventuale setup tag dell'IOB indicato - /// - /// - /// - protected List? getIobTag(string codIob) - { - List? answ = null; -#if false - if (MMDataService.currTagConf != null) - { - // cerco x chiave IOB... - if (MMDataService.currTagConf.ContainsKey(codIob)) - { - answ = MMDataService.currTagConf[codIob]; - } - } -#endif - - 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(); -#if false - // recupero conf tags... - var currTags = getIobTag(codIob); - if (currTags != null && currTags.Count > 0) - { - // FIXME TODO !!!! FARE !!!! - da verificare - answ = currTags.ToDictionary(x => x.TagLocation, x => MMDataService.getTagConf(x.TagLocation)); - } -#endif - - return answ; - } - } -} \ 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 42723414..f2218755 100644 --- a/MP.WASM.Mon/Client/Pages/Index.razor.cs +++ b/MP.WASM.Mon/Client/Pages/Index.razor.cs @@ -1,48 +1,25 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Components; -using System.Net.Http; -using System.Net.Http.Json; -using Microsoft.AspNetCore.Components.Forms; -using Microsoft.AspNetCore.Components.Routing; -using Microsoft.AspNetCore.Components.Web; -using Microsoft.AspNetCore.Components.Web.Virtualization; -using Microsoft.AspNetCore.Components.WebAssembly.Http; -using Microsoft.JSInterop; -using MP.WASM.Mon.Client; -using MP.WASM.Mon.Client.Shared; -using MP.WASM.Mon.Client.Components; -using MP.Data; using MP.Data.Conf; using MP.Data.DatabaseModels; using NLog; - +using System.Net.Http.Json; namespace MP.WASM.Mon.Client.Pages { - public partial class Index + public partial class Index : IDisposable { - private List? listMSE = null; - 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); - protected int fastRefreshMs - { - get => 1000 * fastRefreshSec; - } - protected int slowRefreshMs - { - get => 1000 * slowRefreshSec; - } + #region Public Methods - protected bool doAnimate = true; - protected int fastRefreshSec = 2; - protected int keepAliveMin = 1; - protected int maxCol = 6; - protected string showArt = ""; - protected int slowRefreshSec = 300; + public void Dispose() + { +#if false + //fastTimer.Elapsed -= ElapsedFastTimer; + fastTimer.Stop(); + fastTimer.Dispose(); + //slowTimer.Elapsed -= ElapsedSlowTimer; + slowTimer.Stop(); + slowTimer.Dispose(); +#endif + } public void ElapsedFastTimer(object? source, System.Timers.ElapsedEventArgs e) { @@ -62,7 +39,7 @@ namespace MP.WASM.Mon.Client.Pages await Task.Delay(1); Log.Trace("Elapsed Slow Timer"); #if false - NavManager.NavigateTo(NavManager.Uri); + NavManager.NavigateTo(NavManager.Uri); #endif } @@ -80,6 +57,128 @@ namespace MP.WASM.Mon.Client.Pages slowTimer.Start(); } + #endregion Public Methods + + #region Protected Fields + + protected bool doAnimate = true; + protected int fastRefreshSec = 2; + protected int keepAliveMin = 1; + protected int maxCol = 6; + protected string showArt = ""; + protected int slowRefreshSec = 300; + + #endregion Protected Fields + + #region Protected Properties + + protected int fastRefreshMs + { + get => 1000 * fastRefreshSec; + } + + protected int slowRefreshMs + { + get => 1000 * slowRefreshSec; + } + + #endregion Protected Properties + + #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 false + if (CurrConfig != null && CurrConfig.Count > 0) + { + // sistemo i parametri opzionali... + ConfigModel? risultato = CurrConfig.FirstOrDefault(x => x.Chiave == chiave); + if (risultato != null) + { + varObj = risultato.Valore; + answ = !string.IsNullOrEmpty(risultato.Valore); + } + } +#endif + + return answ; + } + + /// + /// Recupera il valore e se trovato aggiorna + /// + /// Valore da cercare + /// Int in cui salvare il valore se trovato + /// + protected bool getConfValInt(string chiave, ref int varObj) + { + bool answ = false; +#if false + if (CurrConfig != null && CurrConfig.Count > 0) + { + // sistemo i parametri opzionali... + ConfigModel? risultato = CurrConfig.FirstOrDefault(x => x.Chiave == chiave); + if (risultato != null) + { + answ = int.TryParse(risultato.Valore, out varObj); + } + } +#endif + + return answ; + } + + /// + /// Recupera da conf eventuale setup tag dell'IOB indicato + /// + /// + /// + protected List? getIobTag(string codIob) + { + List? answ = null; +#if false + if (MMDataService.currTagConf != null) + { + // cerco x chiave IOB... + if (MMDataService.currTagConf.ContainsKey(codIob)) + { + answ = MMDataService.currTagConf[codIob]; + } + } +#endif + + 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(); +#if false + // recupero conf tags... + var currTags = getIobTag(codIob); + if (currTags != null && currTags.Count > 0) + { + // FIXME TODO !!!! FARE !!!! - da verificare + answ = currTags.ToDictionary(x => x.TagLocation, x => MMDataService.getTagConf(x.TagLocation)); + } +#endif + + return answ; + } + protected override async Task OnInitializedAsync() { await setupConf(); @@ -87,6 +186,19 @@ namespace MP.WASM.Mon.Client.Pages StartTimer(); } + #endregion Protected Methods + + #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? listMSE = null; + + #endregion Private Fields + + #region Private Methods + private async Task ReloadData() { #if DEBUG @@ -118,100 +230,10 @@ namespace MP.WASM.Mon.Client.Pages getConfValInt("MSE_cacheDuration", ref fastRefreshSec); getConfVal("sART", ref showArt); Log.Info($"Effettuato setup parametri | keepAlive: {keepAliveMin} | MaxCol: {maxCol} | doAnimate: {doAnimate} | slowRefreshSec: {slowRefreshSec} | fastRefreshSec: {fastRefreshSec}"); - } + } #endif } - /// - /// 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 false - if (CurrConfig != null && CurrConfig.Count > 0) - { - // sistemo i parametri opzionali... - ConfigModel? risultato = CurrConfig.FirstOrDefault(x => x.Chiave == chiave); - if (risultato != null) - { - varObj = risultato.Valore; - answ = !string.IsNullOrEmpty(risultato.Valore); - } - } -#endif - - return answ; - } - - /// - /// Recupera il valore e se trovato aggiorna - /// - /// Valore da cercare - /// Int in cui salvare il valore se trovato - /// - protected bool getConfValInt(string chiave, ref int varObj) - { - bool answ = false; -#if false - if (CurrConfig != null && CurrConfig.Count > 0) - { - // sistemo i parametri opzionali... - ConfigModel? risultato = CurrConfig.FirstOrDefault(x => x.Chiave == chiave); - if (risultato != null) - { - answ = int.TryParse(risultato.Valore, out varObj); - } - } -#endif - - return answ; - } - - /// - /// Recupera da conf eventuale setup tag dell'IOB indicato - /// - /// - /// - protected List? getIobTag(string codIob) - { - List? answ = null; -#if false - if (MMDataService.currTagConf != null) - { - // cerco x chiave IOB... - if (MMDataService.currTagConf.ContainsKey(codIob)) - { - answ = MMDataService.currTagConf[codIob]; - } - } -#endif - - 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(); -#if false - // recupero conf tags... - var currTags = getIobTag(codIob); - if (currTags != null && currTags.Count > 0) - { - // FIXME TODO !!!! FARE !!!! - da verificare - answ = currTags.ToDictionary(x => x.TagLocation, x => MMDataService.getTagConf(x.TagLocation)); - } -#endif - - return answ; - } + #endregion Private Methods } } \ No newline at end of file diff --git a/MP.WASM.Mon/Client/Shared/NavMenu.razor b/MP.WASM.Mon/Client/Shared/NavMenu.razor deleted file mode 100644 index e1846d0c..00000000 --- a/MP.WASM.Mon/Client/Shared/NavMenu.razor +++ /dev/null @@ -1,39 +0,0 @@ - - -
- -
- -@code { - private bool collapseNavMenu = true; - - private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null; - - private void ToggleNavMenu() - { - collapseNavMenu = !collapseNavMenu; - } -} diff --git a/MP.WASM.Mon/Client/Shared/NavMenu.razor.css b/MP.WASM.Mon/Client/Shared/NavMenu.razor.css deleted file mode 100644 index acc5f9f8..00000000 --- a/MP.WASM.Mon/Client/Shared/NavMenu.razor.css +++ /dev/null @@ -1,62 +0,0 @@ -.navbar-toggler { - background-color: rgba(255, 255, 255, 0.1); -} - -.top-row { - height: 3.5rem; - background-color: rgba(0,0,0,0.4); -} - -.navbar-brand { - font-size: 1.1rem; -} - -.oi { - width: 2rem; - font-size: 1.1rem; - vertical-align: text-top; - top: -2px; -} - -.nav-item { - font-size: 0.9rem; - padding-bottom: 0.5rem; -} - - .nav-item:first-of-type { - padding-top: 1rem; - } - - .nav-item:last-of-type { - padding-bottom: 1rem; - } - - .nav-item ::deep a { - color: #d7d7d7; - border-radius: 4px; - height: 3rem; - display: flex; - align-items: center; - line-height: 3rem; - } - -.nav-item ::deep a.active { - background-color: rgba(255,255,255,0.25); - color: white; -} - -.nav-item ::deep a:hover { - background-color: rgba(255,255,255,0.1); - color: white; -} - -@media (min-width: 641px) { - .navbar-toggler { - display: none; - } - - .collapse { - /* Never collapse the sidebar for wide screens */ - display: block; - } -} diff --git a/MP.WASM.Mon/Client/wwwroot/css/app.css b/MP.WASM.Mon/Client/wwwroot/css/app.css index 9cd148f7..62619b01 100644 --- a/MP.WASM.Mon/Client/wwwroot/css/app.css +++ b/MP.WASM.Mon/Client/wwwroot/css/app.css @@ -1,7 +1,6 @@ @import url('open-iconic/font/css/open-iconic-bootstrap.min.css'); html, body { - font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; } h1:focus { diff --git a/MP.WASM.Mon/Client/wwwroot/index.html b/MP.WASM.Mon/Client/wwwroot/index.html index 752a9e55..6d26eeef 100644 --- a/MP.WASM.Mon/Client/wwwroot/index.html +++ b/MP.WASM.Mon/Client/wwwroot/index.html @@ -7,7 +7,8 @@ MP.WASM.Mon - + + @@ -24,6 +25,8 @@ 🗙 + diff --git a/MP.WASM.Mon/Server/Controllers/MSEController.cs b/MP.WASM.Mon/Server/Controllers/MSEController.cs index 57b19398..55cc8b9e 100644 --- a/MP.WASM.Mon/Server/Controllers/MSEController.cs +++ b/MP.WASM.Mon/Server/Controllers/MSEController.cs @@ -5,7 +5,6 @@ using MP.WASM.Mon.Data; using Newtonsoft.Json; using NLog; using StackExchange.Redis; -using System.Text; namespace MP.WASM.Mon.Server.Controllers { @@ -31,57 +30,14 @@ namespace MP.WASM.Mon.Server.Controllers _configuration = configuration; _DataService = DataService; Log.Info("Avviata classe MSEController"); - - // setup conf IOB da dizionario tryLoadIobTags(); } - -#if false - /// - /// Avvio controller dei dati MSE - /// - /// - /// - public MSEController(IConfiguration configuration, ILogger logger) - { - _logger = logger; - _configuration = configuration; - // setup compoenti REDIS - this.redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis")); - this.redisDb = this.redisConn.GetDatabase(); - //// setup canali pub/sub - //actLogPipe = new MessagePipe(redisConn, Constants.ACT_LOG_M_QUEUE); - - // conf DB - string connStr = _configuration.GetConnectionString("Mp.Mon"); - if (string.IsNullOrEmpty(connStr)) - { - _logger.LogError("ConnString empty!"); - } - else - { - 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()); - } - - // setup conf IOB da dizionario - tryLoadIobTags(); - } -#endif - #endregion Public Constructors #region Public Properties -#if false - public static MP.Data.Controllers.MpMonController dbController { get; set; } = null!; -#endif - /// /// Dizionario dei tag configurati per IOB /// @@ -97,14 +53,6 @@ namespace MP.WASM.Mon.Server.Controllers return _DataService.ConfigGetAll(); } -#if false - public void Dispose() - { - // Clear database controller - dbController.Dispose(); - } -#endif - /// /// restituisce il valore da REDIS associato al tag richeisto /// @@ -113,14 +61,7 @@ namespace MP.WASM.Mon.Server.Controllers [HttpGet("getTagConf/{redKey}")] public string getTagConf(string redKey) { - string outVal = ""; - // cerco in REDIS la conf x l'IOB - var rawData = redisDb.StringGet(redKey); - if (!string.IsNullOrEmpty(rawData)) - { - outVal = $"{rawData}"; - } - return outVal; + return _DataService.getTagConf(redKey); } [HttpGet("getMachines")] @@ -154,7 +95,6 @@ namespace MP.WASM.Mon.Server.Controllers /// private ConnectionMultiplexer redisConn = null!; - //ISubscriber sub = redis.GetSubscriber(); /// /// Oggetto DB redis da impiegare x chiamate R/W /// @@ -164,17 +104,6 @@ namespace MP.WASM.Mon.Server.Controllers #region Private Methods - //[HttpGet] - //public IEnumerable Get() - //{ - // return Enumerable.Range(1, 5).Select(index => new WeatherForecast - // { - // Date = DateTime.Now.AddDays(index), - // TemperatureC = Random.Shared.Next(-20, 55), - // Summary = Summaries[Random.Shared.Next(Summaries.Length)] - // }) - // .ToArray(); - //} /// /// Prova a caricare da file la conf degli IOB se presente ///