From 673eb62d8ca6b0c718fbdc7400c9facac6d3934a Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 15 Sep 2022 15:30:48 +0200 Subject: [PATCH] Inizio gestione con unico obj filtro --- MP.SPEC/Components/ListPARAMS.razor.cs | 152 ++++++++++++++--------- MP.SPEC/Components/ParamsFilter.razor | 78 +++++++----- MP.SPEC/Components/ParamsFilter.razor.cs | 114 +++++++++++------ MP.SPEC/Data/MpDataService.cs | 15 ++- MP.SPEC/Data/SelectFluxParams.cs | 23 +++- MP.SPEC/Pages/PARAMS.razor | 63 +--------- MP.SPEC/Pages/PARAMS.razor.cs | 115 +++-------------- MP.SPEC/Pages/PODL.razor.cs | 4 +- 8 files changed, 267 insertions(+), 297 deletions(-) diff --git a/MP.SPEC/Components/ListPARAMS.razor.cs b/MP.SPEC/Components/ListPARAMS.razor.cs index 61a4548e..369b49d5 100644 --- a/MP.SPEC/Components/ListPARAMS.razor.cs +++ b/MP.SPEC/Components/ListPARAMS.razor.cs @@ -10,33 +10,18 @@ namespace MP.SPEC.Components { #region Public Properties + [Parameter] + public EventCallback PagerResetReq { get; set; } [Parameter] - public EventCallback TotRecordChanged { get; set; } - - [Parameter] - public bool LiveUpdate + public SelectFluxParams SelFilter { - get => _liveUpdate; + get => _selFilter; set { - _liveUpdate = value; - // var pUpd = Task.Run(async () => await reloadData(false)); - // pUpd.Wait(); - } - } - private bool _liveUpdate { get; set; } - - - [Parameter] - public int MaxRecord - { - get => _maxRecord; - set - { - if (_maxRecord != value) + if (!_selFilter.Equals(value)) { - _maxRecord = value; + _selFilter = value; var pUpd = Task.Run(async () => await reloadData(true)); pUpd.Wait(); } @@ -44,37 +29,7 @@ namespace MP.SPEC.Components } [Parameter] - public EventCallback PagerResetReq { get; set; } - - [Parameter] - public string SelFlux - { - get => _selFlux; - set - { - if (_selFlux != value) - { - _selFlux = value; - //var pUpd = Task.Run(async () => await reloadData(false)); - //pUpd.Wait(); - } - } - } - - [Parameter] - public string SelMacchina - { - get => _selMacchina; - set - { - if (_selMacchina != value) - { - _selMacchina = value; - //var pUpd = Task.Run(async () => await reloadData(false)); - //pUpd.Wait(); - } - } - } + public EventCallback TotRecordChanged { get; set; } #endregion Public Properties @@ -138,8 +93,6 @@ namespace MP.SPEC.Components isLoading = false; } - private int tOutPeriod { get; set; } = 2000; - public void StartTimer() { //int.TryParse(Configuration["ReloadStatusTimer"], out tOutPeriod); @@ -201,16 +154,17 @@ namespace MP.SPEC.Components private int _maxRecord = 100; private string _selFlux = "*"; private string _selMacchina = "*"; + private int _totalCount = 0; private FluxLog? currRecord = null; - private List? ListRecords; - private List? SearchRecords; #endregion Private Fields #region Private Properties + private SelectFluxParams _selFilter { get; set; } = new SelectFluxParams(); + private int currPage { get => MessageService.currPage; @@ -219,14 +173,96 @@ namespace MP.SPEC.Components private bool isLoading { get; set; } = false; + private bool LiveUpdate + { + get => SelFilter.LiveUpdate; + } + + private int MaxRecord + { + get => _selFilter.MaxRecord; + } + +#if false + [Parameter] + public bool LiveUpdate + { + get => _liveUpdate; + set + { + _liveUpdate = value; + // var pUpd = Task.Run(async () => await reloadData(false)); pUpd.Wait(); + } + } + private bool _liveUpdate { get; set; } +#endif + +#if false + + [Parameter] + public int MaxRecord + { + get => _maxRecord; + set + { + if (_maxRecord != value) + { + _maxRecord = value; + var pUpd = Task.Run(async () => await reloadData(true)); + pUpd.Wait(); + } + } + } +#endif + private int numRecord { get => MessageService.numRecord; set => MessageService.numRecord = value; } + private string SelFlux + { + get => _selFilter.CodFlux; + } + + private string SelMacchina + { + get => _selFilter.IdxMacchina; + } + +#if false + [Parameter] + public string SelFlux + { + get => _selFlux; + set + { + if (_selFlux != value) + { + _selFlux = value; + //var pUpd = Task.Run(async () => await reloadData(false)); + //pUpd.Wait(); + } + } + } + + [Parameter] + public string SelMacchina + { + get => _selMacchina; + set + { + if (_selMacchina != value) + { + _selMacchina = value; + //var pUpd = Task.Run(async () => await reloadData(false)); + //pUpd.Wait(); + } + } + } +#endif - private int _totalCount = 0; private int totalCount { get => _totalCount; @@ -240,6 +276,8 @@ namespace MP.SPEC.Components } } + private int tOutPeriod { get; set; } = 5000; + #endregion Private Properties #region Private Methods diff --git a/MP.SPEC/Components/ParamsFilter.razor b/MP.SPEC/Components/ParamsFilter.razor index 43e53201..5b2330bb 100644 --- a/MP.SPEC/Components/ParamsFilter.razor +++ b/MP.SPEC/Components/ParamsFilter.razor @@ -1,36 +1,54 @@ - -
-
- -
-
- @if (isLoading) +
+
+ @if (!liveUpdate) { - + } else - { - + { + }
+
+
+
+ +
+
+ @if (isLoading) + { + + } + else + { + + } +
+
+
diff --git a/MP.SPEC/Components/ParamsFilter.razor.cs b/MP.SPEC/Components/ParamsFilter.razor.cs index 7c5f8579..a6814d51 100644 --- a/MP.SPEC/Components/ParamsFilter.razor.cs +++ b/MP.SPEC/Components/ParamsFilter.razor.cs @@ -1,31 +1,63 @@ -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.SPEC; -using MP.SPEC.Shared; -using MP.SPEC.Components; using MP.SPEC.Data; namespace MP.SPEC.Components { public partial class ParamsFilter { - [Parameter] - public SelectFluxParams SelFilter { get; set; } + #region Public Properties [Parameter] public EventCallback FilterChanged { get; set; } + [Parameter] + public SelectFluxParams SelFilter { get; set; } = null!; + + #endregion Public Properties + + #region Protected Fields + + protected string lastUpdate = "-"; + + #endregion Protected Fields + + #region Protected Properties + + protected bool liveUpdate + { + get => SelFilter.LiveUpdate; + set + { + if (!SelFilter.LiveUpdate.Equals(value)) + { + isLoading = true; + SelFilter.LiveUpdate = value; + reportChange(); + isLoading = false; + } + } + } + + [Inject] + protected MpDataService MDService { get; set; } + + protected string selFlux + { + get + { + return SelFilter.CodFlux; + } + + set + { + if (!SelFilter.CodFlux.Equals(value)) + { + SelFilter.CodFlux = value; + reportChange(); + } + } + } + protected string selMacchina { get @@ -45,34 +77,16 @@ namespace MP.SPEC.Components ListFlux = MDService.ParametriGetFilt(selMacchina).Result; Task.Delay(1); StateHasChanged(); - Task.Delay(1); + Task.Delay(1); reportChange(); isLoading = false; } } } - protected string selFlux - { - get - { - return SelFilter.CodFlux; - } + #endregion Protected Properties - set - { - if (!SelFilter.CodFlux.Equals(value)) - { - SelFilter.CodFlux = value; - reportChange(); - } - } - } - - private void reportChange() - { - FilterChanged.InvokeAsync(SelFilter); - } + #region Protected Methods protected override async Task OnInitializedAsync() { @@ -81,6 +95,19 @@ namespace MP.SPEC.Components ListFlux = await MDService.ParametriGetFilt(selMacchina); } + protected async Task toggleUpdate() + { + liveUpdate = !liveUpdate; + if (!liveUpdate) + { + lastUpdate = $"Last Snapshot: {DateTime.Now:yyyy/MM/dd HH:mm:ss}"; + } + await Task.Delay(1); + } + + #endregion Protected Methods + + #region Private Fields private bool isLoading = false; @@ -88,9 +115,9 @@ namespace MP.SPEC.Components private List? ListMacchine; - [Inject] - protected MpDataService MDService { get; set; } + #endregion Private Fields + #region Private Methods private async Task reloadFiltFlux() { @@ -98,5 +125,12 @@ namespace MP.SPEC.Components ListFlux = await MDService.ParametriGetFilt(selMacchina); await InvokeAsync(() => StateHasChanged()); } + + private void reportChange() + { + FilterChanged.InvokeAsync(SelFilter); + } + + #endregion Private Methods } } \ No newline at end of file diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 416d4ebd..ee4f30bb 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -446,15 +446,14 @@ namespace MP.SPEC.Data Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); string readType = "DB"; - + result = await Task.FromResult(dbController.ParametriGetFilt(IdxMacchina)); - - + #if false // 2 minuti valore cache int maxAgeMin = 5; string currKey = $"{redisFluxByMac}:{IdxMacchina}"; - + // cerco in redis dato valore sel macchina... RedisValue rawData = await redisDb.StringGetAsync(currKey); if (!string.IsNullOrEmpty($"{rawData}")) @@ -474,11 +473,11 @@ namespace MP.SPEC.Data if (result == null) { result = new List(); - } + } #endif stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ParametriGetFilt | Read from {readType}: {ts.TotalMilliseconds}ms"); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"ParametriGetFilt | Read from {readType}: {ts.TotalMilliseconds}ms"); return result; } @@ -535,10 +534,10 @@ namespace MP.SPEC.Data /// private IDatabase redisDb = null!; + private string redisFluxByMac = "MP:MON:Cache:FluxByMac"; private string redisMseKey = "MP:MON:Cache:MSE"; private string redisStatoCom = "MP:MON:Cache:StatoCom"; private string redisTipoArt = "MP:MON:Cache:TipoArt"; - private string redisFluxByMac = "MP:MON:Cache:FluxByMac"; #endregion Private Fields diff --git a/MP.SPEC/Data/SelectFluxParams.cs b/MP.SPEC/Data/SelectFluxParams.cs index a783c5ef..be83f2ef 100644 --- a/MP.SPEC/Data/SelectFluxParams.cs +++ b/MP.SPEC/Data/SelectFluxParams.cs @@ -2,17 +2,25 @@ { public class SelectFluxParams { + #region Public Constructors + + public SelectFluxParams() + { } + + #endregion Public Constructors + #region Public Properties - public string IdxMacchina { get; set; } = "*"; public string CodFlux { get; set; } = "*"; + public string IdxMacchina { get; set; } = "*"; + public bool LiveUpdate { get; set; } = true; + + public int MaxRecord { get; set; } = 100; #endregion Public Properties #region Public Methods - - public override bool Equals(object obj) { if (!(obj is SelectFluxParams item)) @@ -20,9 +28,16 @@ if (IdxMacchina != item.IdxMacchina) return false; + if (CodFlux != item.CodFlux) return false; + if (LiveUpdate != item.LiveUpdate) + return false; + + if (MaxRecord != item.MaxRecord) + return false; + return true; } @@ -33,4 +48,4 @@ #endregion Public Methods } -} +} \ No newline at end of file diff --git a/MP.SPEC/Pages/PARAMS.razor b/MP.SPEC/Pages/PARAMS.razor index b1952d0d..c586d536 100644 --- a/MP.SPEC/Pages/PARAMS.razor +++ b/MP.SPEC/Pages/PARAMS.razor @@ -2,64 +2,11 @@
-
-
-
-
-

PARAMETERS

-
- @if (!liveUpdate) - { - - } - else - { - - } -
-
-
-
+
+
+

PARAMETERS

-
-
-
- @*
-
-
-
- -
-
- @if (!isLoading) - { - - } -
-
*@ +
@@ -71,7 +18,7 @@ } else { - + }