ri-ordinamento region e pulizia codice x fix finale interfacce

This commit is contained in:
Samuele Locatelli
2026-04-02 18:29:09 +02:00
parent c582b88e4a
commit a9983d141d
5 changed files with 367 additions and 308 deletions
+293 -278
View File
@@ -8,299 +8,314 @@ using MP_IO.Interfaces;
namespace MP_IO.Controllers
{
public class BENCHController : Controller, IBENCHService
{
/// <summary>
/// Oggetto datalayer specifico
/// </summary>
DataLayer DataLayerObj = new DataLayer();
public class BENCHController : Controller, IBENCHService
{
#region Public Methods
// GET: IOB (è un check alive)
public string Index()
{
return "OK";
}
// GET BENCH/CNTKEY/test
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 = 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/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
// GET BENCH/DTMAC/SIMUL_01
public string DTMAC(string id)
{
// svuoto i precedenti hash... CICLO!
for (int i = 0; i < id; i++)
{
chiave = string.Format("test:{0}", i);
memLayer.ML.redDelKey(chiave);
}
answ = "OK";
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 = DataLayerObj.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;
}
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
// GET BENCH/fSMI/18?idxMS=1&valore=1
public string fSMI(int? id, int? idxMS, int? valore)
{
// 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";
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;
}
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
// GET: IOB (è un check alive)
public string Index()
{
// 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);
}
return "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/DTMAC/SIMUL_01
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
// GET BENCH/INSEN/2004
public string INSEN(string id)
{
Dictionary<string, string> valori = DataLayerObj.mDatiMacchine(id);
foreach (var item in valori)
{
answ += string.Format("{0}|{1}<br/>", item.Key, item.Value);
}
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;
}
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/test
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 = 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/60
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
// GET BENCH/RCLEAN/100
public string RCLEAN(int? id)
{
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);
}
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;
}
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
// GET BENCH/RSETUP/100
public string RSETUP(int? id)
{
// 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);
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());
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;
}
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
// GET BENCH/RSH/100
public string RSH(int? id)
{
answ += string.Format("Macchina {0}, insEnabled {1}<br />", id, DataLayerObj.insEnab(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;
}
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/tSMI/60
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;
}
#endregion Public Methods
#region Private Fields
/// <summary>
/// Oggetto datalayer specifico
/// </summary>
private DataLayer DataLayerObj = new DataLayer();
#endregion Private Fields
}
}
}
+9 -7
View File
@@ -222,9 +222,6 @@ namespace MP_IO.Controllers
return answ;
}
protected static DataLayer DataLayerMan = new DataLayer();
/// <summary>
/// Processa una chiamata POST per l'invio di un array Json di oggetti input (EVENTI)
/// POST: IOB/evListJson/SIMUL_03
@@ -2599,6 +2596,12 @@ namespace MP_IO.Controllers
#endregion Public Methods
#region Protected Fields
protected static DataLayer DataLayerMan = new DataLayer();
#endregion Protected Fields
#region Private Methods
/// <summary>
@@ -2677,7 +2680,7 @@ namespace MP_IO.Controllers
answ = "NO";
}
// leggo parametri correnti...
DateTime adesso= DateTime.Now;
DateTime adesso = DateTime.Now;
try
{
List<objItem> currParams = DataLayerObj.getCurrObjItems(id);
@@ -2709,9 +2712,8 @@ namespace MP_IO.Controllers
else
{
// richiesto 10 sec prima...
trovato.lastRequest= adesso.AddSeconds(-10);
trovato.lastRequest = adesso.AddSeconds(-10);
}
}
// altrimenti AGGIUNGO (READ ONLY)...
else
@@ -2745,4 +2747,4 @@ namespace MP_IO.Controllers
#endregion Private Methods
}
}
}
+24 -20
View File
@@ -2,11 +2,33 @@ namespace MP_IO.Interfaces
{
public interface IBENCHService
{
#region Public Methods
/// <summary>
/// GET BENCH/CNTKEY/test
/// </summary>
string CNTKEY(string id);
/// <summary>
/// GET BENCH/DTMAC/SIMUL_01
/// </summary>
string DTMAC(string id);
/// <summary>
/// GET BENCH/fSMI/18?idxMS=1&valore=1
/// </summary>
string fSMI(int? id, int? idxMS, int? valore);
/// <summary>
/// GET: IOB (è un check alive)
/// </summary>
string Index();
/// <summary>
/// GET BENCH/INSEN/2004
/// </summary>
string INSEN(string id);
/// <summary>
/// GET BENCH/RCLEAN/100
/// </summary>
@@ -22,29 +44,11 @@ namespace MP_IO.Interfaces
/// </summary>
string RSH(int? id);
/// <summary>
/// GET BENCH/DTMAC/SIMUL_01
/// </summary>
string DTMAC(string id);
/// <summary>
/// GET BENCH/CNTKEY/test
/// </summary>
string CNTKEY(string id);
/// <summary>
/// GET BENCH/tSMI/60
/// </summary>
string tSMI(int? id);
/// <summary>
/// GET BENCH/fSMI/18?idxMS=1&valore=1
/// </summary>
string fSMI(int? id, int? idxMS, int? valore);
/// <summary>
/// GET BENCH/INSEN/2004
/// </summary>
string INSEN(string id);
#endregion Public Methods
}
}
}
+5 -2
View File
@@ -1,13 +1,16 @@
using System.Web.Mvc;
namespace MP_IO.Interfaces
{
public interface IHomeService
{
#region Public Methods
/// <summary>
/// GET: Home
/// </summary>
RedirectResult Index();
#endregion Public Methods
}
}
}
+36 -1
View File
@@ -6,6 +6,8 @@ namespace MP_IO.Interfaces
/// </summary>
public interface IIOBService
{
#region Public Methods
/// <param name="id"></param>
/// <param name="pName"></param>
/// <param name="pValue"></param>
@@ -360,6 +362,7 @@ namespace MP_IO.Interfaces
/// <param name="id"></param>
/// <returns></returns>
string getOdlAtDate(string id, string dateRif);
string getOptPar(string id);
/// <summary>
@@ -369,7 +372,9 @@ namespace MP_IO.Interfaces
/// <param name="id"></param>
/// <returns></returns>
string getPODL(string id, int idxPODL);
string getPOdlAct(string id);
string getPOdlNext(string id);
/// <summary>
@@ -378,33 +383,63 @@ namespace MP_IO.Interfaces
/// <param name="id"></param>
/// <returns></returns>
string getTask2Exe(string id);
string getXdlNum(string id, string CodXdl = "");
string Index();
string input(string id, string valore, string dtEve, string dtCurr, string cnt);
string liveJson(string id);
string liveRec(string id, string liveData);
string rawTransfJson(string id);
string remOptPar(string id, string pName);
string remTask2Exe(string id, string taskName);
string resetCurrODL(string id);
string saveConf(string id);
string saveConfYaml(string id);
string saveDataItems(string id);
string saveMachineIobConf(string id);
string savePzCountInc(string id, string qty);
string savePzCountIncAtDate(string id, string qty, string dtEve = "", string dtCurr = "");
string sendAlarmBankUpdate(string id, string memAddr, int index, int currStatus);
string sendReboot(string id, string mac);
string sendRebootGateway(string GWIP);
string setCounter(string id, string counter);
string setM2IOB(string id, string IOB_name);
string setObjItems(string id);
string setRedisHashDict(string id);
string slog(string id);
string takeFlogSnapshot(string id);
string ulog(string id, string flux, string valore, string dtEve, string dtCurr, string cnt, string matrOpr, string label, string valNum);
string ulogJson(string id);
string uploadFile(string id);
string upsertObjItems(string id);
#endregion Public Methods
}
}
}