Aggiunta metodi sendReboot
This commit is contained in:
+2
-1
@@ -60,6 +60,7 @@ namespace MP.Core
|
||||
public const string redisPOdlByPOdl = redisXdlData + "POdlByPOdl";
|
||||
public const string redisPOdlList = redisXdlData + "POdlList";
|
||||
public const string redisRecipeConf = redisBaseAddr + "Cache:Recipe:Conf";
|
||||
public const string redisRemRebLog = redisBaseAddr + "Cache:RemReb";
|
||||
public const string redisStatoCom = redisBaseAddr + "Cache:StatoCom";
|
||||
public const string redisStatoMacch = redisBaseAddr + "Cache:StatoMacch";
|
||||
public const string redisStatoProd = redisBaseAddr + "Cache:StatoProd";
|
||||
@@ -290,7 +291,7 @@ namespace MP.Core
|
||||
public static RedisKey RedKeyPzCount(string idxMacchina, string baseAddr = null)
|
||||
{
|
||||
var prefix = (baseAddr ?? redisBaseAddr).TrimEnd(':');
|
||||
return (RedisKey)$"{prefix}:Cache:PzCount:{idxMacchina}";
|
||||
return (RedisKey)$"{prefix}:PzCount:{idxMacchina}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -941,6 +941,78 @@ namespace MP.Data.Controllers
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunta record RemoteRebootLog
|
||||
/// </summary>
|
||||
/// <param name="newRec"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RemRebootLogAddAsync(RemoteRebootLogModel newRec)
|
||||
{
|
||||
bool fatto = false;
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
var dbResult = dbCtx
|
||||
.DbSetRemRebLog
|
||||
.Add(newRec);
|
||||
fatto = await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera tutti i record di RemoteRebootLog
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<RemoteRebootLogModel>> RemRebootLogGetAllAsync()
|
||||
{
|
||||
List<RemoteRebootLogModel> dbResult = new List<RemoteRebootLogModel>();
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
dbResult = await dbCtx
|
||||
.DbSetRemRebLog
|
||||
.AsNoTracking()
|
||||
.OrderByDescending(x => x.IdxReboot)
|
||||
.ToListAsync();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera ultimo record x ogni IdxMacchina x avere ultimo attivo
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<RemoteRebootLogModel>> RemRebootLogGetLastAsync()
|
||||
{
|
||||
List<RemoteRebootLogModel> dbResult = new List<RemoteRebootLogModel>();
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
dbResult = await dbCtx
|
||||
.DbSetRemRebLog
|
||||
.FromSqlRaw("EXEC stp_RRL_getLast")
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera ultimo record x ogni IdxMacchina x avere ultimo attivo
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RemRebootLogKeepLastAsync(int num2keep)
|
||||
{
|
||||
bool answ = false;
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
var Num2keep = new SqlParameter("@num2keep", num2keep);
|
||||
var dbResult = await dbCtx
|
||||
.Database
|
||||
.ExecuteSqlRawAsync("exec dbo.stp_RRL_KeepLatest @num2keep", Num2keep);
|
||||
answ = dbResult > 0;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Annulla modifiche su una specifica entity (cancel update)
|
||||
/// </summary>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MP.Core.DTO;
|
||||
using MP.Core.Objects;
|
||||
using MP.Data.DbModels;
|
||||
using MP.IOC.Data;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
@@ -652,6 +653,62 @@ namespace MP.IOC.Controllers
|
||||
return Ok(answ);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Salva MAC adress + IP dopo il reboot
|
||||
/// GET: IOB/sendReboot/SIMUL_05?mac=18:C0:4D:37:3C:8C
|
||||
/// </summary>
|
||||
/// <param name="id">ID macchina</param>
|
||||
/// <param name="mac">MAC address macchina</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("sendReboot/{id}")]
|
||||
public async Task<IActionResult> SendReboot(string id, string mac)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
|
||||
|
||||
// Multi: gestione carattere "|" trasformato in "#"
|
||||
id = id.Replace("|", "#");
|
||||
|
||||
string answ = "NO";
|
||||
try
|
||||
{
|
||||
// recupero IP del client remoto
|
||||
var agent = Request.Headers["User-Agent"].ToString();
|
||||
var iPv4 = HttpContext.Connection.RemoteIpAddress?.ToString();
|
||||
|
||||
// chiamo registrazione reboot
|
||||
RemoteRebootLogModel newRec = new()
|
||||
{
|
||||
Agent = agent,
|
||||
DataOraBoot = DateTime.Now,
|
||||
IdxMacchina = id,
|
||||
IPv4 = iPv4,
|
||||
MacAddr = mac
|
||||
};
|
||||
bool fatto = await DService.RemRebootLogAddAsync(newRec);
|
||||
answ = fatto ? "OK" : "KO";
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in sendReboot{Environment.NewLine}{exc}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
}
|
||||
return Ok(answ);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Salva IP del gateway dopo il reboot
|
||||
/// </summary>
|
||||
/// <param name="GWIP">IP del Gateway</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("sendRebootGateway/{id}")]
|
||||
public async Task<IActionResult> SendRebootGateway(string GWIP)
|
||||
{
|
||||
string answ = "OK";
|
||||
// !!!FARE!!! deve salvare il riavvio dell'applicazione GATEWAY multiclient
|
||||
return Ok(answ);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SALVA Counter x macchina restituendo il valore appena inviato o, se mancasse chiave
|
||||
/// redis, del valore da DB
|
||||
@@ -666,8 +723,6 @@ namespace MP.IOC.Controllers
|
||||
{
|
||||
if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
|
||||
|
||||
//Stopwatch sw = new Stopwatch();
|
||||
//sw.Start();
|
||||
// Multi: gestione carattere "|" trasformato in "#"
|
||||
id = id.Replace("|", "#");
|
||||
|
||||
@@ -683,8 +738,6 @@ namespace MP.IOC.Controllers
|
||||
Log.Error($"Errore in SetCounter{Environment.NewLine}{exc}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
}
|
||||
//sw.Stop();
|
||||
//Log.Trace($"SetCounter | Elapsed: {sw.Elapsed.TotalMilliseconds:N2}");
|
||||
return Ok(answ);
|
||||
}
|
||||
|
||||
|
||||
@@ -2794,6 +2794,100 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserisce record RRL + fa pulizia vecchi record
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RemRebootLogAddAsync(RemoteRebootLogModel newRec)
|
||||
{
|
||||
bool fatto = false;
|
||||
// insert del record
|
||||
fatto = await IocDbController.RemRebootLogAddAsync(newRec);
|
||||
// pulizia record vecchi
|
||||
int num2keep = 10;
|
||||
string confVal = await tryGetConfig("IO_NumReboot2Keep");
|
||||
if (!string.IsNullOrEmpty(confVal))
|
||||
{
|
||||
int.TryParse(confVal, out num2keep);
|
||||
}
|
||||
fatto = await IocDbController.RemRebootLogKeepLastAsync(num2keep);
|
||||
// svuota cache
|
||||
var currKey = $"{Utils.redisRemRebLog}:*";
|
||||
await RedisFlushPatternAsync(currKey);
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera tutti i record di RemoteRebootLog
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<RemoteRebootLogModel>> RemRebootLogGetAllAsync()
|
||||
{
|
||||
// setup parametri costanti
|
||||
string source = "DB";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
List<RemoteRebootLogModel> result = new List<RemoteRebootLogModel>();
|
||||
// cerco in _redisConn...
|
||||
var currKey = $"{Utils.redisRemRebLog}:ALL";
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
//if (!string.IsNullOrEmpty($"{rawData}"))
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<RemoteRebootLogModel>>($"{rawData}") ?? new();
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await IocDbController.RemRebootLogGetAllAsync();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, TimeSpan.FromSeconds(30));
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<RemoteRebootLogModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"RemRebootLogGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera ultimo record x ogni IdxMacchina x avere ultimo attivo
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<RemoteRebootLogModel>> RemRebootLogGetLast()
|
||||
{
|
||||
// setup parametri costanti
|
||||
string source = "DB";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
List<RemoteRebootLogModel> result = new List<RemoteRebootLogModel>();
|
||||
// cerco in _redisConn...
|
||||
var currKey = $"{Utils.redisRemRebLog}:LAST";
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<RemoteRebootLogModel>>($"{rawData}") ?? new();
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await IocDbController.RemRebootLogGetLastAsync();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, TimeSpan.FromSeconds(30));
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<RemoteRebootLogModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"RemRebootLogGetLast | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resetta (rileggendo) i dati della State Machine multi ingressi nel formato
|
||||
/// currKey: IdxMacchina
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>6.16.2604.1512</Version>
|
||||
<Version>6.16.2604.1515</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MP-IOC </i>
|
||||
<h4>Versione: 6.16.2604.1512</h4>
|
||||
<h4>Versione: 6.16.2604.1515</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
6.16.2604.1512
|
||||
6.16.2604.1515
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>6.16.2604.1512</version>
|
||||
<version>6.16.2604.1515</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