using MapoDb; using SteamWare; using System; using System.Collections.Generic; using System.Diagnostics; using System.Web.Mvc; using MP_IO.Interfaces; namespace MP_IO.Controllers { public class BENCHController : Controller, IBENCHService { #region Public Methods // 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("
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 { Dictionary valori = DataLayerObj.mDatiMacchine(id); foreach (var item in valori) { answ += string.Format("{0}|{1}
", item.Key, item.Value); } } catch { } } stopWatch.Stop(); // Get the elapsed time as a TimeSpan value. TimeSpan ts = stopWatch.Elapsed; // accodo tempo! answ += string.Format("
Elapsed: {0}ms", 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[] valori = DataLayerObj.mTabSMI(idxFamIn); answ = string.Format("Ricaricata SMI per famiglia {0}
", fiHASH); } answ += string.Format("Trovata {0} Hash per {1}
", 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}
", idxFamIn, idxMicroStato, valIOB, outVal); } catch { } } stopWatch.Stop(); // Get the elapsed time as a TimeSpan value. TimeSpan ts = stopWatch.Elapsed; // accodo tempo! answ += string.Format("
Total Time Elapsed: {0}ms", ts.TotalMilliseconds); // ritorno return answ; } // GET: IOB (è un check alive) public string Index() { return "OK"; } // 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}
", id, DataLayerObj.insEnab(id)); } catch { } } stopWatch.Stop(); // Get the elapsed time as a TimeSpan value. TimeSpan ts = stopWatch.Elapsed; // accodo tempo! answ += string.Format("
Total Time 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[] valori = new KeyValuePair[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("
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[] valori = new KeyValuePair[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("numero", i.ToString()); valori[1] = new KeyValuePair("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("
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[] valori = new KeyValuePair[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}
", item.Key, item.Value); } } catch { } } stopWatch.Stop(); // Get the elapsed time as a TimeSpan value. TimeSpan ts = stopWatch.Elapsed; // accodo tempo! answ += string.Format("
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[] valori = DataLayerObj.mTabSMI(idxFamIn); splitTime = stopWatch.ElapsedMilliseconds; foreach (var item in valori) { answ += string.Format("{0}|{1}
", item.Key, item.Value); } } catch { } } stopWatch.Stop(); // Get the elapsed time as a TimeSpan value. TimeSpan ts = stopWatch.Elapsed; // accodo tempo! answ += string.Format("
ReadTime: {0}ms
Total Time Elapsed: {1}ms", splitTime, ts.TotalMilliseconds); // ritorno return answ; } #endregion Public Methods #region Private Fields /// /// Oggetto datalayer specifico /// private DataLayer DataLayerObj = new DataLayer(); #endregion Private Fields } }