Completato porting BENCH
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MP.IOC.Data;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using NLog.Fluent;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace MP.IOC.Controllers
|
||||
@@ -13,6 +9,8 @@ namespace MP.IOC.Controllers
|
||||
[ApiController]
|
||||
public class BenchController : ControllerBase
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public BenchController(IConfiguration configuration, MpDataService DataService)
|
||||
{
|
||||
Log.Info("Starting MpDataService INIT");
|
||||
@@ -21,28 +19,173 @@ namespace MP.IOC.Controllers
|
||||
Log.Info("Avviata classe Recipe");
|
||||
}
|
||||
|
||||
private static IConfiguration _configuration = null!;
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
/// <summary>
|
||||
/// Dataservice x accesso DB
|
||||
/// Conteggio chiavi REDIS dato pattern api/Bench/CountKeys
|
||||
/// </summary>
|
||||
protected MpDataService DService { get; set; }
|
||||
|
||||
//// GET: IOB (è un check alive)
|
||||
//public string Index()
|
||||
//{
|
||||
// return "OK";
|
||||
//}
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("CountKeys")]
|
||||
public string CountKeys(string? id)
|
||||
{
|
||||
string answ = "ND";
|
||||
if (id == null) id = "";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
// conto quanti oggetti ho in memoria REDIS...
|
||||
string groupHash = ""; // DataLayer.mHash("");
|
||||
if (id.Length > 0)
|
||||
{
|
||||
groupHash += id + ":";
|
||||
}
|
||||
groupHash += "*";
|
||||
answ = $"Trovate {DService.RedisCountKey(groupHash)} Hash per {groupHash}";
|
||||
stopWatch.Stop();
|
||||
// Get the elapsed time as a TimeSpan value.
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
// accodo tempo!
|
||||
answ += $"{Environment.NewLine}Elapsed: {ts.TotalMilliseconds}ms";
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// pulizia dati
|
||||
/// api/Bench/RClean?id=100
|
||||
/// Bench recupero dati macchina api/Bench/DtMac?id=SIMUL_01
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("DatiMacc")]
|
||||
public string DatiMacc(string id)
|
||||
{
|
||||
string answ = "ND";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
// se id nullo --> KO!
|
||||
if (id == null)
|
||||
{
|
||||
answ = "KO";
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = "";
|
||||
try
|
||||
{
|
||||
Dictionary<string, string> valori = DService.ResetDatiMacchina(id);
|
||||
foreach (var item in valori)
|
||||
{
|
||||
answ += $"{item.Key}|{item.Value}{Environment.NewLine}";
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
stopWatch.Stop();
|
||||
// Get the elapsed time as a TimeSpan value.
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
// accodo tempo!
|
||||
answ += $"{Environment.NewLine}Elapsed: {ts.TotalMilliseconds}ms";
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary> Recupera riga traduzione microstato x processing da HASH table
|
||||
/// api/Bench/FindSMI?id=60&idxMS=3&valore=1 </summary> <param name="id"></param> <param
|
||||
/// name="idxMS"></param> <param name="valore"></param> <returns></returns>
|
||||
[HttpGet("FindSMI")]
|
||||
public string FindSMI(int? id, int? idxMS, int? valore)
|
||||
{
|
||||
string answ = "ND";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
// se id nullo --> KO!
|
||||
if (id == null)
|
||||
{
|
||||
answ = "KO";
|
||||
}
|
||||
else
|
||||
{
|
||||
// recupero dati x sapere quale famiglia SMI è necessaria e quale stato / segnale si
|
||||
// sia ricevuto
|
||||
int idxFamIn = Convert.ToInt32(id);
|
||||
int idxMicroStato = Convert.ToInt32(idxMS);
|
||||
int valIOB = Convert.ToInt32(valore);
|
||||
// recupero microstato macchina da chiave relativa
|
||||
answ = "";
|
||||
try
|
||||
{
|
||||
string fiHASH = DService.hSMI(idxFamIn);
|
||||
string outVal = "";
|
||||
bool trovato = DService.RedisHashPresentSz(fiHASH);
|
||||
if (!trovato)
|
||||
{
|
||||
// ricarico tabella!
|
||||
KeyValuePair<string, string>[] valori = DService.StateMachInByKey(idxFamIn);
|
||||
answ = string.Format("Ricaricata SMI per famiglia {0}<br/>", fiHASH);
|
||||
}
|
||||
|
||||
// recupero singolo valore (stringa) x chiave
|
||||
outVal = DService.ValoreSMI(idxFamIn, idxMicroStato, valIOB);
|
||||
// mostro output
|
||||
answ += $"idxFamIN: {idxFamIn} | idxMS: {idxMicroStato} | valIOB: {valIOB} | out: {outVal}";
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
stopWatch.Stop();
|
||||
// Get the elapsed time as a TimeSpan value.
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
// accodo tempo!
|
||||
answ += $"{Environment.NewLine}Total Time Elapsed: {ts.TotalMilliseconds}ms";
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test verifica insert enabled x macchina
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("InsEnab")]
|
||||
public string InsEnab(string id)
|
||||
{
|
||||
string answ = "ND";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
// se id nullo --> KO!
|
||||
if (id == null)
|
||||
{
|
||||
answ = "KO";
|
||||
}
|
||||
else
|
||||
{
|
||||
// recupero microstato macchina da chiave relativa
|
||||
answ = "";
|
||||
try
|
||||
{
|
||||
answ += $"Macchina {id}, insEnabled {DService.IobInsEnab(id)}{Environment.NewLine}";
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
stopWatch.Stop();
|
||||
// Get the elapsed time as a TimeSpan value.
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
// accodo tempo!
|
||||
answ += $"{Environment.NewLine}Total Time Elapsed: {ts.TotalMilliseconds}ms";
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// pulizia dati api/Bench/RClean?id=100
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("RClean")]
|
||||
public string RCLEAN(int? id)
|
||||
public string RClean(int? id)
|
||||
{
|
||||
string answ = "ND";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
@@ -77,14 +220,19 @@ namespace MP.IOC.Controllers
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
|
||||
//// GET: IOB (è un check alive)
|
||||
//public string Index()
|
||||
//{
|
||||
// return "OK";
|
||||
//}
|
||||
/// <summary>
|
||||
/// Setup dati di test hash
|
||||
/// api/Bench/RSetup?id=100
|
||||
/// Setup dati di test hash api/Bench/RSetup?id=100
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("RSetup")]
|
||||
public string RSETUP(int? id)
|
||||
public string RSetup(int? id)
|
||||
{
|
||||
string answ = "ND";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
@@ -121,14 +269,14 @@ namespace MP.IOC.Controllers
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupero singolo valore hash
|
||||
/// api/Bench/RSingleHash?id=50
|
||||
/// Recupero singolo valore hash api/Bench/RSingleHash?id=50
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("RSingleHash")]
|
||||
public string RSH(int? id)
|
||||
public string RSingleHash(int? id)
|
||||
{
|
||||
string answ = "ND";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
@@ -164,81 +312,14 @@ namespace MP.IOC.Controllers
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Bench recupero dati macchina
|
||||
/// api/Bench/DtMac?id=SIMUL_01
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("DtMac")]
|
||||
public string DTMAC(string id)
|
||||
{
|
||||
string answ = "ND";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
// se id nullo --> KO!
|
||||
if (id == null)
|
||||
{
|
||||
answ = "KO";
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = "";
|
||||
try
|
||||
{
|
||||
Dictionary<string, string> valori = DService.MSFDMaccGetCurr(id);
|
||||
foreach (var item in valori)
|
||||
{
|
||||
answ += $"{item.Key}|{item.Value}{Environment.NewLine}";
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
stopWatch.Stop();
|
||||
// Get the elapsed time as a TimeSpan value.
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
// accodo tempo!
|
||||
answ += $"{Environment.NewLine}Elapsed: {ts.TotalMilliseconds}ms";
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Conteggio chiavi REDIS dato pattern
|
||||
/// api/Bench/CountKeys
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("CountKeys")]
|
||||
public string CNTKEY(string? id)
|
||||
{
|
||||
string answ = "ND";
|
||||
if (id == null) id = "";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
// conto quanti oggetti ho in memoria REDIS...
|
||||
string groupHash = ""; // DataLayer.mHash("");
|
||||
if (id.Length > 0)
|
||||
{
|
||||
groupHash += id + ":";
|
||||
}
|
||||
groupHash += "*";
|
||||
answ = $"Trovate {DService.RedisCountKey(groupHash)} Hash per {groupHash}";
|
||||
stopWatch.Stop();
|
||||
// Get the elapsed time as a TimeSpan value.
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
// accodo tempo!
|
||||
answ += $"{Environment.NewLine}Elapsed: {ts.TotalMilliseconds}ms";
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lettura tab StateMachineIngressi
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("StateMachineIn")]
|
||||
public string tSMI(int? id)
|
||||
public string StateMachineIn(int? id)
|
||||
{
|
||||
string answ = "ND";
|
||||
long splitTime = 0;
|
||||
@@ -273,83 +354,24 @@ namespace MP.IOC.Controllers
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
//// GET BENCH/fSMI/18?idxMS=1&valore=1
|
||||
//public string fSMI(int? id, int? idxMS, int? valore)
|
||||
//{
|
||||
// string answ = "ND";
|
||||
// Stopwatch stopWatch = new Stopwatch();
|
||||
// stopWatch.Start();
|
||||
// // se id nullo --> KO!
|
||||
// if (id == null)
|
||||
// {
|
||||
// answ = "KO";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // recupero dati x sapere quale famiglia SMI è necessaria e quale stato / segnale si sia ricevuto
|
||||
// int idxFamIn = Convert.ToInt32(id);
|
||||
// int idxMicroStato = Convert.ToInt32(idxMS);
|
||||
// int valIOB = Convert.ToInt32(valore);
|
||||
// // recupero microstato macchina da chiave relativa
|
||||
// answ = "";
|
||||
// try
|
||||
// {
|
||||
// // verifico se ci sia in memoria tab della fam macchina relativa (sennò carico)
|
||||
// string fiHASH = DataLayer.hSMI(idxFamIn);
|
||||
// string outVal = "";
|
||||
// bool trovato = memLayer.ML.redHashPresentSz(fiHASH);
|
||||
// if (!trovato)
|
||||
// {
|
||||
// // ricarico tabella!
|
||||
// KeyValuePair<string, string>[] valori = DataLayerObj.mTabSMI(idxFamIn);
|
||||
// answ = string.Format("Ricaricata SMI per famiglia {0}<br/>", fiHASH);
|
||||
// }
|
||||
// answ += string.Format("Trovata {0} Hash per {1}<br />", memLayer.ML.redCountKey(fiHASH), fiHASH);
|
||||
// // recupero singolo valore (stringa) x chiave
|
||||
// outVal = DataLayerObj.valoreSMI(idxFamIn, idxMicroStato, valIOB);
|
||||
// // mostro output
|
||||
// answ += string.Format("idxFamIN: {0} | idxMS: {1} | valIOB: {2} | out: {3} <br/>", idxFamIn, idxMicroStato, valIOB, outVal);
|
||||
// }
|
||||
// catch
|
||||
// { }
|
||||
// }
|
||||
// stopWatch.Stop();
|
||||
// // Get the elapsed time as a TimeSpan value.
|
||||
// TimeSpan ts = stopWatch.Elapsed;
|
||||
// // accodo tempo!
|
||||
// answ += string.Format("<hr/>Total Time Elapsed: {0}ms", ts.TotalMilliseconds);
|
||||
// // ritorno
|
||||
// return answ;
|
||||
//}
|
||||
//// GET BENCH/INSEN/2004
|
||||
//public string INSEN(string id)
|
||||
//{
|
||||
// string answ = "ND";
|
||||
// Stopwatch stopWatch = new Stopwatch();
|
||||
// stopWatch.Start();
|
||||
// // se id nullo --> KO!
|
||||
// if (id == null)
|
||||
// {
|
||||
// answ = "KO";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // recupero microstato macchina da chiave relativa
|
||||
// answ = "";
|
||||
// try
|
||||
// {
|
||||
// answ += string.Format("Macchina {0}, insEnabled {1}<br />", id, DataLayerObj.insEnab(id));
|
||||
// }
|
||||
// catch
|
||||
// { }
|
||||
// }
|
||||
// stopWatch.Stop();
|
||||
// // Get the elapsed time as a TimeSpan value.
|
||||
// TimeSpan ts = stopWatch.Elapsed;
|
||||
// // accodo tempo!
|
||||
// answ += string.Format("<hr/>Total Time Elapsed: {0}ms", ts.TotalMilliseconds);
|
||||
// // ritorno
|
||||
// return answ;
|
||||
//}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
/// <summary>
|
||||
/// Dataservice x accesso DB
|
||||
/// </summary>
|
||||
protected MpDataService DService { get; set; }
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static IConfiguration _configuration = null!;
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
+277
-97
@@ -73,6 +73,16 @@ namespace MP.IOC.Data
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Hash dati STATUS x la macchina specificata
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
public static string dtMaccHash(string idxMacchina)
|
||||
{
|
||||
return $"{redisBaseAddrIOC}DtMac:{idxMacchina}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera eventuali azioni richieste
|
||||
/// </summary>
|
||||
@@ -408,7 +418,7 @@ namespace MP.IOC.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string currKey = $"{redisBaseAddr}:TabDatiMacchine:ALL";
|
||||
string currKey = $"{redisBaseAddrIOC}:TabDatiMacchine:ALL";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
@@ -647,7 +657,7 @@ namespace MP.IOC.Data
|
||||
public async Task<bool> FlushRedisCache()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
RedisValue pattern = new RedisValue($"{redisBaseAddrSpec}*");
|
||||
RedisValue pattern = new RedisValue($"{redisBaseAddrIOC}*");
|
||||
bool answ = await RedisFlushPatternAsync(pattern);
|
||||
// rileggo vocabolario.,..
|
||||
ObjVocabolario = VocabolarioGetAll();
|
||||
@@ -657,7 +667,7 @@ namespace MP.IOC.Data
|
||||
public async Task<bool> FlushRedisKey(string redKey)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
RedisValue pattern = new RedisValue($"{redisBaseAddrSpec}:{redKey}");
|
||||
RedisValue pattern = new RedisValue($"{redisBaseAddrIOC}{redKey}");
|
||||
bool answ = await RedisFlushPatternAsync(pattern);
|
||||
return answ;
|
||||
}
|
||||
@@ -731,6 +741,11 @@ namespace MP.IOC.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
public string hSMI(int idxFamIn)
|
||||
{
|
||||
return $"{redisBaseAddrIOC}hSMI:{idxFamIn}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Init ricetta
|
||||
/// </summary>
|
||||
@@ -743,6 +758,17 @@ namespace MP.IOC.Data
|
||||
return mongoController.InitRecipe(confPath, idxPODL, CalcArgs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il valore booleano se la macchina sia abilitata all'input
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
public bool IobInsEnab(string idxMacchina)
|
||||
{
|
||||
bool answ = Convert.ToBoolean(mDatiMacchinaVal(idxMacchina, "insEnabled"));
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="IdxOdl">id odl da cercare</param>
|
||||
@@ -911,7 +937,7 @@ namespace MP.IOC.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string currKey = $"{redisBaseAddr}:M2STab";
|
||||
string currKey = $"{redisBaseAddrIOC}:M2STab";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
@@ -1045,82 +1071,48 @@ namespace MP.IOC.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce valore di una singola chiave del dizionario DatiMacchina
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="chiave"></param>
|
||||
/// <returns></returns>
|
||||
public string mDatiMacchinaVal(string idxMacchina, string chiave)
|
||||
{
|
||||
string answ = "";
|
||||
try
|
||||
{
|
||||
answ = mDatiMacchine(idxMacchina)[chiave];
|
||||
}
|
||||
catch { }
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restitusice elenco KVP dei campi DatiMacchine + StatoMacchine per l'impianto indicato
|
||||
/// </summary>
|
||||
/// <param name="idxMacc"></param>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
public Dictionary<string, string> MSFDMaccGetCurr(string idxMacc)
|
||||
public Dictionary<string, string> mDatiMacchine(string idxMacchina)
|
||||
{
|
||||
Dictionary<string, string>? result = new Dictionary<string, string>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string currKey = $"{redisBaseAddr}:DSMacc:{idxMacc}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
// hard coded dimensione vettore DatiMacchine
|
||||
Dictionary<string, string> answ = new Dictionary<string, string>();
|
||||
// ORA recupero da memoria redis...
|
||||
try
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<Dictionary<string, string>>($"{rawData}");
|
||||
readType = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
var dbResults = dbController.VMSFDGetByMacc(idxMacc);
|
||||
// converto in formato dizionario...
|
||||
if (dbResults != null && dbResults.Count > 0)
|
||||
string currHash = dtMaccHash(idxMacchina);
|
||||
answ = RedisGetHashDict(currHash);
|
||||
// se è vuoto... leggo da DB e popolo!
|
||||
if (answ.Count == 0)
|
||||
{
|
||||
var rowResult = dbResults[0];
|
||||
// salvo 1:1 i valori... STATO
|
||||
result.Add("IdxMicroStato", $"{rowResult.IdxMicroStato}");
|
||||
result.Add("IdxStato", $"{rowResult.IdxStato}");
|
||||
result.Add("CodArticolo", $"{rowResult.CodArticolo}");
|
||||
result.Add("insEnabled", $"{rowResult.InsEnabled}");
|
||||
result.Add("sLogEnabled", $"{rowResult.SLogEnabled}");
|
||||
result.Add("pallet", $"{rowResult.Pallet}");
|
||||
result.Add("CodArticolo_A", $"{rowResult.CodArticoloA}");
|
||||
result.Add("CodArticolo_B", $"{rowResult.CodArticoloB}");
|
||||
result.Add("TempoCicloBase", $"{rowResult.TempoCicloBase}");
|
||||
result.Add("PzPalletProd", $"{rowResult.PzPalletProd}");
|
||||
result.Add("MatrOpr", $"{rowResult.MatrOpr}");
|
||||
result.Add("lastVal", $"{rowResult.LastVal}");
|
||||
result.Add("TCBase", $"{rowResult.TempoCicloBase}");
|
||||
|
||||
//...e SETUP
|
||||
result.Add("CodMacc", $"{rowResult.Codmacchina}");
|
||||
result.Add("IdxFamIn", $"{rowResult.IdxFamigliaIngresso}");
|
||||
result.Add("Multi", $"{rowResult.Multi}");
|
||||
result.Add("BitFilt", $"{rowResult.BitFilt}");
|
||||
result.Add("MaxVal", $"{rowResult.MaxVal}");
|
||||
result.Add("BSR", $"{rowResult.Bsr}");
|
||||
result.Add("ExplodeBit", $"{rowResult.ExplodeBit}");
|
||||
result.Add("NumBit", $"{rowResult.NumBit}");
|
||||
result.Add("IdxFamMacc", $"{rowResult.IdxFamiglia}");
|
||||
result.Add("simplePallet", $"{rowResult.SimplePallet}");
|
||||
result.Add("palletChange", $"{rowResult.PalletChange}");
|
||||
answ = ResetDatiMacchina(idxMacchina);
|
||||
}
|
||||
// cerco info Master/slave...
|
||||
var m2sTab = Macchine2SlaveGetAll();
|
||||
string isMaster = m2sTab.Where(x => x.IdxMacchina == idxMacc).Count() > 0 ? "1" : "0";
|
||||
string isSlave = m2sTab.Where(x => x.IdxMacchinaSlave == idxMacc).Count() > 0 ? "1" : "0";
|
||||
result.Add("Master", isMaster);
|
||||
result.Add("Slave", isSlave);
|
||||
|
||||
// serializzo
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
// durata cache secondo valore insEnabled...
|
||||
double numMinCache = (result["insEnabled"].ToLower() == "true") ? redisShortTimeCache / 4 : redisShortTimeCache;
|
||||
// ...e salvo...
|
||||
redisDb.StringSet(currKey, rawData, getRandTOut(numMinCache));
|
||||
}
|
||||
if (result == null)
|
||||
catch (Exception exc)
|
||||
{
|
||||
result = new Dictionary<string, string>();
|
||||
Log.Error($"Errore in compilazione dati Macchine x Redis - idxMacchina {idxMacchina}:{Environment.NewLine}{exc}");
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"GetCurrMSFDMacc | Read from {readType}: {ts.TotalMilliseconds}ms");
|
||||
return result;
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1594,26 +1586,111 @@ namespace MP.IOC.Data
|
||||
|
||||
public KeyValuePair<string, string>[] RedisGetHash(string redKey)
|
||||
{
|
||||
HashEntry[] rawData = redisDb.HashGetAll($"{redisBaseAddrSpec}:{redKey}");
|
||||
HashEntry[] rawData = redisDb.HashGetAll(redKey);
|
||||
var result = rawData.Where(x => !x.Name.IsNull).Select(x => new KeyValuePair<string, string>(x.Name, x.Value)).ToArray();
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<KeyValuePair<string, string>[]> RedisGetHashAsync(string redKey)
|
||||
{
|
||||
HashEntry[] rawData = await redisDb.HashGetAllAsync($"{redisBaseAddrSpec}:{redKey}");
|
||||
HashEntry[] rawData = await redisDb.HashGetAllAsync(redKey);
|
||||
var result = rawData.Where(x => !x.Name.IsNull).Select(x => new KeyValuePair<string, string>(x.Name, x.Value)).ToArray();
|
||||
return result;
|
||||
}
|
||||
|
||||
public Dictionary<string, string> RedisGetHashDict(string hashKey)
|
||||
{
|
||||
HashEntry[] rawData = redisDb.HashGetAll(hashKey);
|
||||
var result = rawData.Where(x => !x.Name.IsNull).ToDictionary(x => x.Name.ToString(), x => x.Value.ToString());
|
||||
return result;
|
||||
|
||||
//Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||||
//try
|
||||
//{
|
||||
// RedisKey key = hashKey;
|
||||
// HashEntry[] array = redisDb.HashGetAll(key);
|
||||
// HashEntry[] array2 = array;
|
||||
// for (int i = 0; i < array2.Length; i++)
|
||||
// {
|
||||
// HashEntry hashEntry = array2[i];
|
||||
// dictionary.Add(hashEntry.Name, hashEntry.Value);
|
||||
// }
|
||||
//}
|
||||
//catch
|
||||
//{ }
|
||||
|
||||
//return dictionary;
|
||||
}
|
||||
|
||||
public string RedisGetHashField(string hashKey, string hashField)
|
||||
{
|
||||
string result = "";
|
||||
try
|
||||
{
|
||||
RedisKey key = hashKey;
|
||||
RedisValue hashField2 = hashField;
|
||||
result = redisDb.HashGet(key, hashField2).ToString();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in RedisGetHashField{Environment.NewLine}{exc}");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool RedisHashPresent(RedisKey key)
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
result = redisDb.HashGetAll(key).Length != 0;
|
||||
}
|
||||
catch (Exception arg)
|
||||
{
|
||||
Log.Error($"Errore in redHashPresent per la key {key}{Environment.NewLine}{arg}");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool RedisHashPresentSz(string key)
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
RedisKey key2 = key;
|
||||
result = RedisHashPresent(key2);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool RedisKeyPresent(RedisKey key)
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
result = redisDb.KeyExists(key);
|
||||
}
|
||||
catch (Exception arg)
|
||||
{
|
||||
Log.Error($"Errore in redKeyPresent per la key {key}:{Environment.NewLine}{arg}");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool RedisSetHash(string redKey, KeyValuePair<string, string>[] valori, double expireSeconds = -1.0)
|
||||
{
|
||||
bool answ = false;
|
||||
string rKey = $"{redisBaseAddrSpec}:{redKey}";
|
||||
answ = RedisSetHash(redKey, valori);
|
||||
if (expireSeconds > 0.0)
|
||||
{
|
||||
redisDb.KeyExpire(rKey, DateTime.Now.AddSeconds(expireSeconds));
|
||||
redisDb.KeyExpire(redKey, DateTime.Now.AddSeconds(expireSeconds));
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
@@ -1621,9 +1698,28 @@ namespace MP.IOC.Data
|
||||
public bool RedisSetHash(string redKey, KeyValuePair<string, string>[] valori)
|
||||
{
|
||||
bool answ = false;
|
||||
string rKey = $"{redisBaseAddrSpec}:{redKey}";
|
||||
HashEntry[] redHash = valori.Select(x => new HashEntry(x.Key, x.Value)).ToArray();
|
||||
redisDb.HashSet(rKey, redHash);
|
||||
redisDb.HashSet(redKey, redHash);
|
||||
answ = true;
|
||||
return answ;
|
||||
}
|
||||
|
||||
public bool RedisSetHashDict(string redKey, Dictionary<string, string> valori, double expireSeconds = -1.0)
|
||||
{
|
||||
bool answ = false;
|
||||
answ = RedisSetHashDict(redKey, valori);
|
||||
if (expireSeconds > 0.0)
|
||||
{
|
||||
redisDb.KeyExpire(redKey, DateTime.Now.AddSeconds(expireSeconds));
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
public bool RedisSetHashDict(string redKey, Dictionary<string, string> valori)
|
||||
{
|
||||
bool answ = false;
|
||||
HashEntry[] redHash = valori.Select(x => new HashEntry(x.Key, x.Value)).ToArray();
|
||||
redisDb.HashSet(redKey, redHash);
|
||||
answ = true;
|
||||
return answ;
|
||||
}
|
||||
@@ -1631,11 +1727,80 @@ namespace MP.IOC.Data
|
||||
public async Task<bool> RedisSetKey(string redKey, string redVal)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
RedisValue pattern = new RedisValue($"{redisBaseAddrSpec}:{redKey}");
|
||||
RedisValue pattern = new RedisValue($"{redisBaseAddrIOC}{redKey}");
|
||||
bool answ = redisDb.StringSet(redKey, redVal);
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restitusice elenco KVP dei campi DatiMacchine + StatoMacchine per l'impianto indicato
|
||||
/// </summary>
|
||||
/// <param name="idxMacc"></param>
|
||||
/// <returns></returns>
|
||||
public Dictionary<string, string> ResetDatiMacchina(string idxMacc)
|
||||
{
|
||||
string currHash = dtMaccHash(idxMacc);
|
||||
// inizio con un bel reset...
|
||||
RedisFlushPattern(currHash);
|
||||
Dictionary<string, string>? result = new Dictionary<string, string>();
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
var dbResults = dbController.VMSFDGetByMacc(idxMacc);
|
||||
// converto in formato dizionario...
|
||||
if (dbResults != null && dbResults.Count > 0)
|
||||
{
|
||||
var rowResult = dbResults[0];
|
||||
// salvo 1:1 i valori... STATO
|
||||
result.Add("IdxMicroStato", $"{rowResult.IdxMicroStato}");
|
||||
result.Add("IdxStato", $"{rowResult.IdxStato}");
|
||||
result.Add("CodArticolo", $"{rowResult.CodArticolo}");
|
||||
result.Add("insEnabled", $"{rowResult.InsEnabled}");
|
||||
result.Add("sLogEnabled", $"{rowResult.SLogEnabled}");
|
||||
result.Add("pallet", $"{rowResult.Pallet}");
|
||||
result.Add("CodArticolo_A", $"{rowResult.CodArticoloA}");
|
||||
result.Add("CodArticolo_B", $"{rowResult.CodArticoloB}");
|
||||
result.Add("TempoCicloBase", $"{rowResult.TempoCicloBase}");
|
||||
result.Add("PzPalletProd", $"{rowResult.PzPalletProd}");
|
||||
result.Add("MatrOpr", $"{rowResult.MatrOpr}");
|
||||
result.Add("lastVal", $"{rowResult.LastVal}");
|
||||
result.Add("TCBase", $"{rowResult.TempoCicloBase}");
|
||||
|
||||
//...e SETUP
|
||||
result.Add("CodMacc", $"{rowResult.Codmacchina}");
|
||||
result.Add("IdxFamIn", $"{rowResult.IdxFamigliaIngresso}");
|
||||
result.Add("Multi", $"{rowResult.Multi}");
|
||||
result.Add("BitFilt", $"{rowResult.BitFilt}");
|
||||
result.Add("MaxVal", $"{rowResult.MaxVal}");
|
||||
result.Add("BSR", $"{rowResult.Bsr}");
|
||||
result.Add("ExplodeBit", $"{rowResult.ExplodeBit}");
|
||||
result.Add("NumBit", $"{rowResult.NumBit}");
|
||||
result.Add("IdxFamMacc", $"{rowResult.IdxFamiglia}");
|
||||
result.Add("simplePallet", $"{rowResult.SimplePallet}");
|
||||
result.Add("palletChange", $"{rowResult.PalletChange}");
|
||||
}
|
||||
// cerco info Master/slave...
|
||||
var m2sTab = Macchine2SlaveGetAll();
|
||||
string isMaster = m2sTab.Where(x => x.IdxMacchina == idxMacc).Count() > 0 ? "1" : "0";
|
||||
string isSlave = m2sTab.Where(x => x.IdxMacchinaSlave == idxMacc).Count() > 0 ? "1" : "0";
|
||||
result.Add("Master", isMaster);
|
||||
result.Add("Slave", isSlave);
|
||||
|
||||
// durata cache in secondi dal valore insEnabled...
|
||||
double numSecCache = 60 * ((result["insEnabled"].ToLower() == "true") ? redisShortTimeCache / 4 : redisShortTimeCache);
|
||||
// ...e salvo...
|
||||
RedisSetHashDict(currHash, result, numSecCache);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
result = new Dictionary<string, string>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"GetCurrMSFDMacc | Read from {readType}: {ts.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resetta (rileggendo) i dati della State Machine ingressi nel formato
|
||||
/// key: cState_nVal (current MICRO-STATE + "_" + new Value)
|
||||
@@ -1645,7 +1810,7 @@ namespace MP.IOC.Data
|
||||
/// <returns></returns>
|
||||
public KeyValuePair<string, string>[] resetSMI(int idxFamIn)
|
||||
{
|
||||
string currHash = $"{redisBaseAddrSpec}:hSMI:{idxFamIn}";
|
||||
string currHash = hSMI(idxFamIn);
|
||||
// leggo da DB...
|
||||
var tabSMI = dbController.StateMachineIngressi(idxFamIn);
|
||||
|
||||
@@ -1689,7 +1854,7 @@ namespace MP.IOC.Data
|
||||
// ORA recupero da memoria redis...
|
||||
try
|
||||
{
|
||||
string currHash = $"{redisBaseAddrSpec}:hSMI:{idxFamIn}";
|
||||
string currHash = hSMI(idxFamIn);
|
||||
answ = RedisGetHash(currHash);
|
||||
// se è vuoto... leggo da DB e popolo!
|
||||
if (answ.Length == 0)
|
||||
@@ -1821,6 +1986,21 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il valore SPECIFICATO per la state machine ingressi
|
||||
/// value: iTipoEv_nState (IdxTipoEv da trasmettere + New MICRO-STATE)
|
||||
/// </summary>
|
||||
/// <param name="idxFamIn"></param>
|
||||
/// <param name="idxMicroStato"></param>
|
||||
/// <param name="valoreIn"></param>
|
||||
/// <returns></returns>
|
||||
public string ValoreSMI(int idxFamIn, int idxMicroStato, int valoreIn)
|
||||
{
|
||||
string currHash = hSMI(idxFamIn);
|
||||
string field = $"{idxMicroStato}_{valoreIn}";
|
||||
return RedisGetHashField(currHash, field);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco completo tabella Vocabolario
|
||||
/// </summary>
|
||||
@@ -1886,42 +2066,42 @@ namespace MP.IOC.Data
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private const string redisActionReq = redisBaseAddr + "IO:Action:Req";
|
||||
private const string redisAnagGruppi = redisBaseAddrSpec + "Cache:AnagGruppi";
|
||||
private const string redisActionReq = redisBaseAddrIOC + "Action:Req";
|
||||
private const string redisAnagGruppi = redisBaseAddrIOC + "Cache:AnagGruppi";
|
||||
|
||||
private const string redisArtByDossier = redisBaseAddrSpec + "Cache:ArtByDossier";
|
||||
private const string redisArtByDossier = redisBaseAddrIOC + "Cache:ArtByDossier";
|
||||
|
||||
private const string redisArtList = redisBaseAddrSpec + "Cache:ArtList";
|
||||
private const string redisArtList = redisBaseAddrIOC + "Cache:ArtList";
|
||||
|
||||
private const string redisBaseAddr = "MP:";
|
||||
private const string redisBaseAddrSpec = redisBaseAddr + "SPEC:";
|
||||
private const string redisBaseAddrIOC = redisBaseAddr + "IOC:";
|
||||
|
||||
private const string redisConfKey = redisBaseAddrSpec + "Cache:Config";
|
||||
private const string redisConfKey = redisBaseAddrIOC + "Cache:Config";
|
||||
|
||||
private const string redisDossByMac = redisBaseAddrSpec + "Cache:DossByMac";
|
||||
private const string redisDossByMac = redisBaseAddrIOC + "Cache:DossByMac";
|
||||
|
||||
private const string redisFluxByMac = redisBaseAddrSpec + "Cache:FluxByMac";
|
||||
private const string redisFluxByMac = redisBaseAddrIOC + "Cache:FluxByMac";
|
||||
|
||||
private const string redisFluxLogFilt = redisBaseAddrSpec + "Cache:FluxLogFilt";
|
||||
private const string redisFluxLogFilt = redisBaseAddrIOC + "Cache:FluxLogFilt";
|
||||
|
||||
private const string redisGiacenzaList = redisBaseAddrSpec + "Cache:GiacenzaList";
|
||||
private const string redisMacByFlux = redisBaseAddrSpec + "Cache:MacByFlux";
|
||||
private const string redisGiacenzaList = redisBaseAddrIOC + "Cache:GiacenzaList";
|
||||
private const string redisMacByFlux = redisBaseAddrIOC + "Cache:MacByFlux";
|
||||
|
||||
private const string redisMacList = redisBaseAddrSpec + "Cache:MacList";
|
||||
private const string redisMacRecipe = redisBaseAddrSpec + "Cache:Recipe";
|
||||
private const string redisMacList = redisBaseAddrIOC + "Cache:MacList";
|
||||
private const string redisMacRecipe = redisBaseAddrIOC + "Cache:Recipe";
|
||||
|
||||
private const string redisOdlByBatch = redisXdlData + "OdlByBatch";
|
||||
private const string redisOdlCurrByMac = redisXdlData + "OdlByMac";
|
||||
private const string redisOdlList = redisXdlData + "OdlList";
|
||||
private const string redisParamPageExp = redisBaseAddrSpec + "Cache:ParamPage";
|
||||
private const string redisParamPageExp = redisBaseAddrIOC + "Cache:ParamPage";
|
||||
private const string redisPOdlByOdl = redisXdlData + "POdlByOdl";
|
||||
private const string redisPOdlByPOdl = redisXdlData + "POdlByPOdl";
|
||||
private const string redisPOdlList = redisXdlData + "POdlList";
|
||||
private const string redisRecipeConf = redisBaseAddrSpec + "Cache:Recipe:Conf";
|
||||
private const string redisStatoCom = redisBaseAddrSpec + "Cache:StatoCom";
|
||||
private const string redisTipoArt = redisBaseAddrSpec + "Cache:TipoArt";
|
||||
private const string redisVocabolario = redisBaseAddrSpec + "Cache:Vocabolario";
|
||||
private const string redisXdlData = redisBaseAddrSpec + "Cache:XDL:";
|
||||
private const string redisRecipeConf = redisBaseAddrIOC + "Cache:Recipe:Conf";
|
||||
private const string redisStatoCom = redisBaseAddrIOC + "Cache:StatoCom";
|
||||
private const string redisTipoArt = redisBaseAddrIOC + "Cache:TipoArt";
|
||||
private const string redisVocabolario = redisBaseAddrIOC + "Cache:Vocabolario";
|
||||
private const string redisXdlData = redisBaseAddrIOC + "Cache:XDL:";
|
||||
private static IConfiguration _configuration = null!;
|
||||
private static ILogger<MpDataService> _logger = null!;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MP-IOC </i>
|
||||
<h4>Versione: 6.16.2302.1513</h4>
|
||||
<h4>Versione: 6.16.2302.1516</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
6.16.2302.1513
|
||||
6.16.2302.1516
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>6.16.2302.1513</version>
|
||||
<version>6.16.2302.1516</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
Reference in New Issue
Block a user