using Newtonsoft.Json; using SteamWare; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; namespace C_TRACK { public class HealthController : ApiController { // GET api/ public string Get() { string answ = ""; bool redisOk = checkRedis(); bool dbOk = checkDb(); if (redisOk) { if (dbOk) { answ = "HELLO"; } else { answ = "DB KO"; } } else { answ = "REDIS KO"; } return answ; } // GET api//5 public string Get(int id) { string answ = ""; bool redisOk = checkRedis(); bool dbOk = checkDb(); if (redisOk) { if (dbOk) { answ = $"HELLO {id}"; } else { answ = "DB KO"; } } else { answ = "REDIS KO"; } return answ; } // POST api/ public void Post([FromBody]string value) { } // PUT api//5 public void Put(int id, [FromBody]string value) { } // DELETE api//5 public void Delete(int id) { } /// /// Effettua verifica connettività REDIS /// /// protected bool checkRedis() { bool answ = false; var testVal = memLayer.ML.redGetHash(memLayer.ML.ACBH); answ = (testVal != null && testVal.Length > 0); return answ; } /// /// Effettua verifica connettività DB /// /// protected bool checkDb() { bool answ = false; // test lettura appConf... DS_Utility.ConfigDataTable tabDati = memLayer.ML.taConfig.GetData(); answ = (tabDati.Rows.Count > 0); // se NON avessi config --> controllo i comandi ammessi... if(!answ) { answ = comandiAmmessiBCode.Count > 0; } return answ; } /// /// Elenco (da cache) dei comandi ammessi x BCode /// protected Dictionary comandiAmmessiBCode { get { Dictionary answ = new Dictionary(); if (memLayer.ML.isInCacheObject("comandiAmmessiBCode")) { try { answ = JsonConvert.DeserializeObject>(memLayer.ML.objCacheObj("comandiAmmessiBCode").ToString()); } catch { answ = new Dictionary(); } } return answ; } } } }