using MapoDb; using SteamWare; using System; using System.Web.Mvc; namespace MP_IO.Controllers { public class IOBController : Controller { // GET: IOB (è un check alive) public string Index() { return "OK"; } // disabilitato: non vale la pena //// GET: IOB/enabled/5 - tenuta in cache per 5 sec... //[OutputCache(Duration = 5, VaryByParam = "id")] // GET: IOB/enabled/5 public string enabled(int? id) { string answ = "ND"; // se id nullo --> KO! if (id == null) { answ = "KO"; } else { int idx = 0; Int32.TryParse(id.ToString(), out idx); try { // verifico se sia abilitato INSERT x una data macchina if (MapoDb.MapoDb.obj.insEnabled(idx)) { answ = "OK"; } else { answ = "NO"; } } catch (Exception exc) { logger.lg.scriviLog(string.Format("Errore in enabled{0}{1}", Environment.NewLine, exc)); answ = "NO"; } } return answ; } // GET: IOB/slog/5 public string slog(int? id) { string answ = "ND"; // se id nullo --> KO! if (id == null) { answ = "KO"; } else { int idx = 0; Int32.TryParse(id.ToString(), out idx); try { // verifico se sia abilitato SignalLog x una data macchina if (MapoDb.MapoDb.obj.sLogEnabled(idx)) { answ = "OK"; } else { answ = "NO"; } } catch (Exception exc) { logger.lg.scriviLog(string.Format("Errore in sLog{0}{1}", Environment.NewLine, exc)); answ = "NO"; } } return answ; } // GET: IOB/input/5?valore=3&dtEve=20161223180600000&dtCurr=20161223180600000&cnt=999 public string input(string id, string valore, string dtEve, string dtCurr, string cnt) { string answ = ""; // formato yyyymmddHHMMSSnnn ovvero da anno a millisecondi if (cnt == null) cnt = "0"; DateTime dataOraEvento = DateTime.Now; if (memLayer.ML.CRI("_logLevel") > 6) { logger.lg.scriviLog(string.Format("Valori letti:{0}idxMacchina: {1}{0}valore: {2}{0}dtEve: {3}{0}dtCurr: {4}{0}cnt: {5}", Environment.NewLine, id, valore, dtEve, dtCurr, cnt), tipoLog.INFO); } try { answ = DataLayer.processInput(id, valore, dtEve, dtCurr, cnt); } catch (Exception exc) { logger.lg.scriviLog(string.Format("Errore in input{0}{1}", Environment.NewLine, exc)); answ = "NO"; } return answ; } // GET: IOB/setka/5 public string setka(int? id) { string answ = "ND"; // se id nullo --> KO! if (id == null) { answ = "KO"; } else { int idx = 0; Int32.TryParse(id.ToString(), out idx); try { MapoDb.MapoDb.obj.scriviKeepAlive(idx.ToString(), DateTime.Now); answ = MapoDb.MapoDb.obj.taKeepAlive.getByIdxMacchina(idx.ToString())[0].DataOraServer.ToString(); memLayer.ML.setRSV(string.Format("KA{0}", idx), DateTime.Now.ToString()); } catch (Exception exc) { logger.lg.scriviLog(string.Format("Errore in setka{0}{1}", Environment.NewLine, exc)); answ = "NO"; } } return answ; } // GET: IOB/getka/5 public string getka(int? id) { string answ = "ND"; // se id nullo --> KO! if (id == null) { answ = "KO"; } else { int idx = 0; Int32.TryParse(id.ToString(), out idx); try { answ = MapoDb.MapoDb.obj.taKeepAlive.getByIdxMacchina(idx.ToString())[0].DataOraServer.ToString(); } catch (Exception exc) { logger.lg.scriviLog(string.Format("Errore in getka{0}{1}", Environment.NewLine, exc)); answ = "NO"; } } return answ; } // GET: IOB/setredis/5 public string setredis(int? id) { string answ = "ND"; // se id nullo --> KO! if (id == null) { answ = "KO"; } else { int idx = 0; Int32.TryParse(id.ToString(), out idx); try { memLayer.ML.setRSV(string.Format("KA{0}", idx), DateTime.Now.ToString()); answ = memLayer.ML.getRSV(string.Format("KA{0}", idx)); } catch (Exception exc) { logger.lg.scriviLog(string.Format("Errore in setredis{0}{1}", Environment.NewLine, exc)); answ = "NO"; } } return answ; } // GET: IOB/getredis/5 public string getredis(int? id) { string answ = "ND"; // se id nullo --> KO! if (id == null) { answ = "KO"; } else { int idx = 0; Int32.TryParse(id.ToString(), out idx); try { answ = memLayer.ML.getRSV(string.Format("KA{0}", idx)); } catch (Exception exc) { logger.lg.scriviLog(string.Format("Errore in getredis{0}{1}", Environment.NewLine, exc)); answ = "NO"; } } return answ; } // GET: IOB/setrediscount/5 public string setrediscount(int? id) { string answ = "ND"; // se id nullo --> KO! if (id == null) { answ = "KO"; } else { int idx = 0; Int32.TryParse(id.ToString(), out idx); try { long count = memLayer.ML.setRCntI(string.Format("CNT{0}", idx)); answ = count.ToString(); } catch (Exception exc) { logger.lg.scriviLog(string.Format("Errore in setrediscount{0}{1}", Environment.NewLine, exc)); answ = "NO"; } } return answ; } // GET: IOB/getrediscount/5 public string getrediscount(int? id) { string answ = "ND"; // se id nullo --> KO! if (id == null) { answ = "KO"; } else { int idx = 0; Int32.TryParse(id.ToString(), out idx); try { int answInt = memLayer.ML.getRCnt(string.Format("CNT{0}", idx)); answ = answInt.ToString(); //answ = answ != "" ? answ : "0"; } catch (Exception exc) { logger.lg.scriviLog(string.Format("Errore in getrediscount{0}{1}", Environment.NewLine, exc)); answ = "NO"; } } return answ; } // GET: IOB/resetrediscount/5 public string resetrediscount(int? id) { string answ = "ND"; // se id nullo --> KO! if (id == null) { answ = "KO"; } else { int idx = 0; Int32.TryParse(id.ToString(), out idx); try { bool fatto = memLayer.ML.resetRCnt(string.Format("CNT{0}", idx)); answ = fatto ? "ZEROED" : "ERROR"; } catch (Exception exc) { logger.lg.scriviLog(string.Format("Errore in getrediscount{0}{1}", Environment.NewLine, exc)); answ = "NO"; } } return answ; } } }