refresh WASM

This commit is contained in:
Samuele Locatelli
2022-07-08 19:51:24 +02:00
parent cae553c47f
commit 1a019f1c72
9 changed files with 157 additions and 585 deletions
-18
View File
@@ -1,18 +0,0 @@
@page "/counter"
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role="status">Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
-46
View File
@@ -1,46 +0,0 @@
@page "/fetchmse"
@using MP.Data
@using MP.Data.DatabaseModels
@inject HttpClient Http
<PageTitle>MP MON</PageTitle>
<div class="row statusMap mx-1 my-1">
@if (listMSE == null)
{
<div class="col-12">
<LoadingData></LoadingData>
</div>
}
else if (listMSE.Count == 0)
{
<div class="col-12">
<div class="alert alert-warning">
No data found
</div>
</div>
}
else
{
int currIdx = 0;
foreach (var recordIob in listMSE)
{
<DetailMSE CurrRecord="@recordIob" currTagConf="@getIobTag(recordIob.IdxMacchina)" currTagVal="@getTagVal(recordIob.IdxMacchina)" doAnimate="@doAnimate" keepAliveMin="@keepAliveMin" showArt="@showArt"></DetailMSE>
currIdx++;
if (currIdx >= maxCol)
{
currIdx = 0;
@((MarkupString)"</div><div class=\"row statusMap mx-1 my-1\">");
}
}
// controllo se devo "chiudere riga...
int currNum = (currIdx % maxCol);
while (currNum < (maxCol))
{
@((MarkupString)"<div class=\"col machBlock\">&nbsp;</div>")
;
currNum++;
}
}
</div>
-216
View File
@@ -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<MappaStatoExpl>? 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<List<MappaStatoExpl>>("api/MSE");
listMSE = new List<MappaStatoExpl>();
for (int i = 0; i < 4; i++)
{
listMSE.AddRange(singleData);
}
#else
listMSE = await Http.GetFromJsonAsync<List<MappaStatoExpl>>("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
}
/// <summary>
/// Recupera il valore e se trovato aggiorna
/// </summary>
/// <param name = "chiave">Valore da cercare</param>
/// <param name = "varObj">String in cui salvare il valore se trovato</param>
/// <returns></returns>
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;
}
/// <summary>
/// Recupera il valore e se trovato aggiorna
/// </summary>
/// <param name = "chiave">Valore da cercare</param>
/// <param name = "varObj">Int in cui salvare il valore se trovato</param>
/// <returns></returns>
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;
}
/// <summary>
/// Recupera da conf eventuale setup tag dell'IOB indicato
/// </summary>
/// <param name = "codIob"></param>
/// <returns></returns>
protected List<TagData>? getIobTag(string codIob)
{
List<TagData>? answ = null;
#if false
if (MMDataService.currTagConf != null)
{
// cerco x chiave IOB...
if (MMDataService.currTagConf.ContainsKey(codIob))
{
answ = MMDataService.currTagConf[codIob];
}
}
#endif
return answ;
}
/// <summary>
/// Recupera da redis (in una chiamata soltanto) tutti i valori richiesti e compone un dizionario x ottimizzare visualizzazione
/// </summary>
/// <param name = "codIob"></param>
/// <returns></returns>
protected Dictionary<string, string> getTagVal(string codIob)
{
Dictionary<string, string> answ = new Dictionary<string, string>();
#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;
}
}
}
+152 -130
View File
@@ -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<MappaStatoExpl>? 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
/// <summary>
/// Recupera il valore e se trovato aggiorna
/// </summary>
/// <param name="chiave">Valore da cercare</param>
/// <param name="varObj">String in cui salvare il valore se trovato</param>
/// <returns></returns>
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;
}
/// <summary>
/// Recupera il valore e se trovato aggiorna
/// </summary>
/// <param name="chiave">Valore da cercare</param>
/// <param name="varObj">Int in cui salvare il valore se trovato</param>
/// <returns></returns>
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;
}
/// <summary>
/// Recupera da conf eventuale setup tag dell'IOB indicato
/// </summary>
/// <param name="codIob"></param>
/// <returns></returns>
protected List<TagData>? getIobTag(string codIob)
{
List<TagData>? answ = null;
#if false
if (MMDataService.currTagConf != null)
{
// cerco x chiave IOB...
if (MMDataService.currTagConf.ContainsKey(codIob))
{
answ = MMDataService.currTagConf[codIob];
}
}
#endif
return answ;
}
/// <summary>
/// Recupera da redis (in una chiamata soltanto) tutti i valori richiesti e compone un
/// dizionario x ottimizzare visualizzazione
/// </summary>
/// <param name="codIob"></param>
/// <returns></returns>
protected Dictionary<string, string> getTagVal(string codIob)
{
Dictionary<string, string> answ = new Dictionary<string, string>();
#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<MappaStatoExpl>? 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
}
/// <summary>
/// Recupera il valore e se trovato aggiorna
/// </summary>
/// <param name = "chiave">Valore da cercare</param>
/// <param name = "varObj">String in cui salvare il valore se trovato</param>
/// <returns></returns>
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;
}
/// <summary>
/// Recupera il valore e se trovato aggiorna
/// </summary>
/// <param name = "chiave">Valore da cercare</param>
/// <param name = "varObj">Int in cui salvare il valore se trovato</param>
/// <returns></returns>
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;
}
/// <summary>
/// Recupera da conf eventuale setup tag dell'IOB indicato
/// </summary>
/// <param name = "codIob"></param>
/// <returns></returns>
protected List<TagData>? getIobTag(string codIob)
{
List<TagData>? answ = null;
#if false
if (MMDataService.currTagConf != null)
{
// cerco x chiave IOB...
if (MMDataService.currTagConf.ContainsKey(codIob))
{
answ = MMDataService.currTagConf[codIob];
}
}
#endif
return answ;
}
/// <summary>
/// Recupera da redis (in una chiamata soltanto) tutti i valori richiesti e compone un dizionario x ottimizzare visualizzazione
/// </summary>
/// <param name = "codIob"></param>
/// <returns></returns>
protected Dictionary<string, string> getTagVal(string codIob)
{
Dictionary<string, string> answ = new Dictionary<string, string>();
#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
}
}
-39
View File
@@ -1,39 +0,0 @@
<div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="">MP.WASM.Mon</a>
<button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</div>
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
<nav class="flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> Home
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="oi oi-plus" aria-hidden="true"></span> Counter
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="fetchmse">
<span class="oi oi-list-rich" aria-hidden="true"></span> MSE
</NavLink>
</div>
</nav>
</div>
@code {
private bool collapseNavMenu = true;
private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null;
private void ToggleNavMenu()
{
collapseNavMenu = !collapseNavMenu;
}
}
@@ -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;
}
}
-1
View File
@@ -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 {
+4 -1
View File
@@ -7,7 +7,8 @@
<title>MP.WASM.Mon</title>
<base href="/" />
<link rel="stylesheet" href="lib/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="css/site.css" />
<link rel="stylesheet" href="css/fonts.min.css" />
<link rel="stylesheet" href="css/site.min.css" />
<link rel="stylesheet" href="lib/font-awesome/css/all.css" />
<!--<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />-->
@@ -24,6 +25,8 @@
<a class="dismiss">🗙</a>
</div>
<script src="_framework/blazor.webassembly.js"></script>
<!--<script src="lib/font-awesome/js/all.min.js"></script>
<script src="lib/bootstrap/js/bootstrap.min.js"></script>-->
</body>
</html>
@@ -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
/// <summary>
/// Avvio controller dei dati MSE
/// </summary>
/// <param name="configuration"></param>
/// <param name="logger"></param>
public MSEController(IConfiguration configuration, ILogger<MSEController> 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
/// <summary>
/// Dizionario dei tag configurati per IOB
/// </summary>
@@ -97,14 +53,6 @@ namespace MP.WASM.Mon.Server.Controllers
return _DataService.ConfigGetAll();
}
#if false
public void Dispose()
{
// Clear database controller
dbController.Dispose();
}
#endif
/// <summary>
/// restituisce il valore da REDIS associato al tag richeisto
/// </summary>
@@ -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
/// </summary>
private ConnectionMultiplexer redisConn = null!;
//ISubscriber sub = redis.GetSubscriber();
/// <summary>
/// Oggetto DB redis da impiegare x chiamate R/W
/// </summary>
@@ -164,17 +104,6 @@ namespace MP.WASM.Mon.Server.Controllers
#region Private Methods
//[HttpGet]
//public IEnumerable<WeatherForecast> 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();
//}
/// <summary>
/// Prova a caricare da file la conf degli IOB se presente
/// </summary>