diff --git a/MapoDb/DS_applicazione.Designer.cs b/MapoDb/DS_applicazione.Designer.cs index 4f319851..3fe1fb26 100644 --- a/MapoDb/DS_applicazione.Designer.cs +++ b/MapoDb/DS_applicazione.Designer.cs @@ -24938,7 +24938,7 @@ SELECT CodArticolo, DescArticolo, CurrRev, ProdRev, FlagIsNew FROM AnagArticoli [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "15.0.0.0")] private void InitCommandCollection() { - this._commandCollection = new global::System.Data.SqlClient.SqlCommand[2]; + this._commandCollection = new global::System.Data.SqlClient.SqlCommand[3]; this._commandCollection[0] = new global::System.Data.SqlClient.SqlCommand(); this._commandCollection[0].Connection = this.Connection; this._commandCollection[0].CommandText = "dbo.stp_MSFD_getAll"; @@ -24950,6 +24950,11 @@ SELECT CodArticolo, DescArticolo, CurrRev, ProdRev, FlagIsNew FROM AnagArticoli this._commandCollection[1].CommandType = global::System.Data.CommandType.StoredProcedure; this._commandCollection[1].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@RETURN_VALUE", global::System.Data.SqlDbType.Int, 4, global::System.Data.ParameterDirection.ReturnValue, 10, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); this._commandCollection[1].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@IdxMacchina", global::System.Data.SqlDbType.NVarChar, 50, global::System.Data.ParameterDirection.Input, 0, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); + this._commandCollection[2] = new global::System.Data.SqlClient.SqlCommand(); + this._commandCollection[2].Connection = this.Connection; + this._commandCollection[2].CommandText = "dbo.stp_MSFD_getMulti"; + this._commandCollection[2].CommandType = global::System.Data.CommandType.StoredProcedure; + this._commandCollection[2].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@RETURN_VALUE", global::System.Data.SqlDbType.Int, 4, global::System.Data.ParameterDirection.ReturnValue, 10, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -24992,6 +24997,17 @@ SELECT CodArticolo, DescArticolo, CurrRev, ProdRev, FlagIsNew FROM AnagArticoli this.Adapter.Fill(dataTable); return dataTable; } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "15.0.0.0")] + [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")] + [global::System.ComponentModel.DataObjectMethodAttribute(global::System.ComponentModel.DataObjectMethodType.Select, false)] + public virtual DS_applicazione.MSFDDataTable getMulti() { + this.Adapter.SelectCommand = this.CommandCollection[2]; + DS_applicazione.MSFDDataTable dataTable = new DS_applicazione.MSFDDataTable(); + this.Adapter.Fill(dataTable); + return dataTable; + } } } diff --git a/MapoDb/DS_applicazione.xsd b/MapoDb/DS_applicazione.xsd index bdc52d4b..c2b25037 100644 --- a/MapoDb/DS_applicazione.xsd +++ b/MapoDb/DS_applicazione.xsd @@ -2385,6 +2385,16 @@ SELECT CodArticolo, DescArticolo, CurrRev, ProdRev, FlagIsNew FROM AnagArticoli + + + + dbo.stp_MSFD_getMulti + + + + + + diff --git a/MapoDb/DS_applicazione.xss b/MapoDb/DS_applicazione.xss index 169202e3..df763f9e 100644 --- a/MapoDb/DS_applicazione.xss +++ b/MapoDb/DS_applicazione.xss @@ -4,7 +4,7 @@ Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. --> - + @@ -29,7 +29,7 @@ - + diff --git a/MapoDb/DataLayer.cs b/MapoDb/DataLayer.cs index 403ba214..ee66d6ca 100644 --- a/MapoDb/DataLayer.cs +++ b/MapoDb/DataLayer.cs @@ -478,12 +478,13 @@ namespace MapoDb { // inizio preprocessing string newVal = ""; - // processo OGNI macchina a stati dell'impianto... (IdxMacchina e IdxMacchina#qualcosa...) - //foreach(){ !!!FARE!!! - newVal = preProcInput(idxMacchina, valore); - // ora processo e salvo il valore del microstato... INTERNAMENTE gestisce i casi DB/REDIS secondo necessità - connDb.checkMicroStato(idxMacchina, newVal, dataOraEvento, contatore); - //}!!!FARE!!! + // processo OGNI macchina a stati dell'impianto... (KEY: IdxMacchina / IdxMacchina#qualcosa, Val = IdxFamIn) + foreach (var item in mTabMSMI(idxMacchina)) + { + newVal = preProcInput(item.Key, valore); + // ora processo e salvo il valore del microstato... INTERNAMENTE gestisce i casi DB/REDIS secondo necessità + connDb.checkMicroStato(item.Key, newVal, dataOraEvento, contatore); + } } else { @@ -595,7 +596,7 @@ namespace MapoDb // effettuo eventuale esplosione in BIT esclusivi if (ExplodeBit) { - newValInt = 1 << newValInt; + newValInt = Convert.ToInt32(1 << newValInt); } // riconverto a STRING HEX!!! newVal = newValInt.ToString("X"); @@ -637,6 +638,15 @@ namespace MapoDb { return mHash(string.Format("hSMI:{0}", idxFamIn)); } + /// + /// Hash dati Macchine Multi SM Ingressi + /// + /// Macchina PRINCIPALE + /// + public static string hMSMI(string IdxMacchina) + { + return mHash(string.Format("hMSMI:{0}", IdxMacchina)); + } #endregion @@ -855,6 +865,74 @@ namespace MapoDb #region gestione State Machine Ingressi + + /// + /// Restitusice elenco KVP + /// key: IdxMacchina + /// value: IdxFamigliaIngresso + /// + /// + /// + public static KeyValuePair[] mTabMSMI(string idxMacchina) + { + // hard coded dimensione vettore DatiMacchine + KeyValuePair[] answ = new KeyValuePair[1]; + // iniziualizzo con un valore... 0/0 + answ[0] = new KeyValuePair("0", "0"); + // ORA recupero da memoria redis... + try + { + string currHash = hMSMI(idxMacchina); + answ = memLayer.ML.redGetHash(currHash); + // se è vuoto... leggo da DB e popolo! + if (answ.Length == 0) + { + answ = resetMSMI(idxMacchina); + } + } + catch (Exception exc) + { + logger.lg.scriviLog(string.Format("Errore in compilazione Tabella Multi State Machine Ingressi x Redis:{0}{1}", Environment.NewLine, exc)); + } + return answ; + } + /// + /// Resetta (rileggendo) i dati della State Machine multi ingressi nel formato + /// key: IdxMacchina + /// value: IdxFamigliaIngresso + /// + /// + /// + public static KeyValuePair[] resetMSMI(string idxMacchina) + { + string currHash = hMSMI(idxMacchina); + DS_applicazione.MSFDDataTable tabMSMI = 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(); + tabMSMI = connDb.taMSFD.getMulti(); + } + else + { + // leggo DB da singleton + tabMSMI = MapoDb.obj.taMSFD.getMulti(); + } + KeyValuePair[] answ = new KeyValuePair[tabMSMI.Count]; + // salvo tutti i valori StateMachineIngressi... + int i = 0; + foreach (var item in tabMSMI) + { + answ[i] = new KeyValuePair(item.IdxMacchina, item.IdxFamigliaIngresso.ToString()); + i++; + } + // verifico il timeout (default 60 sec...) + int tOut = (memLayer.ML.cdvi("TmOut.MSMI") <= 0) ? 60 : memLayer.ML.cdvi("TmOut.MSMI"); + // salvo in redis! + memLayer.ML.redSaveHash(currHash, answ, tOut); + return answ; + } /// /// Restitusice elenco KVP dei campi della State Machine ingressi nel formato /// key: cState_nVal (current MICRO-STATE + "_" + new Value) @@ -920,7 +998,7 @@ namespace MapoDb answ[i] = new KeyValuePair(key, val); i++; } - // verifico il timeout (default 60 sec... + // verifico il timeout (default 60 sec...) int tOut = (memLayer.ML.cdvi("TmOut.SMI") <= 0) ? 60 : memLayer.ML.cdvi("TmOut.SMI"); // salvo in redis! memLayer.ML.redSaveHash(currHash, answ, tOut);