diff --git a/MP-IO/Controllers/BENCH.cs b/MP-IO/Controllers/BENCH.cs index 731c2cb6..9128dba2 100644 --- a/MP-IO/Controllers/BENCH.cs +++ b/MP-IO/Controllers/BENCH.cs @@ -195,7 +195,7 @@ namespace MP_IO.Controllers answ = ""; try { - KeyValuePair[] valori = DataLayer.mDatiMacchine(idxMacch); + Dictionary valori = DataLayer.mDatiMacchine(idxMacch); foreach (var item in valori) { answ += string.Format("{0}|{1}
", item.Key, item.Value); diff --git a/MP-IO/Controllers/IOBController.cs b/MP-IO/Controllers/IOBController.cs index 708f63ac..7a4a71b7 100644 --- a/MP-IO/Controllers/IOBController.cs +++ b/MP-IO/Controllers/IOBController.cs @@ -29,19 +29,19 @@ namespace MP_IO.Controllers try { - bool insEnabled = false; + bool isEnabled = false; // verifico se sia abilitato INSERT x una data macchina... con REDIS se abilitato if (memLayer.ML.CRB("IOB_RedEnab")) { - insEnabled = DataLayer.insEnab(idx); + isEnabled = DataLayer.insEnab(idx); } // ...oppure dritto su DB else { - insEnabled = MapoDb.MapoDb.obj.insEnabled(idx); + isEnabled = MapoDb.MapoDb.obj.insEnabled(idx); } // salvo risposta! - answ = insEnabled ? "OK" : "NO"; + answ = isEnabled ? "OK" : "NO"; } catch (Exception exc) { @@ -66,15 +66,19 @@ namespace MP_IO.Controllers Int32.TryParse(id.ToString(), out idx); try { - // verifico se sia abilitato SignalLog x una data macchina - if (MapoDb.MapoDb.obj.sLogEnabled(idx)) + bool isEnabled = false; + // verifico se sia abilitato SignalLog x una data macchina... con REDIS se abilitato + if (memLayer.ML.CRB("IOB_RedEnab")) { - answ = "OK"; + isEnabled = DataLayer.sLogEnab(idx); } + // ...oppure dritto su DB else { - answ = "NO"; + isEnabled = MapoDb.MapoDb.obj.sLogEnabled(idx); } + // salvo risposta! + answ = isEnabled ? "OK" : "NO"; } catch (Exception exc) { @@ -158,6 +162,7 @@ namespace MP_IO.Controllers } return answ; } +#if false // GET: IOB/setredis/5 public string setredis(int? id) { @@ -287,6 +292,7 @@ namespace MP_IO.Controllers } } return answ; - } + } +#endif } } \ No newline at end of file diff --git a/MapoDb/DataLayer.cs b/MapoDb/DataLayer.cs index 5ba4ef61..be83bc4d 100644 --- a/MapoDb/DataLayer.cs +++ b/MapoDb/DataLayer.cs @@ -555,19 +555,17 @@ namespace MapoDb /// /// /// - public static KeyValuePair[] mDatiMacchine(int idxMacchina) + public static Dictionary mDatiMacchine(int idxMacchina) { // hard coded dimensione vettore DatiMacchine - KeyValuePair[] answ = new KeyValuePair[1]; - // iniziualizzo con un valore... 0/0 - answ[0] = new KeyValuePair("0", "0"); + Dictionary answ = new Dictionary(); // ORA recupero da memoria redis... try { string currHash = dtMaccHash(idxMacchina); - answ = memLayer.ML.redGetHash(currHash); + answ = memLayer.ML.redGetHashDict(currHash); // se รจ vuoto... leggo da DB e popolo! - if (answ.Length == 0) + if (answ.Count == 0) { answ = resetDatiMacchina(idxMacchina); } @@ -583,46 +581,46 @@ namespace MapoDb /// /// /// - public static KeyValuePair[] resetDatiMacchina(int idxMacchina) + public static Dictionary resetDatiMacchina(int idxMacchina) { string currHash = dtMaccHash(idxMacchina); // inizio con un bel reset... memLayer.ML.redFlushKey(currHash); - KeyValuePair[] answ = new KeyValuePair[18]; + Dictionary answ = new Dictionary(); DS_applicazione.MSFDDataTable tabMSFD = MapoDb.obj.taMSFD.getByIdxMacc(idxMacchina.ToString()); try { DS_applicazione.MSFDRow rigaMSFD = tabMSFD[0]; - // salvo 1:1 i valori... - answ[0] = new KeyValuePair("palletChange", rigaMSFD.palletChange.ToString()); - answ[1] = new KeyValuePair("CodArticolo_A", rigaMSFD.CodArticolo_A); - answ[2] = new KeyValuePair("CodArticolo_B", rigaMSFD.CodArticolo_B); - answ[3] = new KeyValuePair("simplePallet", rigaMSFD.simplePallet.ToString()); - answ[4] = new KeyValuePair("insEnabled", rigaMSFD.insEnabled.ToString()); - answ[5] = new KeyValuePair("sLogEnabled", rigaMSFD.sLogEnabled.ToString()); - answ[6] = new KeyValuePair("IdxStato", rigaMSFD.IdxStato.ToString()); - answ[7] = new KeyValuePair("IdxFamIn", rigaMSFD.IdxFamigliaIngresso.ToString()); - answ[8] = new KeyValuePair("IdxFamMacc", rigaMSFD.IdxFamiglia.ToString()); - answ[9] = new KeyValuePair("CodArticolo", rigaMSFD.CodArticolo); - answ[10] = new KeyValuePair("TempoCicloBase", rigaMSFD.TempoCicloBase.ToString()); - answ[11] = new KeyValuePair("PzPalletProd", rigaMSFD.PzPalletProd.ToString()); - answ[12] = new KeyValuePair("MatrOpr", rigaMSFD.MatrOpr.ToString()); - answ[13] = new KeyValuePair("IdxMicroStato", rigaMSFD.IdxMicroStato.ToString()); - answ[14] = new KeyValuePair("pallet", rigaMSFD.pallet); - answ[15] = new KeyValuePair("lastVal", rigaMSFD.lastVal); - answ[16] = new KeyValuePair("TCBase", rigaMSFD.TempoCicloBase.ToString()); - answ[17] = new KeyValuePair("CodMacc", rigaMSFD.codmacchina); + // 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("IdxFamMacc", rigaMSFD.IdxFamiglia.ToString()); + answ.Add("simplePallet", rigaMSFD.simplePallet.ToString()); + answ.Add("palletChange", rigaMSFD.palletChange.ToString()); } catch { } // 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[4].Value.ToLower() == "true") ? tOutShort : tOutLong; - - //int redDtMacTOut = (memLayer.ML.CRI("redDtMacTOut") <= 0) ? 60 : memLayer.ML.CRI("redDtMacTOut"); + int redDtMacTOut = (answ["insEnabled"].ToLower() == "true") ? tOutShort : tOutLong; // salvo in redis! - memLayer.ML.redSaveHash(currHash, answ, redDtMacTOut); + memLayer.ML.redSaveHashDict(currHash, answ, redDtMacTOut); return answ; } @@ -706,6 +704,23 @@ namespace MapoDb return memLayer.ML.redGetHashField(currHash, field); } /// + /// Restituisce valore di una singola chiave del dizionario DatiMacchina + /// + /// + /// + /// + public static string mDatiMacchinaVal(int idxMacchina, string chiave) + { + string answ = ""; + try + { + answ = mDatiMacchine(idxMacchina)[chiave]; + } + catch + { } + return answ; + } + /// /// Restituisce il valore booleano se la macchina sia abilitata all'input /// /// @@ -713,18 +728,25 @@ namespace MapoDb public static bool insEnab(int idxMacchina) { bool answ = false; - string currHash = dtMaccHash(idxMacchina); - string field = "insEnabled"; try { - // verifico se ne ho altrimenti ricarico... - bool trovato = memLayer.ML.redHashPresentSz(currHash); - if (!trovato) - { - // ricarico tabella! - KeyValuePair[] valori = DataLayer.mDatiMacchine(idxMacchina); - } - answ = Convert.ToBoolean(memLayer.ML.redGetHashField(currHash, field)); + answ = Convert.ToBoolean(mDatiMacchinaVal(idxMacchina, "insEnabled")); + } + catch + { } + return answ; + } + /// + /// Restituisce il valore booleano se la macchina sia abilitata all'inserimento COMPLETO nel Signal Log + /// + /// + /// + public static bool sLogEnab(int idxMacchina) + { + bool answ = false; + try + { + answ = Convert.ToBoolean(mDatiMacchinaVal(idxMacchina, "sLogEnabled")); } catch { }