From 79b92c9d73a9491ebea478fd4c02016fc2f93749 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Tue, 26 Mar 2019 16:26:14 +0100 Subject: [PATCH] Completata review IO x gestione mData + JOBS di EXE TASK --- MP-IO/Controllers/IOBController.cs | 88 ++++++++++++++---- MapoDb/DataLayer.cs | 138 +++++++++++------------------ 2 files changed, 124 insertions(+), 102 deletions(-) diff --git a/MP-IO/Controllers/IOBController.cs b/MP-IO/Controllers/IOBController.cs index 30401081..23c3d52d 100644 --- a/MP-IO/Controllers/IOBController.cs +++ b/MP-IO/Controllers/IOBController.cs @@ -172,23 +172,29 @@ namespace MP_IO.Controllers } return answ; } + /// - /// Recupera STATO corrente x macchina: + /// Recupera DATI correnti x macchina: /// - /// GET: IOB/getCurrStatus/5 + /// GET: IOB/getCurrData/5 /// /// /// /// jSon contenente la riga di stato macchina - public string getCurrStatus(string id) + public string getCurrData(string id) { string answ = ""; - MapoDb.MapoDb connDb = new MapoDb.MapoDb(); // scrivo keep alive!!! (se necessario, altrimenti è in cache...) + MapoDb.MapoDb connDb = new MapoDb.MapoDb(); connDb.scriviKeepAlive(id, DateTime.Now); - // recupero dati macchina... - Dictionary valori = DataLayer.mDatiMacchine(id); - // cerco il SOLO stato... + try + { + // recupero dati macchina... + Dictionary valori = DataLayer.mDatiMacchine(id); + answ = JsonConvert.SerializeObject(valori); + } + catch + { } return answ; } /// @@ -202,15 +208,65 @@ namespace MP_IO.Controllers public string getTask2Exe(string id) { string answ = ""; - //try - //{ - // answ = DataLayer.currODL(id).ToString(); - //} - //catch (Exception exc) - //{ - // logger.lg.scriviLog(string.Format("Errore in currODL (get){0}{1}", Environment.NewLine, exc)); - // answ = "NO"; - //} + // scrivo keep alive!!! (se necessario, altrimenti è in cache...) + MapoDb.MapoDb connDb = new MapoDb.MapoDb(); + connDb.scriviKeepAlive(id, DateTime.Now); + try + { + // leggo da REDIS eventuale elenco task x macchina... + Dictionary valori = DataLayer.mTaskMacchina(id); + answ = JsonConvert.SerializeObject(valori); + } + catch + { } + return answ; + } + /// + /// AGGIUNGE TASK richiesto x macchina: + /// + /// GET: IOB/addTask2Exe/5?taskName=T180326160502&taskVal=setPrg#PRG001 + /// + /// + /// + /// + /// + public string addTask2Exe(string id, string taskName, string taskVal) + { + string answ = ""; + // scrivo keep alive!!! (se necessario, altrimenti è in cache...) + MapoDb.MapoDb connDb = new MapoDb.MapoDb(); + connDb.scriviKeepAlive(id, DateTime.Now); + try + { + DataLayer.addTask4Machine(id, taskName, taskVal); + answ = getTask2Exe(id); + } + catch + { } + return answ; + } + /// + /// ELIMINA TASK richiesto x macchina: + /// + /// GET: IOB/remTask2Exe/5?taskName=T180326160502 + /// + /// + /// + /// + /// + public string remTask2Exe(string id, string taskName) + { + string answ = ""; + // scrivo keep alive!!! (se necessario, altrimenti è in cache...) + MapoDb.MapoDb connDb = new MapoDb.MapoDb(); + connDb.scriviKeepAlive(id, DateTime.Now); + try + { + DataLayer.remTask4Machine(id, taskName); + answ = getTask2Exe(id); + } + catch + { } return answ; } /// diff --git a/MapoDb/DataLayer.cs b/MapoDb/DataLayer.cs index 36d521c2..6425f596 100644 --- a/MapoDb/DataLayer.cs +++ b/MapoDb/DataLayer.cs @@ -1011,6 +1011,15 @@ namespace MapoDb return mHash(string.Format("DtMac:{0}", idxMacchina)); } /// + /// Hash dati EXE TASK x la macchina specificata + /// + /// + /// + public static string exeTaskHash(string idxMacchina) + { + return mHash(string.Format("ExeTask:{0}", idxMacchina)); + } + /// /// Hash dati STATUS x la macchina specificata. /// - dati ODL /// - dati articolo @@ -1097,124 +1106,81 @@ namespace MapoDb #endregion - #region gestione status macchina (ODL, produzione...) + #region gestione task macchina /// - /// Restitusice elenco KVP dei campi StatoMacchine + ODL per l'impianto indicato + /// Restitusice elenco KVP dei TASK (da passare a IOB-WIN) per l'impianto indicato /// /// /// - public static Dictionary mStatusMacchine(string idxMacchina) + public static Dictionary mTaskMacchina(string idxMacchina) { // hard coded dimensione vettore DatiMacchine Dictionary answ = new Dictionary(); // ORA recupero da memoria redis... try { - string currHash = stMaccHash(idxMacchina); + string currHash = exeTaskHash(idxMacchina); answ = memLayer.ML.redGetHashDict(currHash); - // se è vuoto... leggo da DB e popolo! - if (answ.Count == 0) - { - answ = resetStatusMacchina(idxMacchina); - } } catch (Exception exc) { - logger.lg.scriviLog(string.Format("Errore in compilazione datiSTATUS Macchina x Redis - idxMacchina {2}:{0}{1}", Environment.NewLine, exc, idxMacchina)); + logger.lg.scriviLog(string.Format("Errore in compilazione dati EXE TASK x Redis - idxMacchina {2}:{0}{1}", Environment.NewLine, exc, idxMacchina)); } return answ; } + + /// + /// Aggiunge un task all'elenco di quelli salvati (in modalità upsert) + /// + /// + /// + /// + /// + public static bool addTask4Machine(string idxMacchina, string taskKey, string taskVal) + { + bool answ = false; + string currHash = exeTaskHash(idxMacchina); + try + { + // leggo task attuali... + var currTask = mTaskMacchina(idxMacchina); + currTask[taskKey] = taskVal; + answ = memLayer.ML.redSaveHashDict(currHash, currTask); + } + catch + { } + return answ; + } /// - /// Resetta (rileggendo) i dati StatoMacchine + ODL della macchina + /// Aggiunge un task all'elenco di quelli salvati (in modalità upsert) /// /// + /// /// - public static Dictionary resetStatusMacchina(string idxMacchina) + public static bool remTask4Machine(string idxMacchina, string taskKey) { - string currHash = stMaccHash(idxMacchina); - // inizio con un bel reset... - memLayer.ML.redFlushKey(currHash); - Dictionary answ = new Dictionary(); -#if false - DS_applicazione.MSFDDataTable tabMSFD = new DS_applicazione.MSFDDataTable(); - // 2017.09.13: inserisco gestione singleton condizionale - if (memLayer.ML.CRB("disable_singleton")) - { - // instanzio un nuovo oggetto MapoDb - MapoDb connDb = new MapoDb(); - tabMSFD = connDb.taMSFD.getByIdxMacc(idxMacchina); - } - else - { - tabMSFD = MapoDb.obj.taMSFD.getByIdxMacc(idxMacchina); - } - // se ho righe... - DS_applicazione.MSFDDataTable tab = new DS_applicazione.MSFDDataTable(); - DS_applicazione.MSFDRow rigaMSFD; - if (tabMSFD.Rows.Count > 0) - { - try - { - rigaMSFD = tabMSFD[0]; - } - catch - { - rigaMSFD = tab.NewMSFDRow(); - } - } - else - { - rigaMSFD = tab.NewMSFDRow(); - } - // ora provo a compilare... + bool answ = false; + string currHash = exeTaskHash(idxMacchina); try { - // salvo 1:1 i valori... STATO - answ.Add("IdxMicroStato", rigaMSFD.IdxMicroStato.ToString()); - answ.Add("IdxStato", rigaMSFD.IdxStato.ToString()); - answ.Add("CodArticolo", rigaMSFD.CodArticolo); - answ.Add("insEnabled", rigaMSFD.insEnabled.ToString()); - answ.Add("sLogEnabled", rigaMSFD.sLogEnabled.ToString()); - answ.Add("pallet", rigaMSFD.pallet); - answ.Add("CodArticolo_A", rigaMSFD.CodArticolo_A); - answ.Add("CodArticolo_B", rigaMSFD.CodArticolo_B); - answ.Add("TempoCicloBase", rigaMSFD.TempoCicloBase.ToString()); - answ.Add("PzPalletProd", rigaMSFD.PzPalletProd.ToString()); - answ.Add("MatrOpr", rigaMSFD.MatrOpr.ToString()); - answ.Add("lastVal", rigaMSFD.lastVal); - answ.Add("TCBase", rigaMSFD.TempoCicloBase.ToString()); - - //...e SETUP - answ.Add("CodMacc", rigaMSFD.codmacchina); - answ.Add("IdxFamIn", rigaMSFD.IdxFamigliaIngresso.ToString()); - answ.Add("Multi", rigaMSFD.Multi.ToString()); - answ.Add("BitFilt", rigaMSFD.BitFilt.ToString()); - answ.Add("MaxVal", rigaMSFD.MaxVal.ToString()); - answ.Add("BSR", rigaMSFD.BSR.ToString()); - answ.Add("ExplodeBit", rigaMSFD.ExplodeBit.ToString()); - answ.Add("NumBit", rigaMSFD.NumBit.ToString()); - answ.Add("IdxFamMacc", rigaMSFD.IdxFamiglia.ToString()); - answ.Add("simplePallet", rigaMSFD.simplePallet.ToString()); - answ.Add("palletChange", rigaMSFD.palletChange.ToString()); + // leggo task attuali... + var currTask = mTaskMacchina(idxMacchina); + currTask.Remove(taskKey); + memLayer.ML.redDelKey(currHash); + answ = memLayer.ML.redSaveHashDict(currHash, currTask); } - catch (Exception exc) - { - logger.lg.scriviLog(string.Format("Errore in compilazione dati MSFD:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION); - } -#endif - // verifico il timeout che cambia a seconda che sia vero o falso insEnabled... - int tOutShort = memLayer.ML.cdvi("TmOut.MS.S"); - int tOutLong = memLayer.ML.cdvi("TmOut.MS.L"); - int redDtMacTOut = (answ["insEnabled"].ToLower() == "true") ? tOutShort : tOutLong; - // salvo in redis! - memLayer.ML.redSaveHashDict(currHash, answ, redDtMacTOut); + catch + { } return answ; } + + #endregion #region gestione dati macchina + /// /// Restitusice elenco KVP dei campi DatiMacchine + StatoMacchine per l'impianto indicato ///