From 7634fc42ba672e611aa7fd12ad274daa8bbba581 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 8 Jul 2022 17:27:08 +0200 Subject: [PATCH] Bozza riscrittura WASM applicazione MON --- MP-MON.sln | 18 -- MP-WAMON.sln | 49 +++ MP.WASM.Mon/Client/Components/CmpFooter.razor | 9 + .../Client/Components/CmpFooter.razor.cs | 58 ++++ MP.WASM.Mon/Client/Components/CmpHeader.razor | 49 +++ MP.WASM.Mon/Client/Components/DetailMSE.razor | 134 ++++++++ .../Client/Components/DetailMSE.razor.cs | 286 ++++++++++++++++++ .../Client/Components/LoadingData.razor | 6 + .../Client/Components/LoadingDataSmall.razor | 6 + MP.WASM.Mon/Client/MP.WASM.Mon.Client.csproj | 1 + MP.WASM.Mon/Client/Pages/FetchMSE.razor | 48 +++ MP.WASM.Mon/Client/Shared/NavMenu.razor | 7 +- MP.WASM.Mon/Client/_Imports.razor | 2 + .../Server/Controllers/MSEController.cs | 106 ++++--- 14 files changed, 715 insertions(+), 64 deletions(-) create mode 100644 MP-WAMON.sln create mode 100644 MP.WASM.Mon/Client/Components/CmpFooter.razor create mode 100644 MP.WASM.Mon/Client/Components/CmpFooter.razor.cs create mode 100644 MP.WASM.Mon/Client/Components/CmpHeader.razor create mode 100644 MP.WASM.Mon/Client/Components/DetailMSE.razor create mode 100644 MP.WASM.Mon/Client/Components/DetailMSE.razor.cs create mode 100644 MP.WASM.Mon/Client/Components/LoadingData.razor create mode 100644 MP.WASM.Mon/Client/Components/LoadingDataSmall.razor create mode 100644 MP.WASM.Mon/Client/Pages/FetchMSE.razor diff --git a/MP-MON.sln b/MP-MON.sln index 35405781..4e8c2f87 100644 --- a/MP-MON.sln +++ b/MP-MON.sln @@ -7,12 +7,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MP.Data", "MP.Data\MP.Data. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MP.Mon", "MP.Mon\MP.Mon.csproj", "{7780FA7A-3597-4098-81C1-DC9AD6AE7A98}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MP.WASM.Mon.Server", "MP.WASM.Mon\Server\MP.WASM.Mon.Server.csproj", "{4A98B7F4-4EC6-4284-9D6C-63203DB981B1}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MP.WASM.Mon.Client", "MP.WASM.Mon\Client\MP.WASM.Mon.Client.csproj", "{9BF7BDE7-016A-458C-8791-494FD4204301}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MP.WASM.Mon.Shared", "MP.WASM.Mon\Shared\MP.WASM.Mon.Shared.csproj", "{A3B1190C-6F98-434B-8B31-27522C78918A}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,18 +21,6 @@ Global {7780FA7A-3597-4098-81C1-DC9AD6AE7A98}.Debug|Any CPU.Build.0 = Debug|Any CPU {7780FA7A-3597-4098-81C1-DC9AD6AE7A98}.Release|Any CPU.ActiveCfg = Release|Any CPU {7780FA7A-3597-4098-81C1-DC9AD6AE7A98}.Release|Any CPU.Build.0 = Release|Any CPU - {4A98B7F4-4EC6-4284-9D6C-63203DB981B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4A98B7F4-4EC6-4284-9D6C-63203DB981B1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4A98B7F4-4EC6-4284-9D6C-63203DB981B1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4A98B7F4-4EC6-4284-9D6C-63203DB981B1}.Release|Any CPU.Build.0 = Release|Any CPU - {9BF7BDE7-016A-458C-8791-494FD4204301}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9BF7BDE7-016A-458C-8791-494FD4204301}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9BF7BDE7-016A-458C-8791-494FD4204301}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9BF7BDE7-016A-458C-8791-494FD4204301}.Release|Any CPU.Build.0 = Release|Any CPU - {A3B1190C-6F98-434B-8B31-27522C78918A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A3B1190C-6F98-434B-8B31-27522C78918A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A3B1190C-6F98-434B-8B31-27522C78918A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A3B1190C-6F98-434B-8B31-27522C78918A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MP-WAMON.sln b/MP-WAMON.sln new file mode 100644 index 00000000..35405781 --- /dev/null +++ b/MP-WAMON.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.32126.317 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MP.Data", "MP.Data\MP.Data.csproj", "{10BA8450-301D-49C7-8E1E-21B7469C225C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MP.Mon", "MP.Mon\MP.Mon.csproj", "{7780FA7A-3597-4098-81C1-DC9AD6AE7A98}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MP.WASM.Mon.Server", "MP.WASM.Mon\Server\MP.WASM.Mon.Server.csproj", "{4A98B7F4-4EC6-4284-9D6C-63203DB981B1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MP.WASM.Mon.Client", "MP.WASM.Mon\Client\MP.WASM.Mon.Client.csproj", "{9BF7BDE7-016A-458C-8791-494FD4204301}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MP.WASM.Mon.Shared", "MP.WASM.Mon\Shared\MP.WASM.Mon.Shared.csproj", "{A3B1190C-6F98-434B-8B31-27522C78918A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {10BA8450-301D-49C7-8E1E-21B7469C225C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {10BA8450-301D-49C7-8E1E-21B7469C225C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {10BA8450-301D-49C7-8E1E-21B7469C225C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {10BA8450-301D-49C7-8E1E-21B7469C225C}.Release|Any CPU.Build.0 = Release|Any CPU + {7780FA7A-3597-4098-81C1-DC9AD6AE7A98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7780FA7A-3597-4098-81C1-DC9AD6AE7A98}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7780FA7A-3597-4098-81C1-DC9AD6AE7A98}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7780FA7A-3597-4098-81C1-DC9AD6AE7A98}.Release|Any CPU.Build.0 = Release|Any CPU + {4A98B7F4-4EC6-4284-9D6C-63203DB981B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A98B7F4-4EC6-4284-9D6C-63203DB981B1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A98B7F4-4EC6-4284-9D6C-63203DB981B1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A98B7F4-4EC6-4284-9D6C-63203DB981B1}.Release|Any CPU.Build.0 = Release|Any CPU + {9BF7BDE7-016A-458C-8791-494FD4204301}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9BF7BDE7-016A-458C-8791-494FD4204301}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9BF7BDE7-016A-458C-8791-494FD4204301}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9BF7BDE7-016A-458C-8791-494FD4204301}.Release|Any CPU.Build.0 = Release|Any CPU + {A3B1190C-6F98-434B-8B31-27522C78918A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A3B1190C-6F98-434B-8B31-27522C78918A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A3B1190C-6F98-434B-8B31-27522C78918A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A3B1190C-6F98-434B-8B31-27522C78918A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {632D11D1-088B-4795-97E5-048534002558} + EndGlobalSection +EndGlobal diff --git a/MP.WASM.Mon/Client/Components/CmpFooter.razor b/MP.WASM.Mon/Client/Components/CmpFooter.razor new file mode 100644 index 00000000..e0e57471 --- /dev/null +++ b/MP.WASM.Mon/Client/Components/CmpFooter.razor @@ -0,0 +1,9 @@ +
+
+ Mapo MON @(DateTime.Today.Year) | v.@version +
+
+ @($"{DateTime.Now:HH:mm:ss}") | Egalware +
+
+ diff --git a/MP.WASM.Mon/Client/Components/CmpFooter.razor.cs b/MP.WASM.Mon/Client/Components/CmpFooter.razor.cs new file mode 100644 index 00000000..b2d4ac98 --- /dev/null +++ b/MP.WASM.Mon/Client/Components/CmpFooter.razor.cs @@ -0,0 +1,58 @@ +using NLog; + +namespace MP.WASM.Mon.Client.Components +{ + public partial class CmpFooter + { + #region Public Methods + + public void Dispose() + { + //aTimer.Elapsed -= ElapsedTimer; + 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(); + Log.Trace($"Elapsed Timer Footer"); + } + + 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 void OnInitialized() + { + var currAssembly = typeof(Program).Assembly.GetName(); + version = currAssembly.Version != null ? currAssembly.Version : new Version(); + StartTimer(); + } + + #endregion Protected Methods + + #region Private Fields + + private static System.Timers.Timer aTimer = null!; + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + private Version version = null!; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/MP.WASM.Mon/Client/Components/CmpHeader.razor b/MP.WASM.Mon/Client/Components/CmpHeader.razor new file mode 100644 index 00000000..1c2ae42d --- /dev/null +++ b/MP.WASM.Mon/Client/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.WASM.Mon/Client/Components/DetailMSE.razor b/MP.WASM.Mon/Client/Components/DetailMSE.razor new file mode 100644 index 00000000..f8e39dad --- /dev/null +++ b/MP.WASM.Mon/Client/Components/DetailMSE.razor @@ -0,0 +1,134 @@ +
+ @if (CurrRecord == null || !dataLoaded) + { + + } + else + { +
+
+ @CurrRecord.Nome +
+ @if (hasRow(1)) + { +
+ @foreach (var item in rowValues(1)) + { +
@item.TagName: @currVal(item.TagLocation)
+ } +
+ } + else + { +
+
Art
+
+ @if (showArt == "CodArticolo") + { + @CurrRecord.CodArticolo + } + else + { + if (string.IsNullOrEmpty(CurrRecord.Disegno)) + { + [@CurrRecord.CodArticolo] + } + else + { + @CurrRecord.Disegno + } + } +
+
+ } + @if (hasRow(2)) + { +
+ @foreach (var item in rowValues(2)) + { +
@item.TagName: @currVal(item.TagLocation)
+ } +
+ } + else + { +
+
@CurrRecord.DescrizioneStato
+
@getMinSec(getDecimal(@CurrRecord.Durata))
+
+ } + @if (hasRow(3)) + { +
+ @foreach (var item in rowValues(3)) + { +
@item.TagName: @currVal(item.TagLocation)
+ } +
+ } + else + { +
+ @*
OEE
+
xx%
*@ +
TCiclo
+
std: @getMinSec(@CurrRecord.TCAssegnato)
+
act: @getMinSec(@CurrRecord.TCLavRT)
+
+ } + @if (hasRow(4)) + { +
+ @foreach (var item in rowValues(4)) + { +
@item.TagName: @currVal(item.TagLocation)
+ } +
+ } + else + { +
+
Pezzi(prod/ord)
+
@CurrRecord.PezziProd / @CurrRecord.NumPezzi
+
+ } + @if (hasRow(5)) + { +
+ @foreach (var item in rowValues(5)) + { +
@item.TagName: @currVal(item.TagLocation)
+ } +
+ } + @if (hasRow(6)) + { +
+ @foreach (var item in rowValues(6)) + { +
@item.TagName: @currVal(item.TagLocation)
+ } +
+ } +
+
+
+
+ +
+
+
+ } +
\ No newline at end of file diff --git a/MP.WASM.Mon/Client/Components/DetailMSE.razor.cs b/MP.WASM.Mon/Client/Components/DetailMSE.razor.cs new file mode 100644 index 00000000..56cb8ba5 --- /dev/null +++ b/MP.WASM.Mon/Client/Components/DetailMSE.razor.cs @@ -0,0 +1,286 @@ +using Microsoft.AspNetCore.Components; +using MP.Data.Conf; +using MP.Data.DatabaseModels; +using NLog; + +namespace MP.WASM.Mon.Client.Components +{ + public partial class DetailMSE + { + #region Public Properties + + [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; + + [Parameter] + public Dictionary currTagVal { get; set; } = new Dictionary(); + + [Parameter] + public bool doAnimate { get; set; } = true; + + [Parameter] + public int keepAliveMin { get; set; } = 5; + + [Parameter] + public string showArt { get; set; } = ""; + + #endregion Public Properties + + #region Public Methods + + public void Dispose() + { + //aTimer.Elapsed -= ElapsedTimer; + aTimer.Stop(); + aTimer.Dispose(); + } + + public void ElapsedTimer(object? source, System.Timers.ElapsedEventArgs e) + { + var pUpd = Task.Run(async () => + { + await Task.Delay(1); + // verifica variazione x blink... + bool needUpdate = false; + if (CurrRecord == null) + { + needUpdate = true; + } + else + { + if (OldRecord == null) + { + needUpdate = true; + } + else + { + if (!CurrRecord.Semaforo.Equals(OldRecord.Semaforo) || CurrRecord.Semaforo != "sVe") + { + needUpdate = true; + } + } + } + if (needUpdate) + { + if (false) + { + Log.Trace($"Elapsed Timer {CurrRecord?.CodMacchina}"); + } + await InvokeAsync(StateHasChanged); + } + OldRecord = CurrRecord; + }); + 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 Fields + + protected string baseCss = "sem"; + protected int kaFactor = 60 / 2; + + #endregion Protected Fields + + #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 Protected Methods + + /// + /// restituisce il valore data la tagLocation + /// + /// + /// + protected string currVal(string tagLocation) + { + string answ = ""; + if (currTagVal.ContainsKey(tagLocation)) + { + answ = currTagVal[tagLocation]; + } + return answ; + } + + /// + /// Verifica se ci sia un override per la riga indicata + /// + /// + /// + protected bool hasRow(int numRow) + { + bool answ = false; + if (currTagConf != null) + { + if (currTagConf.Count > 0) + { + var currVals = rowValues(numRow); + answ = currVals.Count > 0; + } + } + return answ; + } + + protected override async Task OnInitializedAsync() + { + StartTimer(); + Random rnd = new Random(); + await Task.Delay(rnd.Next(5)); + setupConf(); + dataLoaded = true; + } + + /// + /// Restituisce (se presenti) valori di override per la riga indicata + /// + /// + /// + protected List rowValues(int numRow) + { + List? rowVals = null; + if (currTagConf != null) + { + if (currTagConf.Count > 0) + { + //cerco solo la riga corrente... + rowVals = currTagConf.Where(x => x.RowNum == numRow).ToList(); + } + } + if (rowVals == null) + { + rowVals = new List(); + } + return rowVals; + } + + #endregion Protected Methods + + #region Private Fields + + private static System.Timers.Timer aTimer { get; set; } = null!; + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + #endregion Private Fields + + #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) + { + // se vuoto --> mostra nero! + if (string.IsNullOrEmpty(codSemaforo)) + { + codSemaforo = "sNe"; + } + string codColore = codSemaforo.Substring(1, 2); + string answ = $"{baseCss}{codColore}"; + if (doAnimate && codColore != "Ve") + { + // 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 decimal getDecimal(object? rawData) + { + decimal answ = 0; + if (rawData != null) + { + decimal.TryParse($"{rawData}", out answ); + } + return answ; + } + + private string getMinSec(decimal? currTimeMin) + { + string answ = "nd"; + TimeSpan tSpan = new TimeSpan(0); + try + { + double cTimeMin = currTimeMin != null ? (double)currTimeMin : 0; + tSpan = TimeSpan.FromMinutes(cTimeMin); + answ = $"{tSpan:mm}:{tSpan:ss}"; + } + catch + { } + return answ; + } + + 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; + } + + #endregion Private Methods + } +} \ No newline at end of file diff --git a/MP.WASM.Mon/Client/Components/LoadingData.razor b/MP.WASM.Mon/Client/Components/LoadingData.razor new file mode 100644 index 00000000..db79a629 --- /dev/null +++ b/MP.WASM.Mon/Client/Components/LoadingData.razor @@ -0,0 +1,6 @@ +
+
+

loading data

+ +
+
\ No newline at end of file diff --git a/MP.WASM.Mon/Client/Components/LoadingDataSmall.razor b/MP.WASM.Mon/Client/Components/LoadingDataSmall.razor new file mode 100644 index 00000000..196dafc7 --- /dev/null +++ b/MP.WASM.Mon/Client/Components/LoadingDataSmall.razor @@ -0,0 +1,6 @@ +
+
+ loading data + +
+
\ No newline at end of file diff --git a/MP.WASM.Mon/Client/MP.WASM.Mon.Client.csproj b/MP.WASM.Mon/Client/MP.WASM.Mon.Client.csproj index e76785f0..5ee4c257 100644 --- a/MP.WASM.Mon/Client/MP.WASM.Mon.Client.csproj +++ b/MP.WASM.Mon/Client/MP.WASM.Mon.Client.csproj @@ -12,6 +12,7 @@ + diff --git a/MP.WASM.Mon/Client/Pages/FetchMSE.razor b/MP.WASM.Mon/Client/Pages/FetchMSE.razor new file mode 100644 index 00000000..0e568d4b --- /dev/null +++ b/MP.WASM.Mon/Client/Pages/FetchMSE.razor @@ -0,0 +1,48 @@ +@page "/fetchmse" +@using MP.Data +@using MP.Data.DatabaseModels +@using MP.WASM.Mon.Shared +@inject HttpClient Http + +MSE Data + +

MSE Data

+ + +@if (listMSE == null) +{ +

Loading...

+} +else +{ + + + + + + + + + + + @foreach (var item in listMSE) + { + + + + + + + } + +
DateMaccSemArt
@item.LastUpdate?.ToShortDateString()@item.CodMacchina@item.Semaforo@item.CodArticolo
+} + +@code { + private List? listMSE; + + protected override async Task OnInitializedAsync() + { + listMSE = await Http.GetFromJsonAsync>("api/MSE"); + } +} diff --git a/MP.WASM.Mon/Client/Shared/NavMenu.razor b/MP.WASM.Mon/Client/Shared/NavMenu.razor index df956d41..90e45bbd 100644 --- a/MP.WASM.Mon/Client/Shared/NavMenu.razor +++ b/MP.WASM.Mon/Client/Shared/NavMenu.razor @@ -21,7 +21,12 @@ + diff --git a/MP.WASM.Mon/Client/_Imports.razor b/MP.WASM.Mon/Client/_Imports.razor index 65f6316e..13b8441f 100644 --- a/MP.WASM.Mon/Client/_Imports.razor +++ b/MP.WASM.Mon/Client/_Imports.razor @@ -6,5 +6,7 @@ @using Microsoft.AspNetCore.Components.Web.Virtualization @using Microsoft.AspNetCore.Components.WebAssembly.Http @using Microsoft.JSInterop +@using MP.Data @using MP.WASM.Mon.Client @using MP.WASM.Mon.Client.Shared +@using MP.WASM.Mon.Client.Components diff --git a/MP.WASM.Mon/Server/Controllers/MSEController.cs b/MP.WASM.Mon/Server/Controllers/MSEController.cs index cfe3c659..d46f39df 100644 --- a/MP.WASM.Mon/Server/Controllers/MSEController.cs +++ b/MP.WASM.Mon/Server/Controllers/MSEController.cs @@ -1,8 +1,6 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using MP.Data.Conf; using MP.Data.DatabaseModels; -using MP.WASM.Mon.Shared; using Newtonsoft.Json; using NLog; using StackExchange.Redis; @@ -14,30 +12,13 @@ namespace MP.WASM.Mon.Server.Controllers [Route("api/[controller]")] public class MSEController : ControllerBase { - public static MP.Data.Controllers.MpMonController dbController { get; set; } = null!; - - private static IConfiguration _configuration = null!; - //private static ILogger _logger = null!; - private readonly ILogger _logger; - private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + #region Public Constructors /// - /// Oggetto per connessione a REDIS + /// Avvio controller dei dati MSE /// - private ConnectionMultiplexer redisConn = null!; - //ISubscriber sub = redis.GetSubscriber(); - /// - /// Oggetto DB redis da impiegare x chiamate R/W - /// - private IDatabase redisDb = null!; - - - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - + /// + /// public MSEController(IConfiguration configuration, ILogger logger) { _logger = logger; @@ -67,26 +48,22 @@ namespace MP.WASM.Mon.Server.Controllers tryLoadIobTags(); } + #endregion Public Constructors + + #region Public Properties + + public static MP.Data.Controllers.MpMonController dbController { get; set; } = null!; /// /// Dizionario dei tag configurati per IOB /// public Dictionary> currTagConf { get; set; } = new Dictionary>(); - [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(); - } + #endregion Public Properties + #region Public Methods - [HttpGet("GetConfig")] + [HttpGet("getConfig")] public Task> ConfigGetAll() { return Task.FromResult(dbController.ConfigGetAll().ToList()); @@ -103,7 +80,7 @@ namespace MP.WASM.Mon.Server.Controllers /// /// Chiave in cui cercare il valore /// - [HttpGet("GetTagConf/{redKey}")] + [HttpGet("getTagConf/{redKey}")] public string getTagConf(string redKey) { string outVal = ""; @@ -116,14 +93,17 @@ namespace MP.WASM.Mon.Server.Controllers return outVal; } - - [HttpGet("GetMachines")] + [HttpGet("getMachines")] public Task> MacchineGetAll() { return Task.FromResult(dbController.MacchineGetAll().ToList()); } - [HttpGet("GetMSE")] + /// + /// Metodo principale x ricevere tutte i dati MSE di tutti gli impianti + /// + /// + [HttpGet()] public Task> MseGetAll() { var dbResult = dbController.MseGetAll(); @@ -134,7 +114,42 @@ namespace MP.WASM.Mon.Server.Controllers return Task.FromResult(dbResult); } + #endregion Public Methods + #region Private Fields + + private static IConfiguration _configuration = null!; + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + //private static ILogger _logger = null!; + private readonly ILogger _logger; + + /// + /// Oggetto per connessione a REDIS + /// + private ConnectionMultiplexer redisConn = null!; + + //ISubscriber sub = redis.GetSubscriber(); + /// + /// Oggetto DB redis da impiegare x chiamate R/W + /// + private IDatabase redisDb = null!; + + #endregion Private Fields + + #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 /// @@ -156,7 +171,8 @@ namespace MP.WASM.Mon.Server.Controllers var fileConfData = JsonConvert.DeserializeObject(rawData); if (fileConfData != null) { - // effettuo esplosione conf SE contenesse il valore "***" = tutti gli IOB + // effettuo esplosione conf SE contenesse il valore "***" = tutti + // gli IOB if (fileConfData.IobSetup.ContainsKey("***")) { // recupero elenco macchine... @@ -167,8 +183,8 @@ namespace MP.WASM.Mon.Server.Controllers { if (!string.IsNullOrEmpty(item.IdxMacchina)) { - // converto i valori x la macchina corrente... - // clono in nuovo oggetto + // converto i valori x la macchina corrente... clono in + // nuovo oggetto var specVal = baseConf.Value.Select(i => i.Clone()).ToList(); // sostituisco segnaposto foreach (var singleVal in specVal) @@ -200,7 +216,6 @@ namespace MP.WASM.Mon.Server.Controllers currConf.Add(item.IdxMacchina, specVal); } } - } // altrimenti copio ed ho finito else @@ -218,5 +233,6 @@ namespace MP.WASM.Mon.Server.Controllers } } + #endregion Private Methods } -} +} \ No newline at end of file