Update metodi di abse x gestione ODL corrente su REDIS e ricontrollo su DB a scadenza (300 sec x ora)

This commit is contained in:
Samuele E. Locatelli
2018-07-18 11:51:20 +02:00
parent 6aa11c5c39
commit 4f909408e9
3 changed files with 132 additions and 7 deletions
+2
View File
@@ -25,6 +25,8 @@
<add key="_logDir" value="~/logs/" />
<add key="_logLevel" value="7" />
<add key="_logMaxMb" value="30" />
<!--caching dati-->
<add key="currOdlCacheDur" value="300" />
<!--stringhe connessione-->
<add key="DbConfConnectionString" value="Data Source=SQL2016DEV;Initial Catalog=MoonPro;Persist Security Info=True;User ID=sa;Password=keyhammer16;" />
<add key="MoonProConnectionString" value="Data Source=SQL2016DEV;Initial Catalog=MoonPro;Persist Security Info=True;User ID=sa;Password=keyhammer16;" />
+107 -5
View File
@@ -808,7 +808,7 @@ namespace MapoDb
/// Processa registrazione di un counter x una data macchina IOB
/// </summary>
/// <param name="idxMacchina"></param>
/// <param name="counter">Dati live nel formato chiave1|valore1#chiave2|valore2#chiave3|valore3</param>
/// <param name="counter">contapezzi</param>
/// <returns></returns>
public static string saveCounter(string idxMacchina, string counter)
{
@@ -820,7 +820,7 @@ namespace MapoDb
if (memLayer.ML.CRB("IOB_RedEnab"))
{
// conto la richiesta nel contatore REDIS
long nCall = memLayer.ML.setRCntI(mHash("COUNT:pCall:setCounter"));
long nCall = memLayer.ML.setRCntI(mHash("COUNT:pCall:saveCounter"));
//... se == nCall2Log scrivo su log e resetto
long nCall2Log = memLayer.ML.cdvi("nCall2Log");
if (nCall >= nCall2Log)
@@ -828,11 +828,10 @@ namespace MapoDb
// loggo
logger.lg.scriviLog(string.Format("saveCounter: effettuate {0} call", nCall), tipoLog.INFO);
// resetto!
memLayer.ML.resetRCnt(mHash("COUNT:pCall:setCounter"));
memLayer.ML.resetRCnt(mHash("COUNT:pCall:saveCounter"));
}
}
string answ = "";
DateTime dataOraEvento = DateTime.Now;
// inizio processing vero e proprio INPUT...
if (idxMacchina != null && counter != null)
{
@@ -864,6 +863,58 @@ namespace MapoDb
}
return answ;
}
/// <summary>
/// Processa registrazione di un counter x una data macchina IOB
/// </summary>
/// <param name="idxMacchina"></param>
/// <param name="currODL">cod ODL in produzione, se "" --> non c'è...</param>
/// <returns></returns>
public static string saveCurrODL(string idxMacchina, string currODL)
{
if (currODL == null)
{
throw new ArgumentNullException(nameof(currODL));
}
// 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"));
}
}
string answ = "";
// inizio processing vero e proprio INPUT...
if (idxMacchina != null && currODL != null)
{
if (idxMacchina != "" && currODL != "")
{
memLayer.ML.setRSV(currODLHash(idxMacchina), currODL, memLayer.ML.CRI("currOdlCacheDur"));
// registro in risposta che è andato tutto bene...
answ = "OK";
}
else
{
string errore = "Errore: parametri macchina/currODL vuoti";
logger.lg.scriviLog(errore, tipoLog.ERROR);
answ = errore;
}
}
else
{
string errore = "Errore: mancano parametri macchina/currODL";
logger.lg.scriviLog(errore, tipoLog.ERROR);
answ = errore;
}
return answ;
}
#region definizioni hash x REDIS
@@ -901,12 +952,21 @@ namespace MapoDb
/// Hash dati COUNTER x la macchina specificata
/// </summary>
/// <param name="idxMacchina"></param>
/// <returns></returns>
/// <returns></returns>
public static string pzCountHash(string idxMacchina)
{
return mHash(string.Format("PzCount:{0}", idxMacchina));
}
/// <summary>
/// Hash dati Current ODL x la macchina specificata
/// </summary>
/// <param name="idxMacchina"></param>
/// <returns></returns>
public static string currODLHash(string idxMacchina)
{
return mHash(string.Format("CurrODL:{0}", idxMacchina));
}
/// <summary>
/// Hash dati LIVE x la macchina specificata
/// </summary>
/// <param name="idxMacchina"></param>
@@ -1237,6 +1297,48 @@ namespace MapoDb
return answ;
}
/// <summary>
/// Restituisce il valore dell'ODL corrente (ODL deve esserci per gestione contapezzi, senza ODL NO invio/gestione ODL)
/// </summary>
/// <param name="idxMacchina"></param>
/// <returns></returns>
public static string currODL(string idxMacchina)
{
string answ = "";
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("hasODL: effettuate {0} call", nCall), tipoLog.INFO);
// resetto!
memLayer.ML.resetRCnt(mHash("COUNT:pCall:hasODL"));
}
try
{
rCall = memLayer.ML.getRSV(currODLHash(idxMacchina));
if (rCall != "" && rCall != null)
{
answ = rCall;
}
else
{
answ = MapoDb.obj.currODL(idxMacchina);
// salvo in redis...
saveCurrODL(idxMacchina, answ);
}
}
catch
{ }
}
return answ;
}
/// <summary>
/// Restituisce il valore booleano se la macchina sia abilitata all'inserimento COMPLETO nel Signal Log
/// </summary>
/// <param name="idxMacchina"></param>
+23 -2
View File
@@ -90,8 +90,8 @@ namespace MapoDb
taDatiMacch = new DS_applicazioneTableAdapters.DatiMacchineTableAdapter();
taMSM = new DS_applicazioneTableAdapters.MicroStatoMacchinaTableAdapter();
taMSFD = new DS_applicazioneTableAdapters.MSFDTableAdapter();
taDatiMacchine = new DS_ProdTempiTableAdapters.DatiMacchineTableAdapter();
taODL = new DS_ProdTempiTableAdapters.ODLTableAdapter();
taTCRilevati = new DS_ProdTempiTableAdapters.TempiCicloRilevatiTableAdapter();
}
/// <summary>
@@ -116,6 +116,7 @@ namespace MapoDb
taMSM.Connection.ConnectionString = _connectionString;
taMSFD.Connection.ConnectionString = _connectionString;
taDatiMacchine.Connection.ConnectionString = _connectionString;
taODL.Connection.ConnectionString = _connectionString;
taTCRilevati.Connection.ConnectionString = _connectionString;
}
/// <summary>
@@ -275,9 +276,9 @@ namespace MapoDb
public DS_applicazioneTableAdapters.DatiMacchineTableAdapter taDatiMacch;
public DS_applicazioneTableAdapters.MicroStatoMacchinaTableAdapter taMSM;
public DS_applicazioneTableAdapters.MSFDTableAdapter taMSFD;
// area tempi ciclo
public DS_ProdTempiTableAdapters.DatiMacchineTableAdapter taDatiMacchine;
public DS_ProdTempiTableAdapters.ODLTableAdapter taODL;
public DS_ProdTempiTableAdapters.TempiCicloRilevatiTableAdapter taTCRilevati;
#endregion
@@ -406,6 +407,26 @@ namespace MapoDb
return answ;
}
/// <summary>
/// restituisce valore dell'ODL attivo (iniziato e NON concluso)
/// </summary>
/// <param name="idxMacchina"></param>
/// <returns></returns>
public string currODL(string idxMacchina)
{
string answ = "";
var tab = taODL.getByMacchinaAperto(idxMacchina);
if (tab.Rows.Count > 0)
{
try
{
answ = taODL.getByMacchinaAperto(idxMacchina)[0].IdxODL.ToString();
}
catch
{ }
}
return answ;
}
/// <summary>
/// restituisce boolean se la macchina sia abilitata x registrazione segnali in input (tab DatiMacchine)
/// </summary>
/// <param name="idxMacchina"></param>