345 lines
12 KiB
C#
345 lines
12 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MP.IOC.Data;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
using NLog.Fluent;
|
|
using System.Diagnostics;
|
|
|
|
namespace MP.IOC.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class BenchController : ControllerBase
|
|
{
|
|
public BenchController(IConfiguration configuration, MpDataService DataService)
|
|
{
|
|
Log.Info("Starting MpDataService INIT");
|
|
_configuration = configuration;
|
|
DService = DataService;
|
|
Log.Info("Avviata classe Recipe");
|
|
}
|
|
|
|
private static IConfiguration _configuration = null!;
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
/// <summary>
|
|
/// Dataservice x accesso DB
|
|
/// </summary>
|
|
protected MpDataService DService { get; set; }
|
|
|
|
//// GET: IOB (è un check alive)
|
|
//public string Index()
|
|
//{
|
|
// return "OK";
|
|
//}
|
|
|
|
/// <summary>
|
|
/// pulizia dati
|
|
/// api/Bench/RClean?id=100
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("RClean")]
|
|
public string RCLEAN(int? id)
|
|
{
|
|
string answ = "ND";
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
// se id nullo --> KO!
|
|
if (id == null)
|
|
{
|
|
answ = "KO";
|
|
}
|
|
else
|
|
{
|
|
string chiave;
|
|
KeyValuePair<string, string>[] valori = new KeyValuePair<string, string>[2];
|
|
try
|
|
{
|
|
// svuoto i precedenti hash... CICLO!
|
|
for (int i = 0; i < id; i++)
|
|
{
|
|
chiave = string.Format("test:{0}", i);
|
|
DService.RedisDelKey(chiave);
|
|
}
|
|
answ = "OK";
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
stopWatch.Stop();
|
|
// Get the elapsed time as a TimeSpan value.
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
// accodo tempo!
|
|
answ += $"Elapsed: {ts.TotalMilliseconds}ms";
|
|
// ritorno
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Setup dati di test hash
|
|
/// api/Bench/RSetup?id=100
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("RSetup")]
|
|
public string RSETUP(int? id)
|
|
{
|
|
string answ = "ND";
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
// se id nullo --> KO!
|
|
if (id == null)
|
|
{
|
|
answ = "KO";
|
|
}
|
|
else
|
|
{
|
|
string chiave;
|
|
KeyValuePair<string, string>[] valori = new KeyValuePair<string, string>[2];
|
|
try
|
|
{
|
|
// salvo il datasetet come insieme di hash in redis...
|
|
for (int i = 0; i < id; i++)
|
|
{
|
|
chiave = string.Format("test:{0}", i);
|
|
valori[0] = new KeyValuePair<string, string>("numero", i.ToString());
|
|
valori[1] = new KeyValuePair<string, string>("doppio", (i * 2).ToString());
|
|
DService.RedisSetHash(chiave, valori);
|
|
}
|
|
answ = "OK";
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
stopWatch.Stop();
|
|
// Get the elapsed time as a TimeSpan value.
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
// accodo tempo!
|
|
answ += $"Elapsed: {ts.TotalMilliseconds}ms";
|
|
// ritorno
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Recupero singolo valore hash
|
|
/// api/Bench/RSingleHash?id=50
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("RSingleHash")]
|
|
public string RSH(int? id)
|
|
{
|
|
string answ = "ND";
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
// se id nullo --> KO!
|
|
if (id == null)
|
|
{
|
|
answ = "KO";
|
|
}
|
|
else
|
|
{
|
|
answ = "";
|
|
string chiave;
|
|
KeyValuePair<string, string>[] valori = new KeyValuePair<string, string>[2];
|
|
try
|
|
{
|
|
// ora restituisco record completo dell'hash con ID indicato
|
|
chiave = string.Format("test:{0}", id);
|
|
valori = DService.RedisGetHash(chiave);
|
|
foreach (var item in valori)
|
|
{
|
|
answ += string.Format("{0}|{1}<br/>", item.Key, item.Value);
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
stopWatch.Stop();
|
|
// Get the elapsed time as a TimeSpan value.
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
// accodo tempo!
|
|
answ += $"Elapsed: {ts.TotalMilliseconds}ms";
|
|
// 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.GetCurrMSFDMacc(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 += $"Elapsed: {ts.TotalMilliseconds}ms";
|
|
// ritorno
|
|
return answ;
|
|
}
|
|
//// GET BENCH/CNTKEY/KEY_NAME
|
|
//public string CNTKEY(string id)
|
|
//{
|
|
// string answ = "ND";
|
|
// if (id == null) id = "";
|
|
// Stopwatch stopWatch = new Stopwatch();
|
|
// stopWatch.Start();
|
|
// // conto quanti oggetti DTMac ho in memoria...
|
|
// string groupHash = DataLayer.mHash("");
|
|
// if (id.Length > 0)
|
|
// {
|
|
// groupHash += id + ":";
|
|
// }
|
|
// groupHash += "*";
|
|
// answ = string.Format("Trovate {0} Hash per {1}", memLayer.ML.redCountKey(groupHash), groupHash);
|
|
// stopWatch.Stop();
|
|
// // Get the elapsed time as a TimeSpan value.
|
|
// TimeSpan ts = stopWatch.Elapsed;
|
|
// // accodo tempo!
|
|
// answ += $"Elapsed: {ts.TotalMilliseconds}ms";
|
|
// // ritorno
|
|
// return answ;
|
|
//}
|
|
//// GET BENCH/tSMI/1
|
|
//public string tSMI(int? id)
|
|
//{
|
|
// string answ = "ND";
|
|
// long splitTime = 0;
|
|
// Stopwatch stopWatch = new Stopwatch();
|
|
// stopWatch.Start();
|
|
// // se id nullo --> KO!
|
|
// if (id == null)
|
|
// {
|
|
// answ = "KO";
|
|
// }
|
|
// else
|
|
// {
|
|
// int idxFamIn = Convert.ToInt32(id);
|
|
// answ = "";
|
|
// try
|
|
// {
|
|
// KeyValuePair<string, string>[] valori = DataLayerObj.mTabSMI(idxFamIn);
|
|
// splitTime = stopWatch.ElapsedMilliseconds;
|
|
// foreach (var item in valori)
|
|
// {
|
|
// answ += string.Format("{0}|{1}<br/>", item.Key, item.Value);
|
|
// }
|
|
// }
|
|
// catch
|
|
// { }
|
|
// }
|
|
// stopWatch.Stop();
|
|
// // Get the elapsed time as a TimeSpan value.
|
|
// TimeSpan ts = stopWatch.Elapsed;
|
|
// // accodo tempo!
|
|
// answ += string.Format("<hr/>ReadTime: {0}ms<br>Total Time Elapsed: {1}ms", splitTime, ts.TotalMilliseconds);
|
|
// // 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;
|
|
//}
|
|
}
|
|
}
|