Update ance x metodo enabled in nuovo servizio/repository
This commit is contained in:
@@ -31,6 +31,13 @@ namespace MP.Data.Services.IOC
|
||||
/// <returns></returns>
|
||||
Task<bool> EvListMicroStatoInsertAsync(MicroStatoMacchinaModel newRecMsm, EventListModel newRecEv);
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il valOut booleano se la macchina sia abilitata all'input
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> IobInsEnabAsync(string idxMacchina);
|
||||
|
||||
/// <summary>
|
||||
/// Aggiornamento record Microstato macchina
|
||||
/// </summary>
|
||||
@@ -49,6 +56,14 @@ namespace MP.Data.Services.IOC
|
||||
/// <returns></returns>
|
||||
Task<string> ProcessInputAsync(string idxMacchina, string valore, string dtEve, string dtCurr, string contatore);
|
||||
|
||||
/// <summary>
|
||||
/// scrive un evento di keepalive sulla tabella
|
||||
/// </summary>
|
||||
/// <param name="IdxMacchina"></param>
|
||||
/// <param name="oraMacchina"></param>
|
||||
/// <returns></returns>
|
||||
Task ScriviKeepAliveAsync(string IdxMacchina, DateTime oraMacchina);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -43,37 +43,6 @@ namespace MP.Data.Services.IOC
|
||||
return success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco completo config da DB
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<ConfigModel>> ConfigGetAllAsync()
|
||||
{
|
||||
List<ConfigModel>? result = new List<ConfigModel>();
|
||||
// cerco in redis...
|
||||
RedisValue rawData = await _redisDb.StringGetAsync(MP.Data.Utils.redisConfKey);
|
||||
string source = "DB";
|
||||
if (!string.IsNullOrEmpty($"{rawData}"))
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<ConfigModel>>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await _repo.ConfigGetAllAsync();
|
||||
//result = await Task.FromResult(SpecDbController.ConfigGetAllAsync());
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await _redisDb.StringSetAsync(MP.Data.Utils.redisConfKey, rawData, getRandTOut(redisLongTimeCache));
|
||||
}
|
||||
Log.Debug($"ConfigGetAllAsync Read from {source}");
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<ConfigModel>();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> EvListMicroStatoInsertAsync(MicroStatoMacchinaModel newRecMsm, EventListModel newRecEv)
|
||||
{
|
||||
@@ -81,64 +50,20 @@ namespace MP.Data.Services.IOC
|
||||
return success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il valOut booleano se la macchina sia abilitata all'inserimento COMPLETO nel
|
||||
/// Signal Log
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> IobSLogEnabAsync(string idxMacchina)
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> IobInsEnabAsync(string idxMacchina)
|
||||
{
|
||||
bool answ = false;
|
||||
// ORA recupero da memoria redis...
|
||||
try
|
||||
{
|
||||
var currHash = MP.Data.Utils.RedKeyDatiMacc(idxMacchina, MpIoNS);
|
||||
RedisValue rawData = await _redisDb.HashGetAsync(currHash, (RedisValue)"sLogEnabled");
|
||||
// se è vuoto... leggo da DB e popolo!
|
||||
if (!rawData.HasValue)
|
||||
{
|
||||
await ResetDatiMacchinaAsync(idxMacchina);
|
||||
// riprovo
|
||||
rawData = await _redisDb.HashGetAsync(currHash, (RedisValue)"sLogEnabled");
|
||||
}
|
||||
var key = MP.Data.Utils.RedKeyDatiMacc(idxMacchina, MpIoNS);
|
||||
|
||||
// provo conversione
|
||||
bool.TryParse($"{rawData}", out answ);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore IobSLogEnabAsync | idxMacchina {idxMacchina}:{Environment.NewLine}{exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
string? val = await _redisDb.HashGetAsync(key, "insEnabled");
|
||||
|
||||
/// <summary>
|
||||
/// Elenco completo valori Macchine 2 Slave
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<Macchine2SlaveModel>> Macchine2SlaveGetAllAsync()
|
||||
{
|
||||
List<Macchine2SlaveModel>? result = new List<Macchine2SlaveModel>();
|
||||
string currKey = $"{MP.Data.Utils.redisBaseAddr}:M2STab";
|
||||
// cerco in redis dato valOut sel macchina...
|
||||
RedisValue rawData = await _redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
if (val == null)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<Macchine2SlaveModel>>($"{rawData}");
|
||||
var data = await ResetDatiMacchinaAsync(idxMacchina);
|
||||
data.TryGetValue("insEnabled", out val);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await _repo.Macchine2SlaveAsync();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await _redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10));
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<Macchine2SlaveModel>();
|
||||
}
|
||||
return result;
|
||||
|
||||
return val != null && (val == "1" || val.ToLower() == "true");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -205,12 +130,7 @@ namespace MP.Data.Services.IOC
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// scrive un evento di keepalive sulla tabella
|
||||
/// </summary>
|
||||
/// <param name="IdxMacchina"></param>
|
||||
/// <param name="oraMacchina"></param>
|
||||
/// <returns></returns>
|
||||
/// <inheritdoc />
|
||||
public async Task ScriviKeepAliveAsync(string IdxMacchina, DateTime oraMacchina)
|
||||
{
|
||||
// cerco se ho keep alive in redis,
|
||||
@@ -371,6 +291,37 @@ namespace MP.Data.Services.IOC
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco completo config da DB
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<List<ConfigModel>> ConfigGetAllAsync()
|
||||
{
|
||||
List<ConfigModel>? result = new List<ConfigModel>();
|
||||
// cerco in redis...
|
||||
RedisValue rawData = await _redisDb.StringGetAsync(MP.Data.Utils.redisConfKey);
|
||||
string source = "DB";
|
||||
if (!string.IsNullOrEmpty($"{rawData}"))
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<ConfigModel>>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await _repo.ConfigGetAllAsync();
|
||||
//result = await Task.FromResult(SpecDbController.ConfigGetAllAsync());
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await _redisDb.StringSetAsync(MP.Data.Utils.redisConfKey, rawData, getRandTOut(redisLongTimeCache));
|
||||
}
|
||||
Log.Debug($"ConfigGetAllAsync Read from {source}");
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<ConfigModel>();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper standardizzazione valOut dataora ricevuto da IOB remoti
|
||||
/// </summary>
|
||||
@@ -381,6 +332,38 @@ namespace MP.Data.Services.IOC
|
||||
return s?.Length > 17 ? s[..17] : s?.PadRight(17, '0') ?? string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il valOut booleano se la macchina sia abilitata all'inserimento COMPLETO nel
|
||||
/// Signal Log
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> IobSLogEnabAsync(string idxMacchina)
|
||||
{
|
||||
bool answ = false;
|
||||
// ORA recupero da memoria redis...
|
||||
try
|
||||
{
|
||||
var currHash = MP.Data.Utils.RedKeyDatiMacc(idxMacchina, MpIoNS);
|
||||
RedisValue rawData = await _redisDb.HashGetAsync(currHash, (RedisValue)"sLogEnabled");
|
||||
// se è vuoto... leggo da DB e popolo!
|
||||
if (!rawData.HasValue)
|
||||
{
|
||||
await ResetDatiMacchinaAsync(idxMacchina);
|
||||
// riprovo
|
||||
rawData = await _redisDb.HashGetAsync(currHash, (RedisValue)"sLogEnabled");
|
||||
}
|
||||
|
||||
// provo conversione
|
||||
bool.TryParse($"{rawData}", out answ);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore IobSLogEnabAsync | idxMacchina {idxMacchina}:{Environment.NewLine}{exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il valOut booleano se la macchina sia di tipo MULTI (con più state machine x INGRESSI)
|
||||
/// usando dati macchina in cache per evitare lookup ridondanti
|
||||
@@ -442,6 +425,34 @@ namespace MP.Data.Services.IOC
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco completo valori Macchine 2 Slave
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<List<Macchine2SlaveModel>> Macchine2SlaveGetAllAsync()
|
||||
{
|
||||
List<Macchine2SlaveModel>? result = new List<Macchine2SlaveModel>();
|
||||
string currKey = $"{MP.Data.Utils.redisBaseAddr}:M2STab";
|
||||
// cerco in redis dato valOut sel macchina...
|
||||
RedisValue rawData = await _redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<Macchine2SlaveModel>>($"{rawData}");
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await _repo.Macchine2SlaveAsync();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await _redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10));
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<Macchine2SlaveModel>();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restitusice elenco KVP dei campi DatiMacchine + StatoMacchine per l'impianto indicato
|
||||
/// </summary>
|
||||
|
||||
@@ -98,7 +98,8 @@ namespace MP.IOC.Controllers
|
||||
try
|
||||
{
|
||||
// Il metodo ora restituisce direttamente il booleano logico
|
||||
bool isEnabled = await DService.IobInsEnabAsync(id);
|
||||
bool isEnabled = await IOCService.IobInsEnabAsync(id);
|
||||
//bool isEnabled = await DService.IobInsEnabAsync(id);
|
||||
|
||||
return isEnabled
|
||||
? Ok("OK")
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>8.16.2604.3017</Version>
|
||||
<Version>8.16.2604.3018</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MP-IOC </i>
|
||||
<h4>Versione: 8.16.2604.3017</h4>
|
||||
<h4>Versione: 8.16.2604.3018</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
8.16.2604.3017
|
||||
8.16.2604.3018
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>8.16.2604.3017</version>
|
||||
<version>8.16.2604.3018</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/MP.IOC.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
Reference in New Issue
Block a user