129 lines
2.7 KiB
C#
129 lines
2.7 KiB
C#
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/<controller>
|
|
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/<controller>/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/<controller>
|
|
public void Post([FromBody]string value)
|
|
{
|
|
}
|
|
|
|
// PUT api/<controller>/5
|
|
public void Put(int id, [FromBody]string value)
|
|
{
|
|
}
|
|
|
|
// DELETE api/<controller>/5
|
|
public void Delete(int id)
|
|
{
|
|
}
|
|
/// <summary>
|
|
/// Effettua verifica connettività REDIS
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected bool checkRedis()
|
|
{
|
|
bool answ = false;
|
|
var testVal = memLayer.ML.redGetHash(memLayer.ML.ACBH);
|
|
answ = (testVal != null && testVal.Length > 0);
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Effettua verifica connettività DB
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco (da cache) dei comandi ammessi x BCode
|
|
/// </summary>
|
|
protected Dictionary<string, string> comandiAmmessiBCode
|
|
{
|
|
get
|
|
{
|
|
Dictionary<string, string> answ = new Dictionary<string, string>();
|
|
if (memLayer.ML.isInCacheObject("comandiAmmessiBCode"))
|
|
{
|
|
try
|
|
{
|
|
answ = JsonConvert.DeserializeObject<Dictionary<string, string>>(memLayer.ML.objCacheObj("comandiAmmessiBCode").ToString());
|
|
}
|
|
catch
|
|
{
|
|
answ = new Dictionary<string, string>();
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
}
|
|
} |