Update metodi task2exe
This commit is contained in:
@@ -313,6 +313,39 @@ namespace MP.Data.Controllers
|
||||
return fatto;
|
||||
}
|
||||
|
||||
public async Task<bool> KeepAliveUpsertAsync(string IdxMacc, DateTime OraServer, DateTime OraMacc)
|
||||
{
|
||||
bool fatto = false;
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
var currRec = await dbCtx
|
||||
.DbSetKeepAlive
|
||||
.Where(x => x.IdxMacchina == IdxMacc)
|
||||
.FirstOrDefaultAsync();
|
||||
if (currRec != null)
|
||||
{
|
||||
currRec.DataOraServer = OraServer;
|
||||
currRec.DataOraMacchina = OraMacc;
|
||||
dbCtx.Entry(currRec).State = EntityState.Modified;
|
||||
}
|
||||
else
|
||||
{
|
||||
KeepAliveModel newRec = new KeepAliveModel()
|
||||
{
|
||||
IdxMacchina = IdxMacc,
|
||||
DataOraMacchina = OraMacc,
|
||||
DataOraServer = OraServer,
|
||||
DataOraStart = DateTime.Now
|
||||
};
|
||||
dbCtx
|
||||
.DbSetKeepAlive
|
||||
.Add(newRec);
|
||||
}
|
||||
fatto = await dbCtx.SaveChangesAsync() > 0;
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
public List<LinkMenuModel> ListLinkFilt(string tipoLink)
|
||||
{
|
||||
List<LinkMenuModel> dbResult = new List<LinkMenuModel>();
|
||||
|
||||
@@ -44,6 +44,34 @@ namespace MP.IOC.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("addTask2Exe/{id}")]
|
||||
public async Task<IActionResult> AddTask2Exe(string id, string taskName, string taskVal)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
|
||||
// Multi: gestione carattere "|" trasformato in "#"
|
||||
id = id.Replace("|", "#");
|
||||
|
||||
string answ = "";
|
||||
try
|
||||
{
|
||||
await DService.ScriviKeepAliveAsync(id, DateTime.Now);
|
||||
taskType tName = taskType.nihil;
|
||||
bool isOk = Enum.TryParse(taskName, out tName);
|
||||
if (isOk)
|
||||
{
|
||||
// elimino se trovato + rileggo da REDIS elenco task restanti x macchina...
|
||||
var newList = DService.AddTask4Machine(id, tName, taskVal);
|
||||
answ = JsonConvert.SerializeObject(newList);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in GetTask2Exe{Environment.NewLine}{exc}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
}
|
||||
return Ok(answ);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GET: IOB/
|
||||
/// </summary>
|
||||
@@ -437,12 +465,19 @@ namespace MP.IOC.Controllers
|
||||
|
||||
// Multi: gestione carattere "|" trasformato in "#"
|
||||
id = id.Replace("|", "#");
|
||||
|
||||
string answ = "";
|
||||
DService.ScriviKeepAlive(id, DateTime.Now);
|
||||
// leggo da REDIS eventuale elenco task x macchina...
|
||||
Dictionary<string, string> valori = await DService.GetTask2ExeMacchinaAsync(id);
|
||||
answ = JsonConvert.SerializeObject(valori);
|
||||
try
|
||||
{
|
||||
DService.ScriviKeepAlive(id, DateTime.Now);
|
||||
// leggo da REDIS eventuale elenco task x macchina...
|
||||
Dictionary<string, string> valori = await DService.GetTask2ExeMacchinaAsync(id);
|
||||
answ = JsonConvert.SerializeObject(valori);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in GetTask2Exe{Environment.NewLine}{exc}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
}
|
||||
return Ok(answ);
|
||||
}
|
||||
|
||||
@@ -480,6 +515,52 @@ namespace MP.IOC.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AGGIUNGE TASK richiesto x macchina:
|
||||
///
|
||||
/// GET: IOB/addTask2Exe/3010?taskName=startSetup&taskVal=T190406101512
|
||||
/// GET: IOB/addTask2Exe/3010?taskName=stopSetup&taskVal=T190406101512
|
||||
/// GET: IOB/addTask2Exe/SIMUL_03?taskName=setProg&taskVal=P00000001
|
||||
/// GET: IOB/addTask2Exe/SIMUL_03?taskName=setComm&taskVal=ODL_0000123
|
||||
/// GET: IOB/addTask2Exe/SIMUL_03?taskName=setArt&taskVal=ART_0000321
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="taskName"></param>
|
||||
/// <param name="taskVal"></param>
|
||||
/// <summary>
|
||||
/// ELIMINA TASK richiesto x macchina:
|
||||
///
|
||||
/// GET: IOB/remTask2Exe/SIMUL_03?taskName=T180326160502
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="taskName"></param>
|
||||
[HttpGet("remTask2Exe/{id}")]
|
||||
public async Task<IActionResult> RemTask2Exe(string id, string taskName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
|
||||
// Multi: gestione carattere "|" trasformato in "#"
|
||||
id = id.Replace("|", "#");
|
||||
string answ = "";
|
||||
try
|
||||
{
|
||||
await DService.ScriviKeepAliveAsync(id, DateTime.Now);
|
||||
taskType tName = taskType.nihil;
|
||||
bool isOk = Enum.TryParse(taskName, out tName);
|
||||
if (isOk)
|
||||
{
|
||||
// elimino se trovato + rileggo da REDIS elenco task restanti x macchina...
|
||||
var newList = await DService.RemTask2ExeMacchinaAsync(id, tName);
|
||||
answ = JsonConvert.SerializeObject(newList);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in GetTask2Exe{Environment.NewLine}{exc}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
}
|
||||
return Ok(answ);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processa una chiamata POST per l'invio di un array Json di oggetti plcMemConf
|
||||
/// PUT: IOB/saveConf/SIMUL_03
|
||||
@@ -496,7 +577,6 @@ namespace MP.IOC.Controllers
|
||||
|
||||
string answ = "";
|
||||
|
||||
|
||||
// procedo a deserializzare in blocco l'oggetto...
|
||||
PlcMemMapDto currMemMap = null;
|
||||
try
|
||||
@@ -653,7 +733,6 @@ 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
|
||||
|
||||
+128
-12
@@ -128,7 +128,7 @@ namespace MP.IOC.Data
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifica se sia da reinviare un task alla macchina dall'elenco di quelli salvati (in
|
||||
/// Verifica se sia da reinviare un tName alla macchina dall'elenco di quelli salvati (in
|
||||
/// modalità upsert) se non scaduti
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
@@ -148,9 +148,9 @@ namespace MP.IOC.Data
|
||||
// se ho un valore != "" --> rimetto in coda di invio...
|
||||
if (!string.IsNullOrEmpty(savedVal) && (savedVal != taskVal))
|
||||
{
|
||||
// leggo task attuali...
|
||||
// leggo tName attuali...
|
||||
Dictionary<string, string> currTask = mTaskMacchina(idxMacchina);
|
||||
// rimetto in task da eseguire...
|
||||
// rimetto in tName da eseguire...
|
||||
currTask[taskKey.ToString()] = savedVal;
|
||||
answ = RedisSetHashDict(currHash, currTask);
|
||||
Log.Info($"re-issued task4machine: idxMacchina: {idxMacchina} | taskKey: {taskKey} | savedVal: {savedVal}");
|
||||
@@ -177,7 +177,7 @@ namespace MP.IOC.Data
|
||||
RedisKey currHash = Utils.OptParHash(idxMacchina);
|
||||
try
|
||||
{
|
||||
// leggo task attuali...
|
||||
// leggo tName attuali...
|
||||
var currVal = mOptParMacchina(idxMacchina);
|
||||
currVal[taskKey] = taskVal;
|
||||
answ = RedisSetHashDict(currHash, currVal);
|
||||
@@ -190,7 +190,7 @@ namespace MP.IOC.Data
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunge un task all'elenco di quelli salvati (in modalità upsert)
|
||||
/// Aggiunge un tName all'elenco di quelli salvati (in modalità upsert)
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="taskKey"></param>
|
||||
@@ -205,7 +205,7 @@ namespace MP.IOC.Data
|
||||
Dictionary<string, string> savedTask = new Dictionary<string, string>();
|
||||
try
|
||||
{
|
||||
// leggo task attuali...
|
||||
// leggo tName attuali...
|
||||
currTask = mTaskMacchina(idxMacchina);
|
||||
if (currTask.ContainsKey($"{taskKey}"))
|
||||
{
|
||||
@@ -219,14 +219,14 @@ namespace MP.IOC.Data
|
||||
Log.Info($"Task ADD | hash: {currHash} | idxMacchina: {idxMacchina} | taskKey: {taskKey} | taskVal: {taskVal}");
|
||||
}
|
||||
catch { }
|
||||
// verifico in base al tipo di task se fare backup...
|
||||
// verifico in base al tipo di tName se fare backup...
|
||||
switch (taskKey)
|
||||
{
|
||||
case Enums.taskType.setArt:
|
||||
case Enums.taskType.setComm:
|
||||
case Enums.taskType.setPzComm:
|
||||
case Enums.taskType.setProg:
|
||||
// leggo task SALVATI attuali...
|
||||
// leggo tName SALVATI attuali...
|
||||
savedTask = mSavedTaskMacchina(idxMacchina);
|
||||
savedTask[taskKey.ToString()] = taskVal;
|
||||
answ = RedisSetHashDict(currSavedParHash, savedTask);
|
||||
@@ -590,7 +590,7 @@ namespace MP.IOC.Data
|
||||
};
|
||||
// salva e processa
|
||||
answ = scriviRigaEvento(newRecEv);
|
||||
//answ = scriviRigaEvento(idxMacchina, idxTipoEv, codArticolo, valEsteso, 0, "-", dtEve, DateTime.Now);
|
||||
//currTask = scriviRigaEvento(idxMacchina, idxTipoEv, codArticolo, valEsteso, 0, "-", dtEve, DateTime.Now);
|
||||
// forzo RESET dati macchina...
|
||||
ResetDatiMacchina(idxMacchina);
|
||||
}
|
||||
@@ -2584,7 +2584,8 @@ namespace MP.IOC.Data
|
||||
/// <returns></returns>
|
||||
public bool RedisDelKey(string keyVal)
|
||||
{
|
||||
bool answ = false;
|
||||
bool answ = redisDb.KeyDelete((RedisKey)keyVal);
|
||||
#if false
|
||||
var listEndpoints = redisConnAdmin.GetEndPoints();
|
||||
foreach (var endPoint in listEndpoints)
|
||||
{
|
||||
@@ -2595,9 +2596,44 @@ namespace MP.IOC.Data
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue eliminazione memoria redis keyVal
|
||||
/// </summary>
|
||||
/// <param name="keyVal"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RedisDelKeyAsync(string keyVal)
|
||||
{
|
||||
return await RedisDelKeyAsync((RedisKey)keyVal);
|
||||
#if false
|
||||
bool answ = false;
|
||||
var listEndpoints = redisConnAdmin.GetEndPoints();
|
||||
foreach (var endPoint in listEndpoints)
|
||||
{
|
||||
var server = redisConnAdmin.GetServer(endPoint);
|
||||
if (server != null)
|
||||
{
|
||||
await redisDb.KeyDeleteAsync((RedisKey)keyVal);
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue eliminazione memoria redis keyVal
|
||||
/// </summary>
|
||||
/// <param name="keyVal"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RedisDelKeyAsync(RedisKey keyVal)
|
||||
{
|
||||
return await redisDb.KeyDeleteAsync(keyVal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue flush memoria redis dato keyVal
|
||||
/// </summary>
|
||||
@@ -2730,6 +2766,21 @@ namespace MP.IOC.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> RedisKeyPresentAsync(RedisKey key)
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
result = await redisDb.KeyExistsAsync(key);
|
||||
}
|
||||
catch (Exception arg)
|
||||
{
|
||||
Log.Error($"Errore in redKeyPresent per la currKey {key}:{Environment.NewLine}{arg}");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool RedisKeyPresentSz(string key)
|
||||
{
|
||||
bool result = false;
|
||||
@@ -2804,7 +2855,7 @@ namespace MP.IOC.Data
|
||||
// insert del record
|
||||
fatto = await IocDbController.RemRebootLogAddAsync(newRec);
|
||||
// pulizia record vecchi
|
||||
int num2keep = 10;
|
||||
int num2keep = 5;
|
||||
string confVal = await tryGetConfig("IO_NumReboot2Keep");
|
||||
if (!string.IsNullOrEmpty(confVal))
|
||||
{
|
||||
@@ -2888,6 +2939,35 @@ namespace MP.IOC.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elimina da elenco KVP il TASK per l'impianto indicato
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="tName"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Dictionary<string, string>> RemTask2ExeMacchinaAsync(string idxMacchina, taskType tName)
|
||||
{
|
||||
// hard coded dimensione vettore DatiMacchine
|
||||
Dictionary<string, string> answ = new Dictionary<string, string>();
|
||||
// ORA recupero da memoria redis...
|
||||
try
|
||||
{
|
||||
var currHash = Utils.RedKeyTask2ExeMacc(idxMacchina, MpIoNS);
|
||||
answ = await RedisGetHashDictAsync(currHash);
|
||||
|
||||
answ.Remove($"{tName}");
|
||||
// riscrivo!
|
||||
await RedisDelKeyAsync(currHash);
|
||||
await RedisSetHashDictAsync(currHash, answ);
|
||||
Log.Info($"Task REM - idxMacchina: {idxMacchina} | taskKey: {tName.ToString()}");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Info(string.Format("Errore in RemTask2ExeMacchinaAsync | idxMacchina {2}:{0}{1}", Environment.NewLine, exc, idxMacchina));
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resetta (rileggendo) i dati della State Machine multi ingressi nel formato
|
||||
/// currKey: IdxMacchina
|
||||
@@ -2898,7 +2978,7 @@ namespace MP.IOC.Data
|
||||
public KeyValuePair<string, string>[] resetMSMI(string idxMacchina)
|
||||
{
|
||||
var currHash = Utils.RedKeyMsmi(idxMacchina);
|
||||
//answ = RedisGetHash(currHash);
|
||||
//currTask = RedisGetHash(currHash);
|
||||
// recupero records
|
||||
var tabMSMI = IocDbController.VMSFDGetMultiByMacc(idxMacchina);
|
||||
|
||||
@@ -3222,6 +3302,42 @@ namespace MP.IOC.Data
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// scrive un evento di keepalive sulla tabella
|
||||
/// </summary>
|
||||
/// <param name="IdxMacchina"></param>
|
||||
/// <param name="oraMacchina"></param>
|
||||
/// <returns></returns>
|
||||
public async Task ScriviKeepAliveAsync(string IdxMacchina, DateTime oraMacchina)
|
||||
{
|
||||
string nomeVar = string.Format("KeepAlive:{0}", IdxMacchina);
|
||||
// cerco se ho keep alive in redis,
|
||||
bool keyPresent = false;
|
||||
DateTime adesso = DateTime.Now;
|
||||
var currKey = Utils.RedKeyHash(nomeVar);
|
||||
try
|
||||
{
|
||||
keyPresent = await RedisKeyPresentAsync(currKey);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
// se NON presente salvo in REDIS con TTL 10 sec e sul DB...
|
||||
if (!keyPresent)
|
||||
{
|
||||
await redisDb.StringSetAsync(currKey, adesso.ToString("s"), TimeSpan.FromSeconds(10));
|
||||
try
|
||||
{
|
||||
Log.Trace($"Scrittura keep alive! IdxMacchina: {IdxMacchina}");
|
||||
// effettuo scrittura sul DB
|
||||
await IocDbController.KeepAliveUpsertAsync(IdxMacchina, DateTime.Now, oraMacchina);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in scrittura keep alive!{Environment.NewLine}oraMacchina: {oraMacchina} - IdxMacchina: {IdxMacchina}{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Salvataggio YAML completo di configurazione dell'IOB
|
||||
/// </summary>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>6.16.2604.1515</Version>
|
||||
<Version>6.16.2604.1517</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MP-IOC </i>
|
||||
<h4>Versione: 6.16.2604.1515</h4>
|
||||
<h4>Versione: 6.16.2604.1517</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
6.16.2604.1515
|
||||
6.16.2604.1517
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>6.16.2604.1515</version>
|
||||
<version>6.16.2604.1517</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