diff --git a/MP.Data/Controllers/MpMonController.cs b/MP.Data/Controllers/MpMonController.cs index b6738ecd..9c2ed87b 100644 --- a/MP.Data/Controllers/MpMonController.cs +++ b/MP.Data/Controllers/MpMonController.cs @@ -72,6 +72,23 @@ namespace MP.Data.Controllers return dbResult; } + /// + /// Elenco da tabella Macchine + /// + /// + public List ConfigGetAll() + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbSetConfig + .OrderBy(x => x.Chiave) + .ToList(); + } + return dbResult; + } + /// /// Elenco da tabella MappaStatoExpl /// diff --git a/MP.Data/DatabaseModels/ConfigModel.cs b/MP.Data/DatabaseModels/ConfigModel.cs new file mode 100644 index 00000000..eb4a1ac3 --- /dev/null +++ b/MP.Data/DatabaseModels/ConfigModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; + +namespace MP.Data.DatabaseModels +{ + [Table("Config")] + public partial class ConfigModel + { + public string Chiave { get; set; } + public string Valore { get; set; } + /// + /// Valore di default/riferimento per la variabile + /// + public string ValoreStd { get; set; } + public string Note { get; set; } + } +} diff --git a/MP.Data/MoonProContext.cs b/MP.Data/MoonProContext.cs index 27e32099..957d91ae 100644 --- a/MP.Data/MoonProContext.cs +++ b/MP.Data/MoonProContext.cs @@ -37,6 +37,7 @@ namespace MP.Data public virtual DbSet DbSetArticoli { get; set; } public virtual DbSet DbSetMacchine { get; set; } public virtual DbSet DbSetMSE { get; set; } + public virtual DbSet DbSetConfig { get; set; } #endregion Public Properties @@ -204,6 +205,24 @@ namespace MP.Data .HasMaxLength(250) .HasColumnName("url"); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Chiave); + + entity.ToTable("Config"); + + entity.Property(e => e.Chiave) + .HasMaxLength(50) + .HasColumnName("chiave"); + + entity.Property(e => e.Note).HasColumnName("note"); + + entity.Property(e => e.Valore).HasColumnName("valore"); + + entity.Property(e => e.ValoreStd) + .HasColumnName("valoreStd") + .HasComment("Valore di default/riferimento per la variabile"); + }); OnModelCreatingPartial(modelBuilder); } diff --git a/MP.Mon/Components/CmpFooter.razor b/MP.Mon/Components/CmpFooter.razor index 74a64b8b..507af4e6 100644 --- a/MP.Mon/Components/CmpFooter.razor +++ b/MP.Mon/Components/CmpFooter.razor @@ -3,13 +3,45 @@ Mapo MON @(DateTime.Today.Year) | v.@version
- @adesso | Egalware + @($"{DateTime.Now:HH:mm:ss}") | Egalware
@code { - protected DateTime adesso = DateTime.Now; Version version = typeof(Program).Assembly.GetName().Version; + protected override async Task OnInitializedAsync() + { + StartTimer(); + } + + public void Dispose() + { + aTimer.Stop(); + aTimer.Dispose(); + } + + private static System.Timers.Timer aTimer; + + 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(); + } + + public void ElapsedTimer(Object source, System.Timers.ElapsedEventArgs e) + { + var pUpd = Task.Run(async () => + { + //await ReloadData(); + await Task.Delay(1); + await InvokeAsync(StateHasChanged); + }); + pUpd.Wait(); + } } \ No newline at end of file diff --git a/MP.Mon/Components/CmpHeader.razor b/MP.Mon/Components/CmpHeader.razor new file mode 100644 index 00000000..b2b0ba34 --- /dev/null +++ b/MP.Mon/Components/CmpHeader.razor @@ -0,0 +1,49 @@ +
+ + MP MONitor +
+
+ + @($"{DateTime.Now:dddd dd MMMM yyyy}") + + + EgalWare +
+ +@code { + + protected override async Task OnInitializedAsync() + { + StartTimer(); + } + + public void Dispose() + { + aTimer.Stop(); + aTimer.Dispose(); + } + + private static System.Timers.Timer aTimer; + + public void StartTimer() + { + int tOutPeriod = 60000; + //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 () => + { + //await ReloadData(); + await Task.Delay(1); + await InvokeAsync(StateHasChanged); + }); + pUpd.Wait(); + } + +} \ No newline at end of file diff --git a/MP.Mon/Components/DetailMSE.razor b/MP.Mon/Components/DetailMSE.razor index 14bb6656..5dab45db 100644 --- a/MP.Mon/Components/DetailMSE.razor +++ b/MP.Mon/Components/DetailMSE.razor @@ -15,14 +15,12 @@
@CurrRecord.DescrizioneStato
-
@($"{CurrRecord.Durata:0.00}")'
+
@getMinSec((decimal)CurrRecord.Durata)
@*
OEE
xx%
*@
T.Ciclo
- @*
std: @CurrRecord.TCAssegnato
-
act: @CurrRecord.TCLavRT
*@
std: @getMinSec(@CurrRecord.TCAssegnato)
act: @getMinSec(@CurrRecord.TCLavRT)
diff --git a/MP.Mon/Data/MpDataService.cs b/MP.Mon/Data/MpDataService.cs index fa0a362c..f29f056b 100644 --- a/MP.Mon/Data/MpDataService.cs +++ b/MP.Mon/Data/MpDataService.cs @@ -1,16 +1,24 @@ - -using Newtonsoft.Json; +using MP.Data.DatabaseModels; using System.Text; namespace MP.Mon.Data { public class MpDataService : IDisposable { + #region Private Fields + private static IConfiguration _configuration; private static ILogger _logger; + #endregion Private Fields + + #region Public Fields + public static MP.Data.Controllers.MpMonController dbController; + #endregion Public Fields + + #region Public Constructors public MpDataService(IConfiguration configuration, ILogger logger) { @@ -31,25 +39,37 @@ namespace MP.Mon.Data _logger.LogInformation(sb.ToString()); } } + + #endregion Public Constructors + + #region Public Methods + + public Task> ConfigGetAll() + { + return Task.FromResult(dbController.ConfigGetAll().ToList()); + } + public void Dispose() { // Clear database controller dbController.Dispose(); } - public Task> MacchineGetAll() + public Task> MacchineGetAll() { return Task.FromResult(dbController.MacchineGetAll().ToList()); } - public Task> MseGetAll() + public Task> MseGetAll() { var dbResult = dbController.MseGetAll(); if (dbResult == null) { - dbResult = new List(); + dbResult = new List(); } return Task.FromResult(dbResult); } + + #endregion Public Methods } -} +} \ No newline at end of file diff --git a/MP.Mon/NLog.config b/MP.Mon/NLog.config new file mode 100644 index 00000000..bd414080 --- /dev/null +++ b/MP.Mon/NLog.config @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MP.Mon/Pages/Index.razor.cs b/MP.Mon/Pages/Index.razor.cs index f4dd4b87..e49945e4 100644 --- a/MP.Mon/Pages/Index.razor.cs +++ b/MP.Mon/Pages/Index.razor.cs @@ -17,21 +17,38 @@ using MP.Mon.Components; using MP.Data.DatabaseModels; using MP.Mon.Components; using MP.Mon.Data; +using NLog; namespace MP.Mon.Pages { public partial class Index : IDisposable { protected List? ListMSE = null; + List? CurrConfig = null; - protected int keepAliveMin = 5; // leggere da conf? - protected int maxCol = 6; // leggere da conf? + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - protected bool doAnimate = true; // leggere da conf? + protected int keepAliveMin = 1; + + protected int maxCol = 4; + + protected bool doAnimate = true; + + protected int slowRefreshSec = 300; + protected int fastRefreshSec = 10; + protected int slowRefreshMs + { + get => 1000 * slowRefreshSec; + } + protected int fastRefreshMs + { + get => 1000 * fastRefreshSec; + } protected override async Task OnInitializedAsync() { + await setupConf(); await ReloadData(); StartTimer(); } @@ -40,6 +57,49 @@ namespace MP.Mon.Pages [Inject] protected MpDataService MMDataService { get; set; } = null!; + [Inject] + protected NavigationManager NavManager { get; set; } = null!; + + private async Task setupConf() + { + 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); + + Log.Info($"Effettuato setup parametri | keepAlive: {keepAliveMin} | MaxCol: {maxCol} | doAnimate: {doAnimate} | pageRefreshSec: {slowRefreshSec} | fastRefreshSec: {fastRefreshSec}"); + } + } + + /// + /// Recupera il valore e se trovato aggiorna + /// + /// Valore da cercare + /// Oggetto in cui salvare il valore se trovato + /// + protected bool getConfValInt(string chiave, ref int varObj) + { + bool answ = 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); + } + } + return answ; + } + private async Task ReloadData() { ListMSE = await MMDataService.MseGetAll(); @@ -47,23 +107,30 @@ namespace MP.Mon.Pages public void Dispose() { - aTimer.Stop(); - aTimer.Dispose(); + fastTimer.Stop(); + fastTimer.Dispose(); + slowTimer.Stop(); + slowTimer.Dispose(); } - private static System.Timers.Timer aTimer; + private static System.Timers.Timer fastTimer; + private static System.Timers.Timer slowTimer; public void StartTimer() { - int tOutPeriod = 2000; - //int.TryParse(Configuration["ReloadStatusTimer"], out tOutPeriod); - aTimer = new System.Timers.Timer(tOutPeriod); - aTimer.Elapsed += ElapsedTimer; - aTimer.Enabled = true; - aTimer.Start(); + // 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 ElapsedTimer(Object source, System.Timers.ElapsedEventArgs e) + public void ElapsedFastTimer(Object source, System.Timers.ElapsedEventArgs e) { var pUpd = Task.Run(async () => { @@ -73,5 +140,12 @@ namespace MP.Mon.Pages }); pUpd.Wait(); } + + public async void ElapsedSlowTimer(Object source, System.Timers.ElapsedEventArgs e) + { + ListMSE = null; + await Task.Delay(200); + NavManager.NavigateTo(NavManager.Uri); + } } } \ No newline at end of file diff --git a/MP.Mon/Shared/MainLayout.razor b/MP.Mon/Shared/MainLayout.razor index f17b6251..8d4876e5 100644 --- a/MP.Mon/Shared/MainLayout.razor +++ b/MP.Mon/Shared/MainLayout.razor @@ -4,26 +4,29 @@
+ @*
+
+ + MP MONitor +
+
+ + @($"{DateTime.Now:dddd dd MMMM yyyy, HH:mm}") + + + EgalWare +
+
*@
-
- - MP MONitor -
-
- - @($"{DateTime.Now:dddd dd MMMM yyyy, HH:mm}") - - - EgalWare -
+
@Body
-
+