From e098409b8385093285fef175709b82a6209b30f4 Mon Sep 17 00:00:00 2001 From: Thermo_SIM Date: Fri, 19 Mar 2021 22:52:17 +0100 Subject: [PATCH] Fix COnfig FIle & Sheet cleaning --- Thermo.Active.Config/Config/serverConfig.xml | 4 +++- Thermo.Active.Config/Config/serverConfigValidator.xsd | 2 ++ Thermo.Active.Config/ServerConfigController.cs | 2 ++ .../Controllers/HistorySheetsController.cs | 11 +++++++++++ Thermo.Active.Model/ConfigModels/ServerConfigModel.cs | 4 ++++ .../Listeners/Database/SignalRDatabaseHandler.cs | 8 +++++++- Thermo.Active/Listeners/ListenersHandler.cs | 1 + 7 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Thermo.Active.Config/Config/serverConfig.xml b/Thermo.Active.Config/Config/serverConfig.xml index 1aca93c1..4b73e357 100644 --- a/Thermo.Active.Config/Config/serverConfig.xml +++ b/Thermo.Active.Config/Config/serverConfig.xml @@ -4,7 +4,7 @@ S7NET false - 192.168.0.102 + 192.168.214.1 102 Thermo 2020 C:\CMS\Recipes\ @@ -31,6 +31,8 @@ true 50000 5000 + 10000 + 500 diff --git a/Thermo.Active.Config/Config/serverConfigValidator.xsd b/Thermo.Active.Config/Config/serverConfigValidator.xsd index 6a7ecdf9..c4170347 100644 --- a/Thermo.Active.Config/Config/serverConfigValidator.xsd +++ b/Thermo.Active.Config/Config/serverConfigValidator.xsd @@ -42,6 +42,8 @@ + + diff --git a/Thermo.Active.Config/ServerConfigController.cs b/Thermo.Active.Config/ServerConfigController.cs index 0a1580bf..4ea5e160 100644 --- a/Thermo.Active.Config/ServerConfigController.cs +++ b/Thermo.Active.Config/ServerConfigController.cs @@ -1033,6 +1033,8 @@ namespace Thermo.Active.Config MTCApplicationName = x.Element("MTCApplicationName").Value, MaxAlarmsRows = Convert.ToInt32(x.Element("maxAlarmsRows").Value), AlarmToDelete = Convert.ToInt32(x.Element("alarmToDelete").Value), + MaxSheetHistoryRows = Convert.ToInt32(x.Element("maxSheetHistoryRows").Value), + SheetHistoryToDelete = Convert.ToInt32(x.Element("sheetHistoryToDelete").Value), CmsConnectReady = Convert.ToBoolean(x.Element("CMSConnectReady").Value) }).FirstOrDefault(); diff --git a/Thermo.Active.Database/Controllers/HistorySheetsController.cs b/Thermo.Active.Database/Controllers/HistorySheetsController.cs index 90ea44a0..b9e79682 100644 --- a/Thermo.Active.Database/Controllers/HistorySheetsController.cs +++ b/Thermo.Active.Database/Controllers/HistorySheetsController.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Thermo.Active.Model.DatabaseModels; +using static Thermo.Active.Config.ServerConfig; namespace Thermo.Active.Database.Controllers { @@ -42,6 +43,16 @@ namespace Thermo.Active.Database.Controllers return mod; } + + public void Clean() + { + if (this.count() >= ServerStartupConfig.MaxSheetHistoryRows) + { + dbCtx.Database.ExecuteSqlCommand("DELETE FROM historysheets LIMIT {0}", ServerStartupConfig.SheetHistoryToDelete); + } + + } + public List GetData(int start, int number) { // Get page numbers diff --git a/Thermo.Active.Model/ConfigModels/ServerConfigModel.cs b/Thermo.Active.Model/ConfigModels/ServerConfigModel.cs index 0d096389..42fe0f61 100644 --- a/Thermo.Active.Model/ConfigModels/ServerConfigModel.cs +++ b/Thermo.Active.Model/ConfigModels/ServerConfigModel.cs @@ -18,5 +18,9 @@ namespace Thermo.Active.Model.ConfigModels public int MaxAlarmsRows { get; set; } public int AlarmToDelete { get; set; } + + + public int MaxSheetHistoryRows { get; set; } + public int SheetHistoryToDelete { get; set; } } } \ No newline at end of file diff --git a/Thermo.Active/Listeners/Database/SignalRDatabaseHandler.cs b/Thermo.Active/Listeners/Database/SignalRDatabaseHandler.cs index bf40eae2..f2d39bca 100644 --- a/Thermo.Active/Listeners/Database/SignalRDatabaseHandler.cs +++ b/Thermo.Active/Listeners/Database/SignalRDatabaseHandler.cs @@ -50,7 +50,13 @@ namespace Thermo.Active.Listeners.Database } } } - + public static void cleanHistorySheets() + { + using (HistorySheetsController HSC = new HistorySheetsController()) + { + HSC.Clean(); + } + } public static void UpdateAlarms(object alarmsObj) { diff --git a/Thermo.Active/Listeners/ListenersHandler.cs b/Thermo.Active/Listeners/ListenersHandler.cs index f9b7a02e..24cad4e0 100644 --- a/Thermo.Active/Listeners/ListenersHandler.cs +++ b/Thermo.Active/Listeners/ListenersHandler.cs @@ -130,6 +130,7 @@ namespace Thermo.Active.Listeners })); infos.Add(MessageServices.Current.Subscribe(SEND_THERMO_PROD_INFO_DATA, (a, b) => { + SignalRDatabaseHandler.cleanHistorySheets(); SignalRListener.SendThermoProdInfoData(a); })); infos.Add(MessageServices.Current.Subscribe(SEND_THERMO_PROD_CYCLE_DATA, (a, b) =>