Completato porting BENCH
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MP.IOC.Data;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using NLog.Fluent;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace MP.IOC.Controllers
|
||||
@@ -13,6 +9,8 @@ namespace MP.IOC.Controllers
|
||||
[ApiController]
|
||||
public class BenchController : ControllerBase
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public BenchController(IConfiguration configuration, MpDataService DataService)
|
||||
{
|
||||
Log.Info("Starting MpDataService INIT");
|
||||
@@ -21,28 +19,173 @@ namespace MP.IOC.Controllers
|
||||
Log.Info("Avviata classe Recipe");
|
||||
}
|
||||
|
||||
private static IConfiguration _configuration = null!;
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
/// <summary>
|
||||
/// Dataservice x accesso DB
|
||||
/// Conteggio chiavi REDIS dato pattern api/Bench/CountKeys
|
||||
/// </summary>
|
||||
protected MpDataService DService { get; set; }
|
||||
|
||||
//// GET: IOB (è un check alive)
|
||||
//public string Index()
|
||||
//{
|
||||
// return "OK";
|
||||
//}
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("CountKeys")]
|
||||
public string CountKeys(string? id)
|
||||
{
|
||||
string answ = "ND";
|
||||
if (id == null) id = "";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
// conto quanti oggetti ho in memoria REDIS...
|
||||
string groupHash = ""; // DataLayer.mHash("");
|
||||
if (id.Length > 0)
|
||||
{
|
||||
groupHash += id + ":";
|
||||
}
|
||||
groupHash += "*";
|
||||
answ = $"Trovate {DService.RedisCountKey(groupHash)} Hash per {groupHash}";
|
||||
stopWatch.Stop();
|
||||
// Get the elapsed time as a TimeSpan value.
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
// accodo tempo!
|
||||
answ += $"{Environment.NewLine}Elapsed: {ts.TotalMilliseconds}ms";
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// pulizia dati
|
||||
/// api/Bench/RClean?id=100
|
||||
/// Bench recupero dati macchina api/Bench/DtMac?id=SIMUL_01
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("DatiMacc")]
|
||||
public string DatiMacc(string id)
|
||||
{
|
||||
string answ = "ND";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
// se id nullo --> KO!
|
||||
if (id == null)
|
||||
{
|
||||
answ = "KO";
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = "";
|
||||
try
|
||||
{
|
||||
Dictionary<string, string> valori = DService.ResetDatiMacchina(id);
|
||||
foreach (var item in valori)
|
||||
{
|
||||
answ += $"{item.Key}|{item.Value}{Environment.NewLine}";
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
stopWatch.Stop();
|
||||
// Get the elapsed time as a TimeSpan value.
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
// accodo tempo!
|
||||
answ += $"{Environment.NewLine}Elapsed: {ts.TotalMilliseconds}ms";
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary> Recupera riga traduzione microstato x processing da HASH table
|
||||
/// api/Bench/FindSMI?id=60&idxMS=3&valore=1 </summary> <param name="id"></param> <param
|
||||
/// name="idxMS"></param> <param name="valore"></param> <returns></returns>
|
||||
[HttpGet("FindSMI")]
|
||||
public string FindSMI(int? id, int? idxMS, int? valore)
|
||||
{
|
||||
string answ = "ND";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
// se id nullo --> KO!
|
||||
if (id == null)
|
||||
{
|
||||
answ = "KO";
|
||||
}
|
||||
else
|
||||
{
|
||||
// recupero dati x sapere quale famiglia SMI è necessaria e quale stato / segnale si
|
||||
// sia ricevuto
|
||||
int idxFamIn = Convert.ToInt32(id);
|
||||
int idxMicroStato = Convert.ToInt32(idxMS);
|
||||
int valIOB = Convert.ToInt32(valore);
|
||||
// recupero microstato macchina da chiave relativa
|
||||
answ = "";
|
||||
try
|
||||
{
|
||||
string fiHASH = DService.hSMI(idxFamIn);
|
||||
string outVal = "";
|
||||
bool trovato = DService.RedisHashPresentSz(fiHASH);
|
||||
if (!trovato)
|
||||
{
|
||||
// ricarico tabella!
|
||||
KeyValuePair<string, string>[] valori = DService.StateMachInByKey(idxFamIn);
|
||||
answ = string.Format("Ricaricata SMI per famiglia {0}<br/>", fiHASH);
|
||||
}
|
||||
|
||||
// recupero singolo valore (stringa) x chiave
|
||||
outVal = DService.ValoreSMI(idxFamIn, idxMicroStato, valIOB);
|
||||
// mostro output
|
||||
answ += $"idxFamIN: {idxFamIn} | idxMS: {idxMicroStato} | valIOB: {valIOB} | out: {outVal}";
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
stopWatch.Stop();
|
||||
// Get the elapsed time as a TimeSpan value.
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
// accodo tempo!
|
||||
answ += $"{Environment.NewLine}Total Time Elapsed: {ts.TotalMilliseconds}ms";
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test verifica insert enabled x macchina
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("InsEnab")]
|
||||
public string InsEnab(string id)
|
||||
{
|
||||
string answ = "ND";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
// se id nullo --> KO!
|
||||
if (id == null)
|
||||
{
|
||||
answ = "KO";
|
||||
}
|
||||
else
|
||||
{
|
||||
// recupero microstato macchina da chiave relativa
|
||||
answ = "";
|
||||
try
|
||||
{
|
||||
answ += $"Macchina {id}, insEnabled {DService.IobInsEnab(id)}{Environment.NewLine}";
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
stopWatch.Stop();
|
||||
// Get the elapsed time as a TimeSpan value.
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
// accodo tempo!
|
||||
answ += $"{Environment.NewLine}Total Time Elapsed: {ts.TotalMilliseconds}ms";
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// pulizia dati api/Bench/RClean?id=100
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("RClean")]
|
||||
public string RCLEAN(int? id)
|
||||
public string RClean(int? id)
|
||||
{
|
||||
string answ = "ND";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
@@ -77,14 +220,19 @@ namespace MP.IOC.Controllers
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
|
||||
//// GET: IOB (è un check alive)
|
||||
//public string Index()
|
||||
//{
|
||||
// return "OK";
|
||||
//}
|
||||
/// <summary>
|
||||
/// Setup dati di test hash
|
||||
/// api/Bench/RSetup?id=100
|
||||
/// Setup dati di test hash api/Bench/RSetup?id=100
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("RSetup")]
|
||||
public string RSETUP(int? id)
|
||||
public string RSetup(int? id)
|
||||
{
|
||||
string answ = "ND";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
@@ -121,14 +269,14 @@ namespace MP.IOC.Controllers
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupero singolo valore hash
|
||||
/// api/Bench/RSingleHash?id=50
|
||||
/// Recupero singolo valore hash api/Bench/RSingleHash?id=50
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("RSingleHash")]
|
||||
public string RSH(int? id)
|
||||
public string RSingleHash(int? id)
|
||||
{
|
||||
string answ = "ND";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
@@ -164,81 +312,14 @@ namespace MP.IOC.Controllers
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Bench recupero dati macchina
|
||||
/// api/Bench/DtMac?id=SIMUL_01
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("DtMac")]
|
||||
public string DTMAC(string id)
|
||||
{
|
||||
string answ = "ND";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
// se id nullo --> KO!
|
||||
if (id == null)
|
||||
{
|
||||
answ = "KO";
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = "";
|
||||
try
|
||||
{
|
||||
Dictionary<string, string> valori = DService.MSFDMaccGetCurr(id);
|
||||
foreach (var item in valori)
|
||||
{
|
||||
answ += $"{item.Key}|{item.Value}{Environment.NewLine}";
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
stopWatch.Stop();
|
||||
// Get the elapsed time as a TimeSpan value.
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
// accodo tempo!
|
||||
answ += $"{Environment.NewLine}Elapsed: {ts.TotalMilliseconds}ms";
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Conteggio chiavi REDIS dato pattern
|
||||
/// api/Bench/CountKeys
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("CountKeys")]
|
||||
public string CNTKEY(string? id)
|
||||
{
|
||||
string answ = "ND";
|
||||
if (id == null) id = "";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
// conto quanti oggetti ho in memoria REDIS...
|
||||
string groupHash = ""; // DataLayer.mHash("");
|
||||
if (id.Length > 0)
|
||||
{
|
||||
groupHash += id + ":";
|
||||
}
|
||||
groupHash += "*";
|
||||
answ = $"Trovate {DService.RedisCountKey(groupHash)} Hash per {groupHash}";
|
||||
stopWatch.Stop();
|
||||
// Get the elapsed time as a TimeSpan value.
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
// accodo tempo!
|
||||
answ += $"{Environment.NewLine}Elapsed: {ts.TotalMilliseconds}ms";
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lettura tab StateMachineIngressi
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("StateMachineIn")]
|
||||
public string tSMI(int? id)
|
||||
public string StateMachineIn(int? id)
|
||||
{
|
||||
string answ = "ND";
|
||||
long splitTime = 0;
|
||||
@@ -273,83 +354,24 @@ namespace MP.IOC.Controllers
|
||||
// ritorno
|
||||
return answ;
|
||||
}
|
||||
//// GET BENCH/fSMI/18?idxMS=1&valore=1
|
||||
//public string fSMI(int? id, int? idxMS, int? valore)
|
||||
//{
|
||||
// string answ = "ND";
|
||||
// Stopwatch stopWatch = new Stopwatch();
|
||||
// stopWatch.Start();
|
||||
// // se id nullo --> KO!
|
||||
// if (id == null)
|
||||
// {
|
||||
// answ = "KO";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // recupero dati x sapere quale famiglia SMI è necessaria e quale stato / segnale si sia ricevuto
|
||||
// int idxFamIn = Convert.ToInt32(id);
|
||||
// int idxMicroStato = Convert.ToInt32(idxMS);
|
||||
// int valIOB = Convert.ToInt32(valore);
|
||||
// // recupero microstato macchina da chiave relativa
|
||||
// answ = "";
|
||||
// try
|
||||
// {
|
||||
// // verifico se ci sia in memoria tab della fam macchina relativa (sennò carico)
|
||||
// string fiHASH = DataLayer.hSMI(idxFamIn);
|
||||
// string outVal = "";
|
||||
// bool trovato = memLayer.ML.redHashPresentSz(fiHASH);
|
||||
// if (!trovato)
|
||||
// {
|
||||
// // ricarico tabella!
|
||||
// KeyValuePair<string, string>[] valori = DataLayerObj.mTabSMI(idxFamIn);
|
||||
// answ = string.Format("Ricaricata SMI per famiglia {0}<br/>", fiHASH);
|
||||
// }
|
||||
// answ += string.Format("Trovata {0} Hash per {1}<br />", memLayer.ML.redCountKey(fiHASH), fiHASH);
|
||||
// // recupero singolo valore (stringa) x chiave
|
||||
// outVal = DataLayerObj.valoreSMI(idxFamIn, idxMicroStato, valIOB);
|
||||
// // mostro output
|
||||
// answ += string.Format("idxFamIN: {0} | idxMS: {1} | valIOB: {2} | out: {3} <br/>", idxFamIn, idxMicroStato, valIOB, outVal);
|
||||
// }
|
||||
// catch
|
||||
// { }
|
||||
// }
|
||||
// stopWatch.Stop();
|
||||
// // Get the elapsed time as a TimeSpan value.
|
||||
// TimeSpan ts = stopWatch.Elapsed;
|
||||
// // accodo tempo!
|
||||
// answ += string.Format("<hr/>Total Time Elapsed: {0}ms", ts.TotalMilliseconds);
|
||||
// // ritorno
|
||||
// return answ;
|
||||
//}
|
||||
//// GET BENCH/INSEN/2004
|
||||
//public string INSEN(string id)
|
||||
//{
|
||||
// string answ = "ND";
|
||||
// Stopwatch stopWatch = new Stopwatch();
|
||||
// stopWatch.Start();
|
||||
// // se id nullo --> KO!
|
||||
// if (id == null)
|
||||
// {
|
||||
// answ = "KO";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // recupero microstato macchina da chiave relativa
|
||||
// answ = "";
|
||||
// try
|
||||
// {
|
||||
// answ += string.Format("Macchina {0}, insEnabled {1}<br />", id, DataLayerObj.insEnab(id));
|
||||
// }
|
||||
// catch
|
||||
// { }
|
||||
// }
|
||||
// stopWatch.Stop();
|
||||
// // Get the elapsed time as a TimeSpan value.
|
||||
// TimeSpan ts = stopWatch.Elapsed;
|
||||
// // accodo tempo!
|
||||
// answ += string.Format("<hr/>Total Time Elapsed: {0}ms", ts.TotalMilliseconds);
|
||||
// // ritorno
|
||||
// return answ;
|
||||
//}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
/// <summary>
|
||||
/// Dataservice x accesso DB
|
||||
/// </summary>
|
||||
protected MpDataService DService { get; set; }
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static IConfiguration _configuration = null!;
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user