Aggiunta metodo M2IOB + reorg codeMaid
This commit is contained in:
+57
-38
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hash dati Macchine Multi SM Ingressi
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr">Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)</param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey RedKeyMsmi(string idxMacchina, string baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:hMSMI:{idxMacchina}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Nome della variabile HASH da utilizzare (dato CodModulo / Server / DB impiegato
|
||||
/// dafunzionalita' DbConfig) + idxMacchina richiesto...
|
||||
@@ -190,32 +177,17 @@ namespace MP.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hash dati countapezzi macchina
|
||||
/// Chiave x CurrObjItems macchina
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr">Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)</param>
|
||||
/// <returns></returns>
|
||||
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}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formato RedisKey delal chaive richeista (completa)
|
||||
/// </summary>
|
||||
public static RedisKey RedKeyHash(string keyName)
|
||||
{
|
||||
return (RedisKey)$"{redisBaseAddr}{keyName}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formato RedisValue delal chaive richeista (completa)
|
||||
/// </summary>
|
||||
public static RedisValue RedValue(string keyName)
|
||||
{
|
||||
return (RedisValue)$"{redisBaseAddr}{keyName}";
|
||||
}
|
||||
/// <summary>
|
||||
/// Hash dati STATUS x la macchina specificata
|
||||
/// </summary>
|
||||
@@ -227,12 +199,63 @@ namespace MP.Core
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:DtMac:{idxMacchina}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formato RedisKey delal chaive richeista (completa)
|
||||
/// </summary>
|
||||
public static RedisKey RedKeyHash(string keyName)
|
||||
{
|
||||
return (RedisKey)$"{redisBaseAddr}{keyName}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hash associazione Iob e macchina acquisizione (WIN)
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr"></param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey RedKeyMach2Iob(string idxMacchina, string baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:hM2IOB:{idxMacchina}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hash dati Conf Iob
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr"></param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey RedKeyMachIobConf(string idxMacchina, string baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:IOB:{idxMacchina}:MachIobConf";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hash dati Macchine Multi SM Ingressi
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr">Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)</param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey RedKeyMsmi(string idxMacchina, string baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:hMSMI:{idxMacchina}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hash dati countapezzi macchina
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr">Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)</param>
|
||||
/// <returns></returns>
|
||||
public static RedisKey RedKeyPzCount(string idxMacchina, string baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:Cache:PzCount:{idxMacchina}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hash dati Task2Exe x la macchina specificata
|
||||
/// </summary>
|
||||
@@ -246,15 +269,11 @@ namespace MP.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chiave x CurrObjItems macchina
|
||||
/// Formato RedisValue delal chaive richeista (completa)
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="baseAddr">Chiave override per i valori in caso di dati che accedono al dominio dati di un altra app (es: baseAddr x IO legacy)</param>
|
||||
/// <returns></returns>
|
||||
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
|
||||
|
||||
@@ -600,6 +600,7 @@ namespace MP.Data.Controllers
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Conteggio PzProd Macchina Async
|
||||
/// </summary>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Salva associazione tra macchina, device IOB chiamante e sue info
|
||||
/// </summary>
|
||||
/// <param name="id">Id della macchina</param>
|
||||
/// <param name="IOB_name">Nome dell'IOB di acquisizione della macchina</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("setM2IOB/{id}")]
|
||||
public async Task<IActionResult> 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");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processa una chiamata POST per l'invio di una List Json di UNO O PIU' oggetti objItem
|
||||
/// POST: IOB/upsertObjItems/SIMUL_03
|
||||
|
||||
@@ -2442,6 +2442,15 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
public async Task<bool> RedisSetHashDictAsync(RedisKey redKey, Dictionary<string, string> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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<bool> 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<bool> SaveMachineIobConf(string idxMacchina, Dictionary<string, string> 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user