From 06b87a879d9dfe986ab530e86d1c4b0556d976cb Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 19 Oct 2019 12:39:28 +0200 Subject: [PATCH] Continuo metodi x calcolo durata periodo IDLE (da finire!!!) --- MP-IO/Controllers/IOBController.cs | 54 ++++++++++++++++++ MP-MON/Controllers/MSEController.cs | 60 ++++++-------------- MapoDb/DataLayer.cs | 87 +++++++++++++++++++++++++++-- MapoDb/MapoDb.cs | 34 ++++++----- MapoDb/MapoDb.csproj | 8 +++ MapoDb/app.config | 29 +++++++++- MapoDb/packages.config | 2 + 7 files changed, 210 insertions(+), 64 deletions(-) diff --git a/MP-IO/Controllers/IOBController.cs b/MP-IO/Controllers/IOBController.cs index 4ad79d86..332f3174 100644 --- a/MP-IO/Controllers/IOBController.cs +++ b/MP-IO/Controllers/IOBController.cs @@ -220,6 +220,60 @@ namespace MP_IO.Controllers return answ; } /// + /// Restituisce intera riga dello stato di macchina... + /// es: http://url_site/MP/IO/IOB/getCurrStatoRow/SIMUL_01 + /// + /// + /// + public string getCurrStatoRow(string id) + { + string answ = ""; + DS_applicazione.StatoMacchineDataTable currData = null; + // chiamo metodo redis/db... + try + { + currData = DataLayer.currSMTab(id); + answ = JsonConvert.SerializeObject(currData); + } + catch (Exception exc) + { + logger.lg.scriviLog($"Eccezione in recupero getCurrStatoRow{Environment.NewLine}{exc}", tipoLog.EXCEPTION); + } + return answ; + } + /// + /// Restituisce il valore dello stato di IDLE della macchina, quindi SOLO SE NON é in lavoro e già convertito in minuti... + /// es: http://url_site/MP/IO/IOB/getIdlePeriod/SIMUL_01 + /// + /// + /// + public int getIdlePeriod(string id) + { + int answ = 0; + DS_applicazione.StatoMacchineDataTable currData = null; + // chiamo metodo redis/db... + try + { + currData = DataLayer.currSMTab(id); + if (currData.Count > 0) + { + // recupero da redis elenco stati + + // calcolo SE sia idle... !!!FIXME + if (currData[0].IdxStato != 13) + { + // calcolo durata... + answ = (int)DateTime.Now.Subtract(currData[0].InizioStato).TotalMinutes; + } + } + } + catch (Exception exc) + { + logger.lg.scriviLog($"Eccezione in recupero getIdlePeriod{Environment.NewLine}{exc}", tipoLog.EXCEPTION); + } + return answ; + } + /// /// Recupera DATI correnti x macchina: /// /// GET: IOB/getCurrData/SIMUL_03 diff --git a/MP-MON/Controllers/MSEController.cs b/MP-MON/Controllers/MSEController.cs index b621d5a6..879c119d 100644 --- a/MP-MON/Controllers/MSEController.cs +++ b/MP-MON/Controllers/MSEController.cs @@ -1,4 +1,5 @@ -using MP_MON.Models; +using MapoDb; +using MP_MON.Models; using Newtonsoft.Json; using SteamWare; using System; @@ -26,13 +27,10 @@ namespace MP_MON.Controllers { int dataRefresh = 2000; string answ = ""; - answ = dataSer; - if (answ == null || answ == "") + answ = DataLayer.obj.currMSE; + if (!string.IsNullOrEmpty(answ)) { - var dati = db.stp_MSE_getData(dataRefresh).ToList(); - // serializzo - answ = JsonConvert.SerializeObject(dati); - dataSer = answ; + List dati = getDbSaveRedis(dataRefresh); } return answ; } @@ -41,7 +39,7 @@ namespace MP_MON.Controllers { int dataRefresh = 2000; // salvo idxMacc in sessione se c'è... - if (IdxMacchina != "" && IdxMacchina != null) + if (!string.IsNullOrEmpty(IdxMacchina)) { memLayer.ML.setSessionVal("IdxMacchina", IdxMacchina); } @@ -56,21 +54,22 @@ namespace MP_MON.Controllers catch { } List dati = new List(); - if (dataSer != "" && dataSer != null) + string currMse = DataLayer.obj.currMSE; + if (!string.IsNullOrEmpty(currMse)) { try { - dati = JsonConvert.DeserializeObject>(dataSer); + dati = JsonConvert.DeserializeObject>(currMse); } catch (Exception exc) { - getDbSaveRedis(dataRefresh, hMSE, out dati); + dati = getDbSaveRedis(dataRefresh); logger.lg.scriviLog(string.Format("Recuperata MSE da DB{0}{1}", Environment.NewLine, exc)); } } else { - getDbSaveRedis(dataRefresh, hMSE, out dati); + dati = getDbSaveRedis(dataRefresh); } // filtro dati SOLO PER la macchina che mi interessa... SE C'E'... string reqView = "_StatusMap"; @@ -93,43 +92,18 @@ namespace MP_MON.Controllers return PartialView(reqView, dati); } /// - /// Recupera dati da DB e salva su REDIS + /// Restituisce dati da DB (e li salva su REDIS...) /// - /// - /// - /// - private void getDbSaveRedis(int dataRefresh, string hMSE, out List dati) + /// Parametro x procedura ricalcolo MSE + private List getDbSaveRedis(int dataRefresh) { + List dati = new List(); // se non c'è rileggo... logger.lg.scriviLog("Recuperata MSE da DB"); dati = db.stp_MSE_getData(dataRefresh).ToList(); // serializzo - dataSer = JsonConvert.SerializeObject(dati); - } - /// - /// Hash chaive dati MSE - /// - protected string hMSE - { - get - { - return MapoDb.DataLayer.hMSE(); - } - } - /// - /// Dati MSE serializzati in REDIS (get/set) - /// - protected string dataSer - { - get - { - logger.lg.scriviLog("Recuperata MSE da REDIS"); - return memLayer.ML.getRSV(hMSE); - } - set - { - memLayer.ML.setRSV(hMSE, value, memLayer.ML.CRI("MSE_cacheDuration")); - } + DataLayer.obj.currMSE = JsonConvert.SerializeObject(dati); + return dati; } protected override void Dispose(bool disposing) diff --git a/MapoDb/DataLayer.cs b/MapoDb/DataLayer.cs index 68ef97b0..e205dde0 100644 --- a/MapoDb/DataLayer.cs +++ b/MapoDb/DataLayer.cs @@ -1087,6 +1087,15 @@ namespace MapoDb return mHash(string.Format("CurrOdlRow:{0}", idxMacchina)); } /// + /// Hash dati Current StatoMacchina x la macchina specificata + /// + /// + /// + public static string currStatoMaccHash(string idxMacchina) + { + return mHash(string.Format("CurrStatoMacc:{0}", idxMacchina)); + } + /// /// Hash dati LIVE x la macchina specificata /// /// @@ -1136,9 +1145,36 @@ namespace MapoDb /// Hash dati MSE /// /// - public static string hMSE() + public static string hMSE { - return mHash(string.Format("hMSE_DATA")); + get + { + return mHash(string.Format("hMSE_DATA")); + } + } + + #endregion + + #region gestione MSE + + + /// + /// Dati MSE serializzati in REDIS (get/set) + /// + public string currMSE + { + get + { + string answ = ""; + logger.lg.scriviLog("Richiesta MSE da REDIS"); + answ = memLayer.ML.getRSV(hMSE); + return answ; + } + set + { + int MSE_cacheDuration = memLayer.ML.CRI("MSE_cacheDuration"); + memLayer.ML.setRSV(hMSE, value, MSE_cacheDuration); + } } #endregion @@ -1215,7 +1251,6 @@ namespace MapoDb #endregion - #region gestione OPT PARAMETERS macchina /// @@ -1288,8 +1323,52 @@ namespace MapoDb #endregion - #region gestione dati macchina + #region gestione stato macchina + /// + /// Restituisce il valore dell'intera RIGA stato macchina corrente (da redis o da DB se non trovata...) + /// + /// + /// + public static DS_applicazione.StatoMacchineDataTable currSMTab(string idxMacchina) + { + DS_applicazione.StatoMacchineDataTable answTab = null; + string rCall = ""; + if (memLayer.ML.CRB("IOB_RedEnab")) + { + saveCallRec("hasStatoMacc"); + try + { + rCall = memLayer.ML.getRSV(currStatoMaccHash(idxMacchina)); + if (!string.IsNullOrEmpty(rCall)) + { + answTab = JsonConvert.DeserializeObject(rCall); + } + else + { + answTab = MapoDb.obj.currStatoMaccTab(idxMacchina); + // salvo in redis... + rCall = JsonConvert.SerializeObject(answTab); + int currStatoMaccCacheDur = memLayer.ML.CRI("currStatoMaccCacheDur"); + memLayer.ML.setRSV(currStatoMaccHash(idxMacchina), rCall, currStatoMaccCacheDur); + } + } + catch (Exception exc) + { + logger.lg.scriviLog($"Eccezione in recupero currODLRow{Environment.NewLine}{exc}", tipoLog.EXCEPTION); + } + } + else + { + answTab = MapoDb.obj.currStatoMaccTab(idxMacchina); + } + return answTab; + } + + + #endregion + + #region gestione dati macchina /// /// Restitusice elenco KVP dei campi DatiMacchine + StatoMacchine per l'impianto indicato diff --git a/MapoDb/MapoDb.cs b/MapoDb/MapoDb.cs index 2df834eb..a483e582 100644 --- a/MapoDb/MapoDb.cs +++ b/MapoDb/MapoDb.cs @@ -465,22 +465,26 @@ namespace MapoDb { logger.lg.scriviLog($"Eccezione in recupero currODLTab{Environment.NewLine}{exc}", tipoLog.EXCEPTION); } - // recupero con stored NUOVA... -#if false - DS_ProdTempi.ODLDataTable tabOdl = DataLayer.obj.taODL.getByMacchina(idxMacchina); - if (tabOdl.Rows.Count > 0) + // restituisco! + return answ; + } + /// + /// Testituisce tabella con riga dell'ODL attivo (iniziato e NON concluso) + /// + /// + /// + public DS_applicazione.StatoMacchineDataTable currStatoMaccTab(string idxMacchina) + { + DS_applicazione.StatoMacchineDataTable answ = null; + logger.lg.scriviLog("Recupero currStatoMaccTab da DB!", tipoLog.INFO); + try { - // solo SE ho idxODL (altrimenti loggo errore) - if (tabOdl[0].IdxODL > 0) - { - answ = tabOdl; - } - else - { - logger.lg.scriviLog($"Errore in currODLRow x idxMacchina {idxMacchina}: IdxODL = 0", tipoLog.ERROR); - } - } -#endif + answ = DataLayer.obj.taStatoMacchine.GetDataByIdxMacchina(idxMacchina); + } + catch (Exception exc) + { + logger.lg.scriviLog($"Eccezione in recupero currStatoMaccTab{Environment.NewLine}{exc}", tipoLog.EXCEPTION); + } // restituisco! return answ; } diff --git a/MapoDb/MapoDb.csproj b/MapoDb/MapoDb.csproj index d4a938da..e86fab03 100644 --- a/MapoDb/MapoDb.csproj +++ b/MapoDb/MapoDb.csproj @@ -59,6 +59,12 @@ ..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll + + ..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll + + + ..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll + False @@ -68,11 +74,13 @@ ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll + + diff --git a/MapoDb/app.config b/MapoDb/app.config index dd793f92..04cc0805 100644 --- a/MapoDb/app.config +++ b/MapoDb/app.config @@ -1,12 +1,15 @@  + +
+ @@ -23,7 +26,7 @@ - + @@ -35,8 +38,30 @@ - + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MapoDb/packages.config b/MapoDb/packages.config index 897db559..5dd74408 100644 --- a/MapoDb/packages.config +++ b/MapoDb/packages.config @@ -1,6 +1,8 @@  + + \ No newline at end of file