From 4d19bf164db37e30e4dc69563d2f2b9642a97c2f Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Mon, 16 Apr 2018 10:50:17 +0200 Subject: [PATCH] Update IO: salva e recupera counter x pz --- .vs/config/applicationhost.config | 2 +- Jenkinsfile | 6 +- MP-IO/Controllers/IOBController.cs | 50 ++++++++++++++ MapoDb/DataLayer.cs | 103 +++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+), 4 deletions(-) diff --git a/.vs/config/applicationhost.config b/.vs/config/applicationhost.config index 45d32f0f..d89451a0 100644 --- a/.vs/config/applicationhost.config +++ b/.vs/config/applicationhost.config @@ -194,7 +194,7 @@ - + diff --git a/Jenkinsfile b/Jenkinsfile index 8af0b4bc..bf46ab49 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,9 +17,9 @@ pipeline { /* calcolo numero versione... diverso x branch MASTER/DEVELOP */ script { - withEnv(['NEXT_BUILD_NUMBER=731']) { - // env.versionNumber = VersionNumber(versionNumberString : '5.0.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true) - env.versionNumber = VersionNumber(versionNumberString : '5.0.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}') + withEnv(['NEXT_BUILD_NUMBER=732']) { + // env.versionNumber = VersionNumber(versionNumberString : '5.1.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true) + env.versionNumber = VersionNumber(versionNumberString : '5.1.${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 7ca7f5dd..c05cdbd2 100644 --- a/MP-IO/Controllers/IOBController.cs +++ b/MP-IO/Controllers/IOBController.cs @@ -140,5 +140,55 @@ namespace MP_IO.Controllers } return answ; } + /// + /// Recupera COUNTER x macchina: + /// + /// GET: IOB/getCounter/5 + /// + /// + /// + /// + public string getCounter(string id) + { + string answ = ""; + try + { + answ = DataLayer.pzCounter(id).ToString(); + } + catch (Exception exc) + { + logger.lg.scriviLog(string.Format("Errore in counter (get){0}{1}", Environment.NewLine, exc)); + answ = "NO"; + } + return answ; + } + /// + /// SALVA Counter x macchina: + /// + /// GET: IOB/setCounter/5?counter=10 + /// + /// + /// + /// + /// + public string setCounter(string id, string counter) + { + string answ = ""; + DateTime dataOraEvento = DateTime.Now; + if (memLayer.ML.CRI("_logLevel") > 6) + { + logger.lg.scriviLog(string.Format("Salvataggio counter:{0}idxMacchina: {1}{0}conteggio: {2}", Environment.NewLine, id, counter), tipoLog.INFO); + } + try + { + answ = DataLayer.saveCounter(id, counter); + } + catch (Exception exc) + { + logger.lg.scriviLog(string.Format("Errore in counter (set){0}{1}", Environment.NewLine, exc)); + answ = "NO"; + } + return answ; + } } } \ No newline at end of file diff --git a/MapoDb/DataLayer.cs b/MapoDb/DataLayer.cs index 20017e4e..a0eecea1 100644 --- a/MapoDb/DataLayer.cs +++ b/MapoDb/DataLayer.cs @@ -792,6 +792,68 @@ namespace MapoDb return answ; } + + /// + /// Processa registrazione di un counter x una data macchina IOB + /// + /// + /// Dati live nel formato chiave1|valore1#chiave2|valore2#chiave3|valore3 + /// + public static string saveCounter(string idxMacchina, string counter) + { + if (counter == null) + { + throw new ArgumentNullException(nameof(counter)); + } + // registro conteggio impiego chiamate REDIS + if (memLayer.ML.CRB("IOB_RedEnab")) + { + // conto la richiesta nel contatore REDIS + long nCall = memLayer.ML.setRCntI(mHash("COUNT:setCounter")); + //... se == nCall2Log scrivo su log e resetto + long nCall2Log = memLayer.ML.cdvi("nCall2Log"); + if (nCall >= nCall2Log) + { + // loggo + logger.lg.scriviLog(string.Format("saveCounter: effettuate {0} call", nCall), tipoLog.INFO); + // resetto! + memLayer.ML.resetRCnt(mHash("COUNT:setCounter")); + } + } + string answ = ""; + DateTime dataOraEvento = DateTime.Now; + // inizio processing vero e proprio INPUT... + if (idxMacchina != null && counter != null) + { + if (idxMacchina != "" && counter != "") + { + int newCounter = -1; + int.TryParse(counter, out newCounter); + // se il conteggio è >= 0 SALVO come nuovo conteggio... + if (newCounter >= 0) + { + // salvo in Redis nell'area CURR_VAL TUTTI i valori live + memLayer.ML.setRSV(pzCountHash(idxMacchina), counter); + } + // registro in risposta che è andato tutto bene... + answ = "OK"; + } + else + { + string errore = "Errore: parametri macchina/counter vuoti"; + logger.lg.scriviLog(errore, tipoLog.ERROR); + answ = errore; + } + } + else + { + string errore = "Errore: mancano parametri macchina/counter"; + logger.lg.scriviLog(errore, tipoLog.ERROR); + answ = errore; + } + return answ; + } + #region definizioni hash x REDIS /// @@ -822,6 +884,15 @@ namespace MapoDb return mHash(string.Format("StMac:{0}", idxMacchina)); } /// + /// Hash dati COUNTER x la macchina specificata + /// + /// + /// + public static string pzCountHash(string idxMacchina) + { + return mHash(string.Format("PzCount:{0}", idxMacchina)); + } + /// /// Hash dati LIVE x la macchina specificata /// /// @@ -1055,6 +1126,38 @@ namespace MapoDb return answ; } + /// + /// Restituisce il contapezzi salvato per la macchina + /// + /// + /// + public static int pzCounter(string idxMacchina) + { + int answ = -1; + if (memLayer.ML.CRB("IOB_RedEnab")) + { + + // conto la richiesta nel contatore REDIS + long nCall = memLayer.ML.setRCntI(mHash("COUNT:getCounter")); + //... 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:getCounter")); + } + try + { + int.TryParse(memLayer.ML.getRSV(pzCountHash(idxMacchina)), out answ); + //answ = Convert.ToBoolean(mDatiMacchinaVal(idxMacchina, "Multi") == "1"); + } + catch + { } + } + return answ; + } /// /// Restituisce il valore booleano se la macchina sia di tipo MULTI (con più state machine x INGRESSI) ///