diff --git a/MP.Core/Utils.cs b/MP.Core/Utils.cs
index 93ac5f42..9f7c6efa 100644
--- a/MP.Core/Utils.cs
+++ b/MP.Core/Utils.cs
@@ -118,7 +118,6 @@ namespace MP.Core
return answ;
}
-
public static string FormDurata(double durataMinuti)
{
string answ = "";
@@ -157,18 +156,6 @@ namespace MP.Core
return endRounded;
}
- ///
- /// Hash dati Macchine Multi SM Ingressi
- ///
- ///
- /// 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 RedKeyMsmi(string idxMacchina, string baseAddr = null)
- {
- var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
- return (RedisKey)$"{prefix}:hMSMI:{idxMacchina}";
- }
-
///
/// Nome della variabile HASH da utilizzare (dato CodModulo / Server / DB impiegato
/// dafunzionalita' DbConfig) + idxMacchina richiesto...
@@ -190,32 +177,17 @@ namespace MP.Core
}
///
- /// Hash dati countapezzi macchina
+ /// 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 RedKeyPzCount(string idxMacchina, string baseAddr = null)
+ public static RedisKey RedKeyCurrObjItems(string idxMacchina, string baseAddr = null)
{
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
- return (RedisKey)$"{prefix}:Cache:PzCount:{idxMacchina}";
+ return (RedisKey)$"{prefix}:CurrentParameters:{idxMacchina}";
}
- ///
- /// Formato RedisKey delal chaive richeista (completa)
- ///
- public static RedisKey RedKeyHash(string keyName)
- {
- return (RedisKey)$"{redisBaseAddr}{keyName}";
- }
-
- ///
- /// Formato RedisValue delal chaive richeista (completa)
- ///
- public static RedisValue RedValue(string keyName)
- {
- return (RedisValue)$"{redisBaseAddr}{keyName}";
- }
///
/// Hash dati STATUS x la macchina specificata
///
@@ -227,12 +199,63 @@ namespace MP.Core
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
return (RedisKey)$"{prefix}:DtMac:{idxMacchina}";
}
+
+ ///
+ /// Formato RedisKey delal chaive richeista (completa)
+ ///
+ public static RedisKey RedKeyHash(string keyName)
+ {
+ return (RedisKey)$"{redisBaseAddr}{keyName}";
+ }
+
+ ///
+ /// Hash associazione Iob e macchina acquisizione (WIN)
+ ///
+ ///
+ ///
+ ///
+ public static RedisKey RedKeyMach2Iob(string idxMacchina, string baseAddr = null)
+ {
+ var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
+ return (RedisKey)$"{prefix}:hM2IOB:{idxMacchina}";
+ }
+
+ ///
+ /// Hash dati Conf Iob
+ ///
+ ///
+ ///
+ ///
public static RedisKey RedKeyMachIobConf(string idxMacchina, string baseAddr = null)
{
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
return (RedisKey)$"{prefix}:IOB:{idxMacchina}:MachIobConf";
}
+ ///
+ /// Hash dati Macchine Multi SM Ingressi
+ ///
+ ///
+ /// 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 RedKeyMsmi(string idxMacchina, string baseAddr = null)
+ {
+ var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
+ return (RedisKey)$"{prefix}:hMSMI:{idxMacchina}";
+ }
+
+ ///
+ /// Hash dati countapezzi 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 RedKeyPzCount(string idxMacchina, string baseAddr = null)
+ {
+ var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
+ return (RedisKey)$"{prefix}:Cache:PzCount:{idxMacchina}";
+ }
+
///
/// Hash dati Task2Exe x la macchina specificata
///
@@ -246,15 +269,11 @@ namespace MP.Core
}
///
- /// Chiave x CurrObjItems macchina
+ /// Formato RedisValue delal chaive richeista (completa)
///
- ///
- /// 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)
+ public static RedisValue RedValue(string keyName)
{
- var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
- return (RedisKey)$"{prefix}:CurrentParameters:{idxMacchina}";
+ return (RedisValue)$"{redisBaseAddr}{keyName}";
}
#endregion Public Methods
diff --git a/MP.Data/Controllers/MpIocController.cs b/MP.Data/Controllers/MpIocController.cs
index 3a3cfa77..2557ef3a 100644
--- a/MP.Data/Controllers/MpIocController.cs
+++ b/MP.Data/Controllers/MpIocController.cs
@@ -600,6 +600,7 @@ namespace MP.Data.Controllers
}
return dbResult;
}
+
///
/// Conteggio PzProd Macchina Async
///
diff --git a/MP.IOC/Controllers/IOBController.cs b/MP.IOC/Controllers/IOBController.cs
index 0804b9c2..82200bd5 100644
--- a/MP.IOC/Controllers/IOBController.cs
+++ b/MP.IOC/Controllers/IOBController.cs
@@ -1,9 +1,11 @@
using Microsoft.AspNetCore.Mvc;
using MP.Core.DTO;
+using MP.Core.Objects;
using MP.IOC.Data;
using Newtonsoft.Json;
using NLog;
using System.Reflection;
+using static MP.Core.Objects.Enums;
namespace MP.IOC.Controllers
{
@@ -405,6 +407,62 @@ namespace MP.IOC.Controllers
return Ok(answ);
}
+ ///
+ /// Salva associazione tra macchina, device IOB chiamante e sue info
+ ///
+ /// Id della macchina
+ /// Nome dell'IOB di acquisizione della macchina
+ ///
+ [HttpGet("setM2IOB/{id}")]
+ public async Task SetM2IOB(string id, string IOB_name)
+ {
+ if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
+
+ // Multi: gestione carattere "|" trasformato in "#"
+ id = id.Replace("|", "#");
+
+ try
+ {
+ // recupero IP del client remoto
+ var agent = Request.Headers["User-Agent"].ToString();
+ var IPv4 = HttpContext.Connection.RemoteIpAddress?.ToString();
+
+ // creo oggetto IOB_data...
+ IOB_data m2IOB = new IOB_data
+ {
+ name = IOB_name,
+ IP = IPv4,
+ iType = IobType.ND,
+ typeCss = "fa fa-question-circle-o",
+ CNC_Counter = false
+ };
+ // imposto tipo ed icona come windows/linux secondo UserAgent...
+ if (agent.IndexOf("WIN") >= 0)
+ {
+ m2IOB.iType = IobType.WIN;
+ m2IOB.typeCss = "fa fa-windows";
+ m2IOB.CNC_Counter = true;
+ }
+ else if (agent.IndexOf("Python") >= 0)
+ {
+ m2IOB.iType = IobType.rPi;
+ m2IOB.typeCss = "fa fa-linux";
+ }
+ // serializzo...
+ string dataSer = JsonConvert.SerializeObject(m2IOB);
+ // salvo...
+ await DService.SaveMachine2Iob(id, dataSer);
+
+ // salvo tutto OK
+ return Ok("OK");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Errore in SetM2IOB{Environment.NewLine}{exc}");
+ return StatusCode(StatusCodes.Status500InternalServerError, "NO");
+ }
+ }
+
///
/// Processa una chiamata POST per l'invio di una List Json di UNO O PIU' oggetti objItem
/// POST: IOB/upsertObjItems/SIMUL_03
diff --git a/MP.IOC/Data/MpDataService.cs b/MP.IOC/Data/MpDataService.cs
index 98064d7c..2c267361 100644
--- a/MP.IOC/Data/MpDataService.cs
+++ b/MP.IOC/Data/MpDataService.cs
@@ -2442,6 +2442,15 @@ namespace MP.IOC.Data
return answ;
}
+ public async Task RedisSetHashDictAsync(RedisKey redKey, Dictionary valori)
+ {
+ bool answ = false;
+ HashEntry[] redHash = valori.Select(x => new HashEntry(x.Key, x.Value)).ToArray();
+ await redisDb.HashSetAsync(redKey, redHash);
+ answ = true;
+ return answ;
+ }
+
///
/// Resetta (rileggendo) i dati della State Machine multi ingressi nel formato
/// key: IdxMacchina
@@ -2695,6 +2704,18 @@ namespace MP.IOC.Data
return answ;
}
+ public async Task SaveMachine2Iob(string idxMacchina, string serData)
+ {
+ bool fatto = false;
+ var currKey = Utils.RedKeyMach2Iob(idxMacchina);
+ // se != null --> salvo!
+ if (!string.IsNullOrEmpty(serData))
+ {
+ fatto = await redisDb.StringSetAsync(currKey, serData);
+ }
+ return fatto;
+ }
+
public async Task SaveMachineIobConf(string idxMacchina, Dictionary currDict)
{
bool fatto = false;
@@ -2702,7 +2723,7 @@ namespace MP.IOC.Data
// se != null --> salvo!
if (currDict != null)
{
- fatto = RedisSetHashDict(currKey, currDict);
+ fatto = await RedisSetHashDictAsync(currKey, currDict);
}
return fatto;
}