helpers gestione semafori Recipe + Warmers
This commit is contained in:
@@ -36,6 +36,10 @@ namespace Thermo.Active.Database.Controllers
|
||||
private const string machineEventKpis = "Events:Kpis";
|
||||
private const string machineMessagePath = "Events:Messages";
|
||||
|
||||
|
||||
private const string thermoSemRecipe = "Thermo:Semaphore:Recipe";
|
||||
private const string thermoSemWarmers = "Thermo:Semaphore:Warmers";
|
||||
|
||||
public static void WriteProductionNotification(uint ProductionProcess, string Notification)
|
||||
{
|
||||
string redisHash = redUtil.man.redHash(redisNotificationAddress).Replace("%NN%", ProductionProcess.ToString("00"));
|
||||
@@ -246,5 +250,89 @@ namespace Thermo.Active.Database.Controllers
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Imposta semaforo Recipe
|
||||
/// </summary>
|
||||
/// <param name="doLock">true: imposto lock per 5 sec, false: tolgo lock (stringa vuota)</param>
|
||||
/// <returns></returns>
|
||||
public static bool setRecipeReadSem(bool doLock)
|
||||
{
|
||||
return setSemaphore(doLock, redUtil.man.redHash(thermoSemRecipe));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce semaforo Recipe
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static bool getRecipeReadSem
|
||||
{
|
||||
get
|
||||
{
|
||||
return getSemaphore(redUtil.man.redHash(thermoSemRecipe));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Imposta semaforo Warmers
|
||||
/// </summary>
|
||||
/// <param name="doLock">true: imposto lock per 5 sec, false: tolgo lock (stringa vuota)</param>
|
||||
/// <returns></returns>
|
||||
public static bool setWarmersReadSem(bool doLock)
|
||||
{
|
||||
return setSemaphore(doLock, redUtil.man.redHash(thermoSemWarmers));
|
||||
}
|
||||
/// <summary>
|
||||
/// Restituisce semaforo Warmers
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static bool getWarmersReadSem
|
||||
{
|
||||
get
|
||||
{
|
||||
return getSemaphore(redUtil.man.redHash(thermoSemWarmers));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gestione generica SET semaforo
|
||||
/// </summary>
|
||||
/// <param name="doLock"></param>
|
||||
/// <param name="redisHash"></param>
|
||||
/// <returns></returns>
|
||||
private static bool setSemaphore(bool doLock, string redisHash)
|
||||
{
|
||||
bool answ = true;
|
||||
int ttlSec = 5;
|
||||
string rawData = $"{DateTime.Now}";
|
||||
try
|
||||
{
|
||||
if (doLock)
|
||||
{
|
||||
// imposto lock
|
||||
answ = redUtil.man.setRSV(redisHash, rawData, ttlSec);
|
||||
}
|
||||
else
|
||||
{
|
||||
// metto empty string a 1 sec
|
||||
answ = redUtil.man.setRSV(redisHash, "", 1);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Gestione generica GET semafoto
|
||||
/// </summary>
|
||||
/// <param name="redisHash"></param>
|
||||
/// <returns></returns>
|
||||
private static bool getSemaphore(string redisHash)
|
||||
{
|
||||
bool answ = true;
|
||||
string rawData = redUtil.man.getRSV(redisHash);
|
||||
// se non nulla --> ho semaforo!
|
||||
answ = !string.IsNullOrEmpty(rawData);
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user