pulizia metodi inutili + cambio async recupero stateMachine
This commit is contained in:
@@ -1677,6 +1677,25 @@ namespace MP.Data.Controllers
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Intera tabella state machine ingressi 2 eventi
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<TransizioneIngressiModel>> StateMachineIngressiAsync(int idxFam)
|
||||
{
|
||||
List<TransizioneIngressiModel> dbResult = new List<TransizioneIngressiModel>();
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stato prod macchina (completo)
|
||||
/// </summary>
|
||||
|
||||
@@ -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!
|
||||
|
||||
@@ -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<string, string>[] valori = StateMachInByKey(idxFamIn);
|
||||
KeyValuePair<string, string>[] 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<string, string>[] valori, double expireSeconds = -1.0)
|
||||
{
|
||||
@@ -4233,6 +4219,36 @@ namespace MP.IOC.Data
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
/// <param name="idxFamIn"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<KeyValuePair<string, string>[]> StateMachInByKeyAsync(int idxFamIn)
|
||||
{
|
||||
// hard coded dimensione vettore DatiMacchine
|
||||
KeyValuePair<string, string>[] answ = new KeyValuePair<string, string>[1];
|
||||
// iniziualizzo con un valore... 0/0
|
||||
answ[0] = new KeyValuePair<string, string>("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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Statistiche ODL calcolate (da stored stp_STAT_ODL)
|
||||
@@ -5055,6 +5071,42 @@ namespace MP.IOC.Data
|
||||
RedisSetHash(currHash, answ, tOut);
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// 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)
|
||||
/// </summary>
|
||||
/// <param name="idxFamIn"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<KeyValuePair<string, string>[]> resetSMIAsync(int idxFamIn)
|
||||
{
|
||||
var currHash = Utils.GetHashSMI(idxFamIn);
|
||||
// leggo da DB...
|
||||
var tabSMI = await IocDbController.StateMachineIngressiAsync(idxFamIn);
|
||||
|
||||
KeyValuePair<string, string>[] answ = new KeyValuePair<string, string>[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<string, string>(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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scrive una riga di evento nel db + check cambio stato DiarioDiBordo
|
||||
|
||||
Reference in New Issue
Block a user