diff --git a/MP.Core/Utils.cs b/MP.Core/Utils.cs
index e7a050cb..f45e4f7f 100644
--- a/MP.Core/Utils.cs
+++ b/MP.Core/Utils.cs
@@ -150,9 +150,9 @@ namespace MP.Core
///
///
///
- public static RedisKey hSMI(int idxFamIn)
+ public static RedisKey GetHashSMI(int idxFamIn)
{
- return (RedisKey)$"{redisBaseAddr}hSMI:{idxFamIn}";
+ return (RedisKey)$"{redisBaseAddr}GetHashSMI:{idxFamIn}";
}
///
@@ -174,7 +174,7 @@ namespace MP.Core
///
/// Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)
///
- public static RedisKey msmiHash(string idxMacchina, string baseAddr = null)
+ public static RedisKey RedKeyMsmi(string idxMacchina, string baseAddr = null)
{
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
return (RedisKey)$"{prefix}:hMSMI:{idxMacchina}";
@@ -206,7 +206,7 @@ namespace MP.Core
///
/// Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)
///
- public static RedisKey redisPzCount(string idxMacchina, string baseAddr = null)
+ public static RedisKey RedKeyPzCount(string idxMacchina, string baseAddr = null)
{
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
return (RedisKey)$"{prefix}:Cache:PzCount:{idxMacchina}";
@@ -234,12 +234,24 @@ namespace MP.Core
///
/// Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)
///
- public static RedisKey taskMaccHash(string idxMacchina, string baseAddr = null)
+ public static RedisKey RedKeyTask2ExeMacc(string idxMacchina, string baseAddr = null)
{
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
return (RedisKey)$"{prefix}:ExeTask:{idxMacchina}";
}
+ ///
+ /// Chiave x CurrObjItems macchina
+ ///
+ ///
+ /// Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)
+ ///
+ public static RedisKey RedKeyCurrObjItems(string idxMacchina, string baseAddr = null)
+ {
+ var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
+ return (RedisKey)$"{prefix}:CurrentParameters:{idxMacchina}";
+ }
+
#endregion Public Methods
}
}
\ No newline at end of file
diff --git a/MP.IOC/Controllers/BenchController.cs b/MP.IOC/Controllers/BenchController.cs
index cf12f332..b12d7cd8 100644
--- a/MP.IOC/Controllers/BenchController.cs
+++ b/MP.IOC/Controllers/BenchController.cs
@@ -121,7 +121,7 @@ namespace MP.IOC.Controllers
answ = "";
try
{
- var fiHASH = Utils.hSMI(idxFamIn);
+ var fiHASH = Utils.GetHashSMI(idxFamIn);
string outVal = "";
bool trovato = DService.RedisHashPresent(fiHASH);
if (!trovato)
diff --git a/MP.IOC/Controllers/IOBController.cs b/MP.IOC/Controllers/IOBController.cs
index 4dd52ff3..17791532 100644
--- a/MP.IOC/Controllers/IOBController.cs
+++ b/MP.IOC/Controllers/IOBController.cs
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
+using MP.Core.DTO;
using MP.IOC.Data;
using Newtonsoft.Json;
using NLog;
@@ -121,6 +122,29 @@ namespace MP.IOC.Controllers
}
}
+ ///
+ /// GET elenco parametri correnti x IOB
+ ///
+ ///
+ ///
+ [HttpGet("getCurrObjItems/{id}")]
+ public async Task GetCurrObjItems(string id)
+ {
+ if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
+
+ // Multi: gestione carattere "|" trasformato in "#"
+ id = id.Replace("|", "#");
+
+ var rawData = await DService.MachineParamListAsync(id);
+ List actValues = new List();
+ // ordino!
+ actValues = rawData
+ .OrderBy(x => x.displOrdinal)
+ .ThenBy(x => x.description)
+ .ToList();
+ return Ok(actValues);
+ }
+
///
/// Recupera ODL corrente x macchina:
/// GET: IOB/getCurrODL/SIMUL_03
@@ -320,6 +344,43 @@ namespace MP.IOC.Controllers
return Ok(answ);
}
+ ///
+ /// Processa una chiamata POST per l'invio di una List Json di UNO O PIU' oggetti objItem
+ /// POST: IOB/upsertObjItems/SIMUL_03
+ ///
+ /// ID dell'IOB
+ ///
+ [HttpPost("upsertObjItems/{id}")]
+ public async Task UpsertObjItems(string id, [FromBody] List innovazioni)
+ {
+ if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
+
+ // Multi: gestione carattere "|" trasformato in "#"
+ id = id.Replace("|", "#");
+ string answ = "NA";
+
+ try
+ {
+ // se != null --> salvo!
+ if (innovazioni != null)
+ {
+ // salvo
+ bool fatto = await DService.MachineParamUpsertAsync(id, innovazioni);
+ answ = "OK";
+ }
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Errore in upsertObjItems{Environment.NewLine}{exc}");
+ return StatusCode(StatusCodes.Status500InternalServerError, "NO");
+ }
+ return Ok(answ);
+ }
+
+ ///
+ /// Verifica versione corrente REST API
+ ///
+ ///
[HttpGet("version")]
public IActionResult Version()
{
diff --git a/MP.IOC/Data/MpDataService.cs b/MP.IOC/Data/MpDataService.cs
index 2fa8d250..a22d96d8 100644
--- a/MP.IOC/Data/MpDataService.cs
+++ b/MP.IOC/Data/MpDataService.cs
@@ -426,7 +426,7 @@ namespace MP.IOC.Data
int valIOB = Convert.ToInt32(valINT);
next_idxMS = idxMicroStato;
// verifico esistenza tab SMI...
- var fiHASH = Utils.hSMI(idxFamIn);
+ var fiHASH = Utils.GetHashSMI(idxFamIn);
bool trovato = RedisHashPresent(fiHASH);
if (!trovato)
{
@@ -992,7 +992,7 @@ namespace MP.IOC.Data
// ORA recupero da memoria redis...
try
{
- var currHash = Utils.taskMaccHash(idxMacchina, MpIoNS);
+ var currHash = Utils.RedKeyTask2ExeMacc(idxMacchina, MpIoNS);
answ = await RedisGetHashDictAsync(currHash);
}
catch (Exception exc)
@@ -1239,6 +1239,160 @@ namespace MP.IOC.Data
return result;
}
+
+ ///
+ /// Lista parametri correnti (ObjItemDTO) della macchina
+ ///
+ ///
+ ///
+ public List MachineParamList(string idxMacchina)
+ {
+ // setup parametri costanti
+ string source = "NA";
+ Stopwatch sw = new Stopwatch();
+ sw.Start();
+ List? result = new List();
+ // cerco in _redisConn...
+ var currKey = Utils.RedKeyCurrObjItems(idxMacchina, MpIoNS);
+ RedisValue rawData = redisDb.StringGet(currKey);
+ if (rawData.HasValue && rawData.Length() > 2)
+ {
+ var rawVal = JsonConvert.DeserializeObject>($"{rawData}");
+ // ordino!
+ result = rawVal
+ .OrderBy(x => x.displOrdinal)
+ .ThenBy(x => x.description)
+ .ToList();
+ source = "REDIS";
+ }
+ if (result == null)
+ {
+ result = new List();
+ source = "NONE";
+ }
+ sw.Stop();
+ Log.Debug($"MachineParamList | {source} | {sw.Elapsed.TotalMilliseconds}ms");
+ return result;
+ }
+ ///
+ /// Lista parametri correnti (ObjItemDTO) della macchina
+ ///
+ ///
+ ///
+ public async Task> MachineParamListAsync(string idxMacchina)
+ {
+ // setup parametri costanti
+ string source = "NA";
+ Stopwatch sw = new Stopwatch();
+ sw.Start();
+ List? result = new List();
+ // cerco in _redisConn...
+ var currKey = Utils.RedKeyCurrObjItems(idxMacchina, MpIoNS);
+ RedisValue rawData = await redisDb.StringGetAsync(currKey);
+ if (rawData.HasValue && rawData.Length() > 2)
+ {
+ var rawVal = JsonConvert.DeserializeObject>($"{rawData}");
+ // ordino!
+ result = rawVal
+ .OrderBy(x => x.displOrdinal)
+ .ThenBy(x => x.description)
+ .ToList();
+ source = "REDIS";
+ }
+ if (result == null)
+ {
+ result = new List();
+ source = "NONE";
+ }
+ sw.Stop();
+ Log.Debug($"MachineParamListAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms");
+ return result;
+ }
+
+ ///
+ /// Effettua UPSERT elenco parametri correnti x IOB (se c'è UPDATE, se manca ADD)
+ ///
+ ///
+ ///
+ ///
+ public bool MachineParamUpsert(string idxMacchina, List innovations)
+ {
+ bool answ = false;
+ if (innovations != null)
+ {
+ Log.Info($"upsertCurrObjItems | idxMacchina: {idxMacchina} | {innovations.Count} innovations");
+ // leggo i valori attuali...
+ List actValues = MachineParamList(idxMacchina);
+ // per ogni valore passatomi faccio insert o update rispetto elenco valori correnti
+ // in REDIS
+ foreach (var item in actValues)
+ {
+ // cerco nelle innovazioni SE CI SIA il valore...
+ var trovato = innovations.Find(obj => obj.uid == item.uid);
+ // se non trovato nelle innovazioni...
+ if (trovato == null)
+ {
+ // lo ri-aggiungo x non perderlo
+ innovations.Add(item);
+ Log.Trace($"innovations | add | item.uid: {item.uid} | item.value: {item.value}");
+ }
+ // altrimenti aggiorno campo (non trasmesso) name e tengo il resto...
+ else
+ {
+ trovato.name = item.name;
+ Log.Info($"innovations | update | item.uid: {item.uid} | item.value: {item.value} --> {trovato.value} ");
+ }
+ }
+ // serializzo e salvo
+ string serVal = JsonConvert.SerializeObject(innovations);
+ var currKey = Utils.RedKeyCurrObjItems(idxMacchina, MpIoNS);
+ RedisValue rawData = redisDb.StringSet(currKey, serVal);
+ }
+ return answ;
+ }
+
+ ///
+ /// Effettua UPSERT elenco parametri correnti x IOB (se c'è UPDATE, se manca ADD)
+ ///
+ ///
+ ///
+ ///
+ public async Task MachineParamUpsertAsync(string idxMacchina, List innovations)
+ {
+ bool answ = false;
+ if (innovations != null)
+ {
+ Log.Info($"upsertCurrObjItems | idxMacchina: {idxMacchina} | {innovations.Count} innovations");
+ // leggo i valori attuali...
+ List actValues = await MachineParamListAsync(idxMacchina);
+ // per ogni valore passatomi faccio insert o update rispetto elenco valori correnti
+ // in REDIS
+ foreach (var item in actValues)
+ {
+ // cerco nelle innovazioni SE CI SIA il valore...
+ var trovato = innovations.Find(obj => obj.uid == item.uid);
+ // se non trovato nelle innovazioni...
+ if (trovato == null)
+ {
+ // lo ri-aggiungo x non perderlo
+ innovations.Add(item);
+ Log.Trace($"innovations | add | item.uid: {item.uid} | item.value: {item.value}");
+ }
+ // altrimenti aggiorno campo (non trasmesso) name e tengo il resto...
+ else
+ {
+ trovato.name = item.name;
+ Log.Info($"innovations | update | item.uid: {item.uid} | item.value: {item.value} --> {trovato.value} ");
+ }
+ }
+ // serializzo e salvo
+ string serVal = JsonConvert.SerializeObject(innovations);
+ var currKey = Utils.RedKeyCurrObjItems(idxMacchina, MpIoNS);
+ RedisValue rawData = await redisDb.StringSetAsync(currKey, serVal);
+ }
+ return answ;
+ }
+
///
/// Restituisce valore di una singola chiave del dizionario DatiMacchina
///
@@ -1321,7 +1475,7 @@ namespace MP.IOC.Data
// ORA recupero da memoria redis...
try
{
- var currHash = Utils.msmiHash(idxMacchina);
+ var currHash = Utils.RedKeyMsmi(idxMacchina);
answ = RedisGetHash(currHash);
// se è vuoto... leggo da DB e popolo!
if (answ.Length == 0)
@@ -1348,7 +1502,7 @@ namespace MP.IOC.Data
// ORA recupero da memoria redis...
try
{
- var currHash = Utils.taskMaccHash(idxMacchina, MpIoNS);
+ var currHash = Utils.RedKeyTask2ExeMacc(idxMacchina, MpIoNS);
answ = RedisGetHashDict(currHash);
}
catch (Exception exc)
@@ -1963,7 +2117,7 @@ namespace MP.IOC.Data
int answ = -1;
try
{
- var currKey = Utils.redisPzCount(idxMacchina, MpIoNS);
+ var currKey = Utils.RedKeyPzCount(idxMacchina, MpIoNS);
RedisValue rawData = await redisDb.StringGetAsync(currKey);
if (rawData.HasValue)
{
@@ -2297,7 +2451,7 @@ namespace MP.IOC.Data
///
public KeyValuePair[] resetMSMI(string idxMacchina)
{
- var currHash = Utils.msmiHash(idxMacchina);
+ var currHash = Utils.RedKeyMsmi(idxMacchina);
//answ = RedisGetHash(currHash);
// recupero records
var tabMSMI = IocDbController.VMSFDGetMultiByMacc(idxMacchina);
@@ -2456,7 +2610,7 @@ namespace MP.IOC.Data
// se il conteggio è >= 0 SALVO come nuovo conteggio...
if (newCounter >= 0)
{
- var currKey = Utils.redisPzCount(idxMacchina, MpIoNS);
+ var currKey = Utils.RedKeyPzCount(idxMacchina, MpIoNS);
RedisValue rawData = redisDb.StringGet(currKey);
if (!rawData.HasValue)
{
@@ -2508,7 +2662,7 @@ namespace MP.IOC.Data
// se il conteggio è >= 0 SALVO come nuovo conteggio...
if (newCounter >= 0)
{
- var currKey = Utils.redisPzCount(idxMacchina, MpIoNS);
+ var currKey = Utils.RedKeyPzCount(idxMacchina, MpIoNS);
RedisValue rawData = await redisDb.StringGetAsync(currKey);
if (!rawData.HasValue)
{
@@ -2614,7 +2768,7 @@ namespace MP.IOC.Data
// ORA recupero da memoria redis...
try
{
- var currHash = Utils.hSMI(idxFamIn);
+ var currHash = Utils.GetHashSMI(idxFamIn);
answ = RedisGetHash(currHash);
// se è vuoto... leggo da DB e popolo!
if (answ.Length == 0)
@@ -2737,7 +2891,7 @@ namespace MP.IOC.Data
///
public string ValoreSMI(int idxFamIn, int idxMicroStato, int valoreIn)
{
- var currHash = Utils.hSMI(idxFamIn);
+ var currHash = Utils.GetHashSMI(idxFamIn);
string field = $"{idxMicroStato}_{valoreIn}";
return RedisGetHashField(currHash, field);
}
@@ -3098,7 +3252,7 @@ namespace MP.IOC.Data
///
private KeyValuePair[] resetSMI(int idxFamIn)
{
- var currHash = Utils.hSMI(idxFamIn);
+ var currHash = Utils.GetHashSMI(idxFamIn);
// leggo da DB...
var tabSMI = IocDbController.StateMachineIngressi(idxFamIn);
@@ -3270,7 +3424,7 @@ namespace MP.IOC.Data
///
private string valoreSMI(int idxFamIn, int idxMicroStato, int valoreIn)
{
- var currHash = Utils.hSMI(idxFamIn);
+ var currHash = Utils.GetHashSMI(idxFamIn);
string field = string.Format("{0}_{1}", idxMicroStato, valoreIn);
return RedisGetHashField(currHash, field);
}
diff --git a/MP.IOC/MP.IOC.csproj b/MP.IOC/MP.IOC.csproj
index 3fb4df1a..4677cd5a 100644
--- a/MP.IOC/MP.IOC.csproj
+++ b/MP.IOC/MP.IOC.csproj
@@ -4,7 +4,7 @@
net8.0
enable
enable
- 6.16.2604.1316
+ 6.16.2604.1317
diff --git a/MP.IOC/Resources/ChangeLog.html b/MP.IOC/Resources/ChangeLog.html
index 30c3867d..c7d8e9f9 100644
--- a/MP.IOC/Resources/ChangeLog.html
+++ b/MP.IOC/Resources/ChangeLog.html
@@ -1,6 +1,6 @@
Modulo MP-IOC
- Versione: 6.16.2604.1316
+ Versione: 6.16.2604.1317
Note di rilascio:
-
diff --git a/MP.IOC/Resources/VersNum.txt b/MP.IOC/Resources/VersNum.txt
index 3cb935d6..762a3aac 100644
--- a/MP.IOC/Resources/VersNum.txt
+++ b/MP.IOC/Resources/VersNum.txt
@@ -1 +1 @@
-6.16.2604.1316
+6.16.2604.1317
diff --git a/MP.IOC/Resources/manifest.xml b/MP.IOC/Resources/manifest.xml
index e2a937a8..4dc8e9e3 100644
--- a/MP.IOC/Resources/manifest.xml
+++ b/MP.IOC/Resources/manifest.xml
@@ -1,6 +1,6 @@
-
- 6.16.2604.1316
+ 6.16.2604.1317
https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/MP.IOC.zip
https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/ChangeLog.html
false