diff --git a/Thermo.Active.Database/Controllers/RedisController.cs b/Thermo.Active.Database/Controllers/RedisController.cs index 74ec5ec5..bb5df791 100644 --- a/Thermo.Active.Database/Controllers/RedisController.cs +++ b/Thermo.Active.Database/Controllers/RedisController.cs @@ -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; } + /// + /// Imposta semaforo Recipe + /// + /// true: imposto lock per 5 sec, false: tolgo lock (stringa vuota) + /// + public static bool setRecipeReadSem(bool doLock) + { + return setSemaphore(doLock, redUtil.man.redHash(thermoSemRecipe)); + } + + + /// + /// Restituisce semaforo Recipe + /// + /// + public static bool getRecipeReadSem + { + get + { + return getSemaphore(redUtil.man.redHash(thermoSemRecipe)); + } + } + /// + /// Imposta semaforo Warmers + /// + /// true: imposto lock per 5 sec, false: tolgo lock (stringa vuota) + /// + public static bool setWarmersReadSem(bool doLock) + { + return setSemaphore(doLock, redUtil.man.redHash(thermoSemWarmers)); + } + /// + /// Restituisce semaforo Warmers + /// + /// + public static bool getWarmersReadSem + { + get + { + return getSemaphore(redUtil.man.redHash(thermoSemWarmers)); + } + } + + /// + /// Gestione generica SET semaforo + /// + /// + /// + /// + 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; + } + /// + /// Gestione generica GET semafoto + /// + /// + /// + 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; + } } }