From e136c48dd28b9f51efd2dfcb5d22d1e89e84f4bb Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 3 Nov 2021 19:28:35 +0100 Subject: [PATCH] Reload pagina anche su PlantStatus --- GWMS.UI/Pages/PlantParameters.razor.cs | 2 ++ GWMS.UI/Pages/PlantStatus.razor.cs | 30 ++++++++++++++++++++++++-- GWMS.UI/appsettings.json | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/GWMS.UI/Pages/PlantParameters.razor.cs b/GWMS.UI/Pages/PlantParameters.razor.cs index e6f5e75..9eddc01 100644 --- a/GWMS.UI/Pages/PlantParameters.razor.cs +++ b/GWMS.UI/Pages/PlantParameters.razor.cs @@ -323,6 +323,8 @@ namespace GWMS.UI.Pages public void Dispose() { + aTimer.Stop(); + aTimer.Dispose(); AppMService.EA_SearchUpdated -= OnSeachUpdated; } diff --git a/GWMS.UI/Pages/PlantStatus.razor.cs b/GWMS.UI/Pages/PlantStatus.razor.cs index 70b03a7..939427c 100644 --- a/GWMS.UI/Pages/PlantStatus.razor.cs +++ b/GWMS.UI/Pages/PlantStatus.razor.cs @@ -3,12 +3,11 @@ using GWMS.UI.Data; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; -using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Configuration; using Microsoft.JSInterop; using System; using System.Collections.Generic; using System.Linq; -using System.Security.Claims; using System.Threading.Tasks; namespace GWMS.UI.Pages @@ -18,6 +17,7 @@ namespace GWMS.UI.Pages { #region Private Fields + private static System.Timers.Timer aTimer; private PlantDTO currRecord = null; private List ListRecords; @@ -35,6 +35,9 @@ namespace GWMS.UI.Pages #region Private Properties + [Inject] + private IConfiguration Configuration { get; set; } + private bool isLoading { get; set; } = false; private bool ShowCharts { get; set; } = false; @@ -131,6 +134,7 @@ namespace GWMS.UI.Pages MessageService.PageName = "Impianti"; MessageService.PageIcon = "fas fa-tachometer-alt pr-2"; MessageService.EA_SearchUpdated += OnSeachUpdated; + StartTimer(); await ReloadAllData(); } @@ -152,15 +156,37 @@ namespace GWMS.UI.Pages public void Dispose() { + aTimer.Stop(); + aTimer.Dispose(); MessageService.EA_SearchUpdated -= OnSeachUpdated; } + public void ElapsedTimer(Object source, System.Timers.ElapsedEventArgs e) + { + var pUpd = Task.Run(async () => + { + await ReloadAllData(); + await InvokeAsync(StateHasChanged); + }); + pUpd.Wait(); + } + public async void OnSeachUpdated() { await UpdateData(); StateHasChanged(); } + public void StartTimer() + { + int tOutPeriod = 3000; + int.TryParse(Configuration["ReloadStatusTimer"], out tOutPeriod); + aTimer = new System.Timers.Timer(tOutPeriod); + aTimer.Elapsed += ElapsedTimer; + aTimer.Enabled = true; + aTimer.Start(); + } + #endregion Public Methods } } \ No newline at end of file diff --git a/GWMS.UI/appsettings.json b/GWMS.UI/appsettings.json index e4df357..8fea74e 100644 --- a/GWMS.UI/appsettings.json +++ b/GWMS.UI/appsettings.json @@ -39,6 +39,7 @@ "ChartWaitDelay": 10, "logo": "img/LogoPizzaferri.jpg", "ReloadParamTimer": 5000, + "ReloadStatusTimer": 5000, "ExternalProviders": { "MailKit": { "SMTP": {