Files
MoonPro.net/MP-IO/Controllers/BENCH.cs
T
2017-10-03 10:33:53 +02:00

302 lines
8.4 KiB
C#

using MapoDb;
using SteamWare;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Web.Mvc;
namespace MP_IO.Controllers
{
public class BENCHController : Controller
{
// GET: IOB (è un check alive)
public string Index()
{
return "OK";
}
// GET BENCH/RCLEAN/100
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);
memLayer.ML.redDelKey(chiave);
}
answ = "OK";
}
catch
{ }
}
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
// accodo tempo!
answ += string.Format("<hr/>Elapsed: {0}ms", ts.TotalMilliseconds);
// ritorno
return answ;
}
// GET BENCH/RSETUP/100
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
{
// recupero tutti i record della tabella
// 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());
memLayer.ML.redSaveHash(chiave, valori);
}
answ = "OK";
}
catch
{ }
}
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
// accodo tempo!
answ += string.Format("<hr/>Elapsed: {0}ms", ts.TotalMilliseconds);
// ritorno
return answ;
}
// GET BENCH/RSH/100
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 = memLayer.ML.redGetHash(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 += string.Format("<hr/>Elapsed: {0}ms", ts.TotalMilliseconds);
// ritorno
return answ;
}
// GET BENCH/DTMAC/2004
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 = DataLayer.mDatiMacchine(id);
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/>Elapsed: {0}ms", ts.TotalMilliseconds);
// 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 += string.Format("<hr/>Elapsed: {0}ms", ts.TotalMilliseconds);
// 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 = DataLayer.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 = DataLayer.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 = DataLayer.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, DataLayer.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;
}
}
}