diff --git a/MP.IOC/Controllers/BenchController.cs b/MP.IOC/Controllers/BenchController.cs
index 7cf9bc80..1cba0a0a 100644
--- a/MP.IOC/Controllers/BenchController.cs
+++ b/MP.IOC/Controllers/BenchController.cs
@@ -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();
///
- /// Dataservice x accesso DB
+ /// Conteggio chiavi REDIS dato pattern api/Bench/CountKeys
///
- protected MpDataService DService { get; set; }
-
- //// GET: IOB (è un check alive)
- //public string Index()
- //{
- // return "OK";
- //}
+ ///
+ ///
+ [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;
+ }
///
- /// pulizia dati
- /// api/Bench/RClean?id=100
+ /// Bench recupero dati macchina api/Bench/DtMac?id=SIMUL_01
+ ///
+ ///
+ ///
+ [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 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;
+ }
+
+ /// Recupera riga traduzione microstato x processing da HASH table
+ /// api/Bench/FindSMI?id=60&idxMS=3&valore=1
+ [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[] valori = DService.StateMachInByKey(idxFamIn);
+ answ = string.Format("Ricaricata SMI per famiglia {0}
", 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;
+ }
+
+ ///
+ /// Test verifica insert enabled x macchina
+ ///
+ ///
+ ///
+ [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;
+ }
+
+ ///
+ /// pulizia dati api/Bench/RClean?id=100
///
///
///
[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";
+ //}
///
- /// Setup dati di test hash
- /// api/Bench/RSetup?id=100
+ /// Setup dati di test hash api/Bench/RSetup?id=100
///
///
///
[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;
}
+
///
- /// Recupero singolo valore hash
- /// api/Bench/RSingleHash?id=50
+ /// Recupero singolo valore hash api/Bench/RSingleHash?id=50
///
///
///
[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;
}
- ///
- /// Bench recupero dati macchina
- /// api/Bench/DtMac?id=SIMUL_01
- ///
- ///
- ///
- [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 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;
- }
- ///
- /// Conteggio chiavi REDIS dato pattern
- /// api/Bench/CountKeys
- ///
- ///
- ///
- [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;
- }
+
///
/// Lettura tab StateMachineIngressi
///
///
///
[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[] valori = DataLayerObj.mTabSMI(idxFamIn);
- // answ = string.Format("Ricaricata SMI per famiglia {0}
", fiHASH);
- // }
- // answ += string.Format("Trovata {0} Hash per {1}
", 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}
", idxFamIn, idxMicroStato, valIOB, outVal);
- // }
- // catch
- // { }
- // }
- // stopWatch.Stop();
- // // Get the elapsed time as a TimeSpan value.
- // TimeSpan ts = stopWatch.Elapsed;
- // // accodo tempo!
- // answ += string.Format("
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}
", id, DataLayerObj.insEnab(id));
- // }
- // catch
- // { }
- // }
- // stopWatch.Stop();
- // // Get the elapsed time as a TimeSpan value.
- // TimeSpan ts = stopWatch.Elapsed;
- // // accodo tempo!
- // answ += string.Format("
Total Time Elapsed: {0}ms", ts.TotalMilliseconds);
- // // ritorno
- // return answ;
- //}
+
+ #endregion Public Methods
+
+ #region Protected Properties
+
+ ///
+ /// Dataservice x accesso DB
+ ///
+ 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
}
-}
+}
\ No newline at end of file
diff --git a/MP.IOC/Data/MpDataService.cs b/MP.IOC/Data/MpDataService.cs
index ac1a148f..e549da18 100644
--- a/MP.IOC/Data/MpDataService.cs
+++ b/MP.IOC/Data/MpDataService.cs
@@ -73,6 +73,16 @@ namespace MP.IOC.Data
#region Public Methods
+ ///
+ /// Hash dati STATUS x la macchina specificata
+ ///
+ ///
+ ///
+ public static string dtMaccHash(string idxMacchina)
+ {
+ return $"{redisBaseAddrIOC}DtMac:{idxMacchina}";
+ }
+
///
/// Recupera eventuali azioni richieste
///
@@ -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 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 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}";
+ }
+
///
/// Init ricetta
///
@@ -743,6 +758,17 @@ namespace MP.IOC.Data
return mongoController.InitRecipe(confPath, idxPODL, CalcArgs);
}
+ ///
+ /// Restituisce il valore booleano se la macchina sia abilitata all'input
+ ///
+ ///
+ ///
+ public bool IobInsEnab(string idxMacchina)
+ {
+ bool answ = Convert.ToBoolean(mDatiMacchinaVal(idxMacchina, "insEnabled"));
+ return answ;
+ }
+
///
///
/// id odl da cercare
@@ -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;
}
+ ///
+ /// Restituisce valore di una singola chiave del dizionario DatiMacchina
+ ///
+ ///
+ ///
+ ///
+ public string mDatiMacchinaVal(string idxMacchina, string chiave)
+ {
+ string answ = "";
+ try
+ {
+ answ = mDatiMacchine(idxMacchina)[chiave];
+ }
+ catch { }
+ return answ;
+ }
+
///
/// Restitusice elenco KVP dei campi DatiMacchine + StatoMacchine per l'impianto indicato
///
- ///
+ ///
///
- public Dictionary MSFDMaccGetCurr(string idxMacc)
+ public Dictionary mDatiMacchine(string idxMacchina)
{
- Dictionary? result = new Dictionary();
- 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 answ = new Dictionary();
+ // ORA recupero da memoria redis...
+ try
{
- result = JsonConvert.DeserializeObject>($"{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();
+ 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;
}
///
@@ -1594,26 +1586,111 @@ namespace MP.IOC.Data
public KeyValuePair[] 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(x.Name, x.Value)).ToArray();
return result;
}
public async Task[]> 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(x.Name, x.Value)).ToArray();
return result;
}
+ public Dictionary 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 dictionary = new Dictionary();
+ //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[] 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[] 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 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 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 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;
}
+ ///
+ /// Restitusice elenco KVP dei campi DatiMacchine + StatoMacchine per l'impianto indicato
+ ///
+ ///
+ ///
+ public Dictionary ResetDatiMacchina(string idxMacc)
+ {
+ string currHash = dtMaccHash(idxMacc);
+ // inizio con un bel reset...
+ RedisFlushPattern(currHash);
+ Dictionary? result = new Dictionary();
+ 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();
+ }
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"GetCurrMSFDMacc | Read from {readType}: {ts.TotalMilliseconds}ms");
+ return result;
+ }
+
///
/// 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
///
public KeyValuePair[] 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;
}
+ ///
+ /// Restituisce il valore SPECIFICATO per la state machine ingressi
+ /// value: iTipoEv_nState (IdxTipoEv da trasmettere + New MICRO-STATE)
+ ///
+ ///
+ ///
+ ///
+ ///
+ public string ValoreSMI(int idxFamIn, int idxMicroStato, int valoreIn)
+ {
+ string currHash = hSMI(idxFamIn);
+ string field = $"{idxMicroStato}_{valoreIn}";
+ return RedisGetHashField(currHash, field);
+ }
+
///
/// Elenco completo tabella Vocabolario
///
@@ -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 _logger = null!;
diff --git a/MP.IOC/Resources/ChangeLog.html b/MP.IOC/Resources/ChangeLog.html
index 36f3e633..915f447b 100644
--- a/MP.IOC/Resources/ChangeLog.html
+++ b/MP.IOC/Resources/ChangeLog.html
@@ -1,6 +1,6 @@
Modulo MP-IOC
- Versione: 6.16.2302.1513
+ Versione: 6.16.2302.1516
Note di rilascio:
-
diff --git a/MP.IOC/Resources/VersNum.txt b/MP.IOC/Resources/VersNum.txt
index c3581cf7..984cd353 100644
--- a/MP.IOC/Resources/VersNum.txt
+++ b/MP.IOC/Resources/VersNum.txt
@@ -1 +1 @@
-6.16.2302.1513
+6.16.2302.1516
diff --git a/MP.IOC/Resources/manifest.xml b/MP.IOC/Resources/manifest.xml
index 74a91bbc..9dc7ea48 100644
--- a/MP.IOC/Resources/manifest.xml
+++ b/MP.IOC/Resources/manifest.xml
@@ -1,6 +1,6 @@
-
- 6.16.2302.1513
+ 6.16.2302.1516
https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip
https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html
false