diff --git a/MP.Data/Controllers/MpIocController.cs b/MP.Data/Controllers/MpIocController.cs
index 5e05ff15..d6134939 100644
--- a/MP.Data/Controllers/MpIocController.cs
+++ b/MP.Data/Controllers/MpIocController.cs
@@ -1677,6 +1677,25 @@ namespace MP.Data.Controllers
return dbResult;
}
+ ///
+ /// Intera tabella state machine ingressi 2 eventi
+ ///
+ ///
+ public async Task> StateMachineIngressiAsync(int idxFam)
+ {
+ List dbResult = new List();
+ using (var dbCtx = new MoonProContext(_configuration))
+ {
+ var IdxFamIn = new SqlParameter("@IdxFamigliaIngresso", idxFam);
+ dbResult = await dbCtx
+ .DbSetSMI
+ .FromSqlRaw("exec dbo.stp_TRI_getByIdxFamIng @IdxFamigliaIngresso", IdxFamIn)
+ .AsNoTracking()
+ .ToListAsync();
+ }
+ return dbResult;
+ }
+
///
/// Stato prod macchina (completo)
///
diff --git a/MP.IOC/Controllers/BenchController.cs b/MP.IOC/Controllers/BenchController.cs
index b12d7cd8..3d5e6fd2 100644
--- a/MP.IOC/Controllers/BenchController.cs
+++ b/MP.IOC/Controllers/BenchController.cs
@@ -123,7 +123,7 @@ namespace MP.IOC.Controllers
{
var fiHASH = Utils.GetHashSMI(idxFamIn);
string outVal = "";
- bool trovato = DService.RedisHashPresent(fiHASH);
+ bool trovato = DService.RedisKeyPresent(fiHASH);
if (!trovato)
{
// ricarico tabella!
diff --git a/MP.IOC/Data/MpDataService.cs b/MP.IOC/Data/MpDataService.cs
index c80bc1d0..cf9ed024 100644
--- a/MP.IOC/Data/MpDataService.cs
+++ b/MP.IOC/Data/MpDataService.cs
@@ -970,11 +970,11 @@ namespace MP.IOC.Data
next_idxMS = idxMicroStato;
// verifico esistenza tab SMI...
var fiHASH = Utils.GetHashSMI(idxFamIn);
- bool trovato = RedisHashPresent(fiHASH);
+ bool trovato = await RedisKeyPresentAsync(fiHASH);
if (!trovato)
{
// ricarico tabella (salvando in redis x ricerca successiva)!
- KeyValuePair[] valori = StateMachInByKey(idxFamIn);
+ KeyValuePair[] valori = await StateMachInByKeyAsync(idxFamIn);
}
string todoSMI = "";
// recupero singolo valore (stringa) x chiave
@@ -3545,16 +3545,6 @@ namespace MP.IOC.Data
return result;
}
- public bool RedisHashPresent(RedisKey key)
- {
- return redisDb.KeyExists(key);
- }
-
- public bool RedisHashPresentSz(string key)
- {
- return RedisHashPresent((RedisKey)key);
- }
-
public bool RedisKeyPresent(RedisKey key)
{
return redisDb.KeyExists(key);
@@ -3565,10 +3555,6 @@ namespace MP.IOC.Data
return await redisDb.KeyExistsAsync(key);
}
- public bool RedisKeyPresentSz(string key)
- {
- return RedisKeyPresent((RedisKey)key);
- }
public void RedisSetHash(RedisKey redKey, KeyValuePair[] valori, double expireSeconds = -1.0)
{
@@ -4233,6 +4219,36 @@ namespace MP.IOC.Data
}
return answ;
}
+ ///
+ /// Restitusice elenco KVP dei campi della State Machine ingressi nel formato
+ /// currKey: cState_nVal (current MICRO-STATE + "_" + new Value)
+ /// value: iTipoEv_nState (IdxTipoEv da trasmettere + New MICRO-STATE
+ ///
+ ///
+ ///
+ public async Task[]> StateMachInByKeyAsync(int idxFamIn)
+ {
+ // 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
+ {
+ var currHash = Utils.GetHashSMI(idxFamIn);
+ answ = await RedisGetHashAsync(currHash);
+ // se รจ vuoto... leggo da DB e popolo!
+ if (answ.Length == 0)
+ {
+ answ = await resetSMIAsync(idxFamIn);
+ }
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Errore in compilazione State Machine Ingressi x Redis:{Environment.NewLine}{exc}");
+ }
+ return answ;
+ }
///
/// Statistiche ODL calcolate (da stored stp_STAT_ODL)
@@ -5055,6 +5071,42 @@ namespace MP.IOC.Data
RedisSetHash(currHash, answ, tOut);
return answ;
}
+ ///
+ /// Resetta (rileggendo) i dati della State Machine ingressi nel formato
+ /// currKey: cState_nVal (current MICRO-STATE + "_" + new Value)
+ /// value: iTipoEv_nState (IdxTipoEv da trasmettere + New MICRO-STATE)
+ ///
+ ///
+ ///
+ private async Task[]> resetSMIAsync(int idxFamIn)
+ {
+ var currHash = Utils.GetHashSMI(idxFamIn);
+ // leggo da DB...
+ var tabSMI = await IocDbController.StateMachineIngressiAsync(idxFamIn);
+
+ KeyValuePair[] answ = new KeyValuePair[tabSMI.Count];
+ // salvo tutti i valori StateMachineIngressi...
+ int i = 0;
+ string key = "";
+ string val = "";
+ foreach (var item in tabSMI)
+ {
+ key = string.Format("{0}_{1}", item.IdxMicroStato, item.ValoreIngresso);
+ val = string.Format("{0}_{1}", item.IdxTipoEvento, item.NextIdxMicroStato);
+ answ[i] = new KeyValuePair(key, val);
+ i++;
+ }
+ // verifico il timeout (default 60 sec...)
+ var sTOutSmi = tryGetConfig("TmOut.SMI").Result;
+ int tOut = 60;
+ if (!string.IsNullOrEmpty(sTOutSmi))
+ {
+ int.TryParse(sTOutSmi, out tOut);
+ }
+ // salvo in redis!
+ await RedisSetHashAsync(currHash, answ, tOut);
+ return answ;
+ }
///
/// Scrive una riga di evento nel db + check cambio stato DiarioDiBordo