From 9dad20e641c004ac88a8cd1f177e31a5ba5014e9 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 19 Oct 2019 10:30:19 +0200 Subject: [PATCH] FIOX MP/IO: aggiunti metodi getCurrOdlStart e getCurrOdlRow --- Jenkinsfile | 6 +- MP-IO/Controllers/IOBController.cs | 48 ++++++++- MapoDb/DataLayer.cs | 163 ++++++++++++----------------- MapoDb/MapoDb.cs | 22 ++-- 4 files changed, 134 insertions(+), 105 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index be32d204..b51fa9d0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,9 +18,9 @@ pipeline { /* calcolo numero versione... diverso x branch MASTER/DEVELOP */ script { - withEnv(['NEXT_BUILD_NUMBER=1238']) { - // env.versionNumber = VersionNumber(versionNumberString : '6.6.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true) - env.versionNumber = VersionNumber(versionNumberString : '6.6.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}') + withEnv(['NEXT_BUILD_NUMBER=1239']) { + // env.versionNumber = VersionNumber(versionNumberString : '6.7.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true) + env.versionNumber = VersionNumber(versionNumberString : '6.7.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}') env.APP_NAME = 'MAPO' } } diff --git a/MP-IO/Controllers/IOBController.cs b/MP-IO/Controllers/IOBController.cs index 46af77d8..12acd4b3 100644 --- a/MP-IO/Controllers/IOBController.cs +++ b/MP-IO/Controllers/IOBController.cs @@ -172,7 +172,53 @@ namespace MP_IO.Controllers } return answ; } - + /// + /// Restituisce data-ora inizio dell'odl correntemente in lavorazione sulla macchina... + /// es: http://url_site/MP/IO/IOB/getCurrOdlStart/SIMUL_03 + /// + /// + /// + public DateTime getCurrOdlStart(string id) + { + DateTime answ = new DateTime(DateTime.Now.Year - 1, 12, 31); + // chiamo metodo redis/db... + try + { + DS_ProdTempi.ODLDataTable currTab = DataLayer.currODLRowTab(id); + if (currTab.Count > 0) + { + DS_ProdTempi.ODLRow odlRow = currTab[0]; + answ = odlRow.DataInizio; + } + } + catch (Exception exc) + { + logger.lg.scriviLog($"Eccezione in recupero getCurrOdlStart{Environment.NewLine}{exc}", tipoLog.EXCEPTION); + } + return answ; + } + /// + /// Restituisce intera riga dell'odl correntemente in lavorazione sulla macchina... + /// es: http://url_site/MP/IO/IOB/getCurrOdlRow/SIMUL_01 + /// + /// + /// + public string getCurrOdlRow(string id) + { + string answ = ""; + DS_ProdTempi.ODLDataTable currData = null; + // chiamo metodo redis/db... + try + { + currData = DataLayer.currODLRowTab(id); + answ = JsonConvert.SerializeObject(currData); + } + catch (Exception exc) + { + logger.lg.scriviLog($"Eccezione in recupero getCurrOdlRow{Environment.NewLine}{exc}", tipoLog.EXCEPTION); + } + return answ; + } /// /// Recupera DATI correnti x macchina: /// diff --git a/MapoDb/DataLayer.cs b/MapoDb/DataLayer.cs index 2c1febdb..68ef97b0 100644 --- a/MapoDb/DataLayer.cs +++ b/MapoDb/DataLayer.cs @@ -1,6 +1,8 @@ -using SteamWare; +using Newtonsoft.Json; +using SteamWare; using System; using System.Collections.Generic; +using System.Data; using System.Data.SqlClient; using System.Globalization; using System.Reflection; @@ -241,6 +243,40 @@ namespace MapoDb } } + public static List DataTableToList(DataTable dt) where T : class, new() + { + List lstItems = new List(); + if (dt != null && dt.Rows.Count > 0) + foreach (DataRow row in dt.Rows) + lstItems.Add(ConvertDataRowToGenericType(row)); + else + lstItems = null; + return lstItems; + } + + private static T ConvertDataRowToGenericType(DataRow row) where T : class, new() + { + Type entityType = typeof(T); + T objEntity = new T(); + foreach (DataColumn column in row.Table.Columns) + { + object value = row[column.ColumnName]; + if (value == DBNull.Value) value = null; + PropertyInfo property = entityType.GetProperty(column.ColumnName, BindingFlags.Instance | BindingFlags.IgnoreCase | BindingFlags.Public); + try + { + if (property != null && property.CanWrite) + property.SetValue(objEntity, value, null); + + } + catch (Exception ex) + { + throw ex; + } + } + return objEntity; + } + #endregion #region utility public esposte @@ -945,17 +981,7 @@ namespace MapoDb // registro conteggio impiego chiamate REDIS if (memLayer.ML.CRB("IOB_RedEnab")) { - // conto la richiesta nel contatore REDIS - long nCall = memLayer.ML.setRCntI(mHash("COUNT:pCall:saveCurrODL")); - //... se == nCall2Log scrivo su log e resetto - long nCall2Log = memLayer.ML.cdvi("nCall2Log"); - if (nCall >= nCall2Log) - { - // loggo - logger.lg.scriviLog(string.Format("saveCurrODL: effettuate {0} call", nCall), tipoLog.INFO); - // resetto! - memLayer.ML.resetRCnt(mHash("COUNT:pCall:saveCurrODL")); - } + saveCallRec("saveCurrODL"); } string answ = ""; // inizio processing vero e proprio INPUT... @@ -1052,6 +1078,15 @@ namespace MapoDb return mHash(string.Format("CurrODL:{0}", idxMacchina)); } /// + /// Hash dati Current ODL ROW x la macchina specificata + /// + /// + /// + public static string currOdlRowHash(string idxMacchina) + { + return mHash(string.Format("CurrOdlRow:{0}", idxMacchina)); + } + /// /// Hash dati LIVE x la macchina specificata /// /// @@ -1369,17 +1404,7 @@ namespace MapoDb bool answ = false; if (memLayer.ML.CRB("IOB_RedEnab")) { - // conto la richiesta nel contatore REDIS - long nCall = memLayer.ML.setRCntI(mHash("COUNT:pCall:insEnabled")); - //... se == nCall2Log scrivo su log e resetto - long nCall2Log = memLayer.ML.cdvi("nCall2Log"); - if (nCall >= nCall2Log) - { - // loggo - logger.lg.scriviLog(string.Format("insEnabled: effettuate {0} call", nCall), tipoLog.INFO); - // resetto! - memLayer.ML.resetRCnt(mHash("COUNT:pCall:insEnabled")); - } + saveCallRec("insEnabled"); try { answ = Convert.ToBoolean(mDatiMacchinaVal(idxMacchina, "insEnabled")); @@ -1409,36 +1434,39 @@ namespace MapoDb /// /// /// - public static DS_ProdTempi.ODLRow currODLRow(string idxMacchina) + public static DS_ProdTempi.ODLDataTable currODLRowTab(string idxMacchina) { - DS_ProdTempi.ODLRow answ = null; + DS_ProdTempi.ODLDataTable answTab = null; string rCall = ""; if (memLayer.ML.CRB("IOB_RedEnab")) { saveCallRec("hasODL_row"); - try { - rCall = memLayer.ML.getRSV(currODLHash(idxMacchina)); - if (rCall != null && rCall != "") + rCall = memLayer.ML.getRSV(currOdlRowHash(idxMacchina)); + if (!string.IsNullOrEmpty(rCall)) { - answ = rCall; + answTab = JsonConvert.DeserializeObject(rCall); } else { - answ = MapoDb.obj.currODLRow(idxMacchina); + answTab = MapoDb.obj.currODLTab(idxMacchina); // salvo in redis... - saveCurrODL(idxMacchina, answ); + rCall = JsonConvert.SerializeObject(answTab); + int currOdlRowCacheDur = memLayer.ML.CRI("currOdlRowCacheDur"); + memLayer.ML.setRSV(currOdlRowHash(idxMacchina), rCall, currOdlRowCacheDur); } } - catch - { } + catch (Exception exc) + { + logger.lg.scriviLog($"Eccezione in recupero currODLRow{Environment.NewLine}{exc}", tipoLog.EXCEPTION); + } } else { - answ = MapoDb.obj.currODLRow(idxMacchina); + answTab = MapoDb.obj.currODLTab(idxMacchina); } - return answ; + return answTab; } /// @@ -1452,18 +1480,7 @@ namespace MapoDb string rCall = ""; if (memLayer.ML.CRB("IOB_RedEnab")) { - - // conto la richiesta nel contatore REDIS - long nCall = memLayer.ML.setRCntI(mHash("COUNT:pCall:hasODL")); - //... se == nCall2Log scrivo su log e resetto - long nCall2Log = memLayer.ML.cdvi("nCall2Log"); - if (nCall >= nCall2Log) - { - // loggo - logger.lg.scriviLog(string.Format("IOB {1} | hasODL: effettuate {0} call", nCall, idxMacchina), tipoLog.INFO); - // resetto! - memLayer.ML.resetRCnt(mHash("COUNT:pCall:hasODL")); - } + saveCallRec("hasODL"); try { rCall = memLayer.ML.getRSV(currODLHash(idxMacchina)); @@ -1525,18 +1542,7 @@ namespace MapoDb bool answ = false; if (memLayer.ML.CRB("IOB_RedEnab")) { - - // conto la richiesta nel contatore REDIS - long nCall = memLayer.ML.setRCntI(mHash("COUNT:pCall:sLogEnabled")); - //... se == nCall2Log scrivo su log e resetto - long nCall2Log = memLayer.ML.cdvi("nCall2Log"); - if (nCall >= nCall2Log) - { - // loggo - logger.lg.scriviLog(string.Format("sLogEnabled: effettuate {0} call", nCall), tipoLog.INFO); - // resetto! - memLayer.ML.resetRCnt(mHash("COUNT:pCall:sLogEnabled")); - } + saveCallRec("sLogEnabled"); try { answ = Convert.ToBoolean(mDatiMacchinaVal(idxMacchina, "sLogEnabled")); @@ -1562,18 +1568,7 @@ namespace MapoDb int answ = -1; if (memLayer.ML.CRB("IOB_RedEnab")) { - - // conto la richiesta nel contatore REDIS - long nCall = memLayer.ML.setRCntI(mHash("COUNT:pCall:getCounterTC")); - //... se == nCall2Log scrivo su log e resetto - long nCall2Log = memLayer.ML.cdvi("nCall2Log"); - if (nCall >= nCall2Log) - { - // loggo - logger.lg.scriviLog(string.Format("pzCounterTC: effettuate {0} call", nCall), tipoLog.INFO); - // resetto! - memLayer.ML.resetRCnt(mHash("COUNT:pCall:getCounterTC")); - } + saveCallRec("getCounterTC"); } // variabile x controllo dati recuperati DS_ProdTempi.StatoProdDataTable datiProdAct = null; @@ -1663,18 +1658,7 @@ namespace MapoDb string rCall = ""; if (memLayer.ML.CRB("IOB_RedEnab")) { - - // conto la richiesta nel contatore REDIS - long nCall = memLayer.ML.setRCntI(mHash("COUNT:pCall:getCounter")); - //... se == nCall2Log scrivo su log e resetto - long nCall2Log = memLayer.ML.cdvi("nCall2Log"); - if (nCall >= nCall2Log) - { - // loggo - logger.lg.scriviLog(string.Format("pzCounter: effettuate {0} call", nCall), tipoLog.INFO); - // resetto! - memLayer.ML.resetRCnt(mHash("COUNT:pCall:getCounter")); - } + saveCallRec("getCounter"); try { rCall = memLayer.ML.getRSV(pzCountHash(idxMacchina)); @@ -1704,18 +1688,7 @@ namespace MapoDb bool answ = false; if (memLayer.ML.CRB("IOB_RedEnab")) { - - // conto la richiesta nel contatore REDIS - long nCall = memLayer.ML.setRCntI(mHash("COUNT:pCall:isMulti")); - //... se == nCall2Log scrivo su log e resetto - long nCall2Log = memLayer.ML.cdvi("nCall2Log"); - if (nCall >= nCall2Log) - { - // loggo - logger.lg.scriviLog(string.Format("isMulti: effettuate {0} call", nCall), tipoLog.INFO); - // resetto! - memLayer.ML.resetRCnt(mHash("COUNT:pCall:isMulti")); - } + saveCallRec("isMulti"); try { answ = Convert.ToBoolean(mDatiMacchinaVal(idxMacchina, "Multi") == "1"); diff --git a/MapoDb/MapoDb.cs b/MapoDb/MapoDb.cs index 559784d1..2df834eb 100644 --- a/MapoDb/MapoDb.cs +++ b/MapoDb/MapoDb.cs @@ -449,28 +449,38 @@ namespace MapoDb return answ; } /// - /// restituisce RIGA dell'ODL attivo (iniziato e NON concluso) + /// Testituisce tabella con riga dell'ODL attivo (iniziato e NON concluso) /// /// /// - public DS_ProdTempi.ODLRow currODLRow(string idxMacchina) + public DS_ProdTempi.ODLDataTable currODLTab(string idxMacchina) { - DS_ProdTempi.ODLRow answ = null; - logger.lg.scriviLog("Recupero currODLRow da DB!", tipoLog.INFO); + DS_ProdTempi.ODLDataTable answ = null; + logger.lg.scriviLog("Recupero currODLTab da DB!", tipoLog.INFO); + try + { + answ = DataLayer.obj.taODL.getByMacchina(idxMacchina); + } + catch (Exception exc) + { + 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) { // solo SE ho idxODL (altrimenti loggo errore) if (tabOdl[0].IdxODL > 0) { - answ = tabOdl[0]; + answ = tabOdl; } else { logger.lg.scriviLog($"Errore in currODLRow x idxMacchina {idxMacchina}: IdxODL = 0", tipoLog.ERROR); } - } + } +#endif // restituisco! return answ; }