diff --git a/MP.MONO.Data/Constants.cs b/MP.MONO.Data/Constants.cs new file mode 100644 index 0000000..858aedc --- /dev/null +++ b/MP.MONO.Data/Constants.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace MP.MONO.Data +{ + //// + //// This is here so CodeMaid doesn't reorganize this document + //// + public class Constants + { + + #region Public Fields + + public static readonly string BASE_HASH = "MAPO-MONO"; + public static readonly string BASE_PATH = Directory.GetCurrentDirectory(); + //public static readonly string BASE_PATH = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) ?? Directory.GetCurrentDirectory(); + + // Configurazioni + public static readonly string STATUS_CONF_KEY = $"{BASE_HASH}:Conf:Status"; + public static readonly string MODE_CONF_KEY = $"{BASE_HASH}:Conf:Mode"; + + // Dati correnti + public static readonly string ACT_LOG_CURR_KEY = $"{BASE_HASH}:Current:ActivityLog"; + public static readonly string ALARM_CURR_KEY = $"{BASE_HASH}:Current:Alarms"; + public static readonly string EVENT_LOG_CURR_KEY = $"{BASE_HASH}:Current:EventsLog"; + public static readonly string MACH_STATS_CURR_KEY = $"{BASE_HASH}:Current:MachStats"; + public static readonly string MAINT_STATS_CURR_KEY = $"{BASE_HASH}:Current:Maintenance"; + public static readonly string PARAMS_CURR_KEY = $"{BASE_HASH}:Current:Parameters"; + public static readonly string PROD_CURR_KEY = $"{BASE_HASH}:Current:Production"; + public static readonly string STATUS_CURR_KEY = $"{BASE_HASH}:Current:Status"; + public static readonly string TOOLS_CURR_KEY = $"{BASE_HASH}:Current:Tools"; + + #endregion Public Fields + } +} diff --git a/MP.MONO.Data/Utils.cs b/MP.MONO.Data/Utils.cs index 4cb1ed4..eec3aa8 100644 --- a/MP.MONO.Data/Utils.cs +++ b/MP.MONO.Data/Utils.cs @@ -8,6 +8,7 @@ namespace MP.MONO.Data { public class Utils { +#if false /// /// Hash Redis x la chiave richiesta (es StatusMacchina, StateMachineIngressi, ...) /// @@ -16,6 +17,7 @@ namespace MP.MONO.Data public static string mHash(string keyName) { return $"MAPO-MONO:{keyName}"; - } + } +#endif } } diff --git a/MP.MONO.UI/Components/CmpTop.razor b/MP.MONO.UI/Components/CmpTop.razor index 428e9b6..8c27eca 100644 --- a/MP.MONO.UI/Components/CmpTop.razor +++ b/MP.MONO.UI/Components/CmpTop.razor @@ -15,11 +15,11 @@
-
Machine Status
+
Machine Status
@statusDesc
-
Machine Mode
+
Machine Mode
@modeDesc
diff --git a/MP.MONO.UI/Data/CurrentDataService.cs b/MP.MONO.UI/Data/CurrentDataService.cs index 7ac1d7d..e19404a 100644 --- a/MP.MONO.UI/Data/CurrentDataService.cs +++ b/MP.MONO.UI/Data/CurrentDataService.cs @@ -106,7 +106,7 @@ namespace MP.MONO.UI.Data public async Task> getStats() { List? dbResult = new List(); - string cacheKey = Utils.mHash("Machine:MachStats:Current"); + string cacheKey = Constants.MACH_STATS_CURR_KEY; string rawData = await redisDb.StringGetAsync(cacheKey); if (!string.IsNullOrEmpty(rawData)) { @@ -122,7 +122,7 @@ namespace MP.MONO.UI.Data public async Task> MachineParameters() { List? dbResult = new List(); - string cacheKey = Utils.mHash("Machine:Parameters:Current"); + string cacheKey = Constants.PARAMS_CURR_KEY; string rawData = await redisDb.StringGetAsync(cacheKey); if (!string.IsNullOrEmpty(rawData)) { @@ -138,7 +138,7 @@ namespace MP.MONO.UI.Data public async Task getProd() { ProductionDTO? dbResult = new ProductionDTO(); - string cacheKey = Utils.mHash("Machine:Production:Current"); + string cacheKey = Constants.PROD_CURR_KEY; string rawData = await redisDb.StringGetAsync(cacheKey); if (!string.IsNullOrEmpty(rawData)) { @@ -154,7 +154,7 @@ namespace MP.MONO.UI.Data public async Task getStatus() { MachineDTO? dbResult = new MachineDTO(); - string cacheKey = Utils.mHash("Machine:Status:Current"); + string cacheKey = Constants.STATUS_CURR_KEY; string rawData = await redisDb.StringGetAsync(cacheKey); if (!string.IsNullOrEmpty(rawData)) { @@ -169,7 +169,7 @@ namespace MP.MONO.UI.Data public async Task> getStatusList() { List? dbResult = new List(); - string cacheKey = Utils.mHash("Conf:Status"); + string cacheKey = Constants.STATUS_CONF_KEY; string rawData = await redisDb.StringGetAsync(cacheKey); if (!string.IsNullOrEmpty(rawData)) { @@ -184,7 +184,7 @@ namespace MP.MONO.UI.Data public async Task> getModesList() { List? dbResult = new List(); - string cacheKey = Utils.mHash("Conf:Mode"); + string cacheKey = Constants.MODE_CONF_KEY; string rawData = await redisDb.StringGetAsync(cacheKey); if (!string.IsNullOrEmpty(rawData)) { @@ -200,7 +200,7 @@ namespace MP.MONO.UI.Data public async Task> getMaintenance() { List? dbResult = new List(); - string cacheKey = Utils.mHash("Machine:Maintenance:Current"); + string cacheKey = Constants.MAINT_STATS_CURR_KEY; string rawData = await redisDb.StringGetAsync(cacheKey); if (!string.IsNullOrEmpty(rawData)) { @@ -215,7 +215,7 @@ namespace MP.MONO.UI.Data public async Task> getTools() { List? dbResult = new List(); - string cacheKey = Utils.mHash("Machine:Tools:Current"); + string cacheKey = Constants.TOOLS_CURR_KEY; string rawData = await redisDb.StringGetAsync(cacheKey); if (!string.IsNullOrEmpty(rawData)) { @@ -230,7 +230,7 @@ namespace MP.MONO.UI.Data public async Task> getActLog() { List? dbResult = new List(); - string cacheKey = Utils.mHash("Machine:ActivityLog:Current"); + string cacheKey = Constants.ACT_LOG_CURR_KEY; string rawData = await redisDb.StringGetAsync(cacheKey); if (!string.IsNullOrEmpty(rawData)) { @@ -245,7 +245,7 @@ namespace MP.MONO.UI.Data public async Task> getEventHist() { List? dbResult = new List(); - string cacheKey = Utils.mHash("Machine:Events:Current"); + string cacheKey = Constants.EVENT_LOG_CURR_KEY; string rawData = await redisDb.StringGetAsync(cacheKey); if (!string.IsNullOrEmpty(rawData)) { diff --git a/MachineSim/Program.cs b/MachineSim/Program.cs index 0a1a834..5323c4b 100644 --- a/MachineSim/Program.cs +++ b/MachineSim/Program.cs @@ -68,7 +68,7 @@ void setupConf() { List? statusList = JsonConvert.DeserializeObject>(rawData); // salvo in redis! - redisDb.StringSetAsync(Utils.mHash("Conf:Status"), JsonConvert.SerializeObject(statusList)); + redisDb.StringSetAsync(Constants.STATUS_CONF_KEY, JsonConvert.SerializeObject(statusList)); } } // leggo e salvo conf modi @@ -80,7 +80,7 @@ void setupConf() { var localObj = JsonConvert.DeserializeObject>(rawData); // salvo in redis! - redisDb.StringSetAsync(Utils.mHash("Conf:Mode"), JsonConvert.SerializeObject(localObj)); + redisDb.StringSetAsync(Constants.MODE_CONF_KEY, JsonConvert.SerializeObject(localObj)); } } } @@ -89,8 +89,7 @@ void saveAndSendMessage(string memKey, string value, string notifyChannel, strin { // effettuo la scrittura nell'area di memoria indicata redisDb.StringSetAsync(memKey, value); - //redis.GetDatabase().SetAdd(memKey, value); - //redis.GetDatabase().StringSetAsync(memKey, value); + //redisDb.SetAdd(memKey, value); // invio notifica tramite il canale richiesto sub.Publish(notifyChannel, message); @@ -118,7 +117,7 @@ void simAlarms() } string rawData = JsonConvert.SerializeObject(activeAlarms); // decodifico allarme e lo trasformo in List di allarmi attivi... - saveAndSendMessage(Utils.mHash("Machine:Alarms:Current"), rawData, "allarms", rawData); + saveAndSendMessage(Constants.ALARM_CURR_KEY, rawData, "allarms", rawData); // attesa random Thread.Sleep(rand.Next(minPeriod, maxPeriod)); } while (true); @@ -133,7 +132,7 @@ void simParameters() { var newParams = currSimGen.getParameters(); string rawData = JsonConvert.SerializeObject(newParams); - saveAndSendMessage(Utils.mHash("Machine:Parameters:Current"), rawData, "parameters", rawData); + saveAndSendMessage(Constants.PARAMS_CURR_KEY, rawData, "parameters", rawData); // attesa random Thread.Sleep(rand.Next(minPeriod, maxPeriod)); } while (true); @@ -149,7 +148,7 @@ void simStatus() // recupero uno stato simulato var newStatus = currSimGen.getStatus(); string rawData = JsonConvert.SerializeObject(newStatus); - saveAndSendMessage(Utils.mHash("Machine:Status:Current"), rawData, "status", rawData); + saveAndSendMessage(Constants.STATUS_CURR_KEY, rawData, "status", rawData); // attesa random Thread.Sleep(rand.Next(minPeriod, maxPeriod)); @@ -166,7 +165,7 @@ void simProd() // recupero uno stato simulato var newStatus = currSimGen.getProd(); string rawData = JsonConvert.SerializeObject(newStatus); - saveAndSendMessage(Utils.mHash("Machine:Production:Current"), rawData, "production", rawData); + saveAndSendMessage(Constants.PROD_CURR_KEY, rawData, "production", rawData); // attesa random Thread.Sleep(rand.Next(minPeriod, maxPeriod)); @@ -183,7 +182,7 @@ void simMachStat() // recupero uno stato simulato var newVal = currSimGen.getProdStats(); string rawData = JsonConvert.SerializeObject(newVal); - saveAndSendMessage(Utils.mHash("Machine:MachStats:Current"), rawData, "machstats", rawData); + saveAndSendMessage(Constants.MACH_STATS_CURR_KEY, rawData, "machstats", rawData); // attesa random Thread.Sleep(rand.Next(minPeriod, maxPeriod)); @@ -200,7 +199,7 @@ void simMaint() // recupero uno stato simulato var newVal = currSimGen.getMaint(); string rawData = JsonConvert.SerializeObject(newVal); - saveAndSendMessage(Utils.mHash("Machine:Maintenance:Current"), rawData, "maintenance", rawData); + saveAndSendMessage(Constants.MAINT_STATS_CURR_KEY, rawData, "maintenance", rawData); // attesa random Thread.Sleep(rand.Next(minPeriod, maxPeriod)); @@ -217,7 +216,7 @@ void simTools() // recupero uno stato simulato var newVal = currSimGen.getTools(); string rawData = JsonConvert.SerializeObject(newVal); - saveAndSendMessage(Utils.mHash("Machine:Tools:Current"), rawData, "tools", rawData); + saveAndSendMessage(Constants.TOOLS_CURR_KEY, rawData, "tools", rawData); // attesa random Thread.Sleep(rand.Next(minPeriod, maxPeriod)); @@ -234,7 +233,7 @@ void simEvents() // recupero uno stato simulato var newVal = currSimGen.getEvents(); string rawData = JsonConvert.SerializeObject(newVal); - saveAndSendMessage(Utils.mHash("Machine:Events:Current"), rawData, "events", rawData); + saveAndSendMessage(Constants.EVENT_LOG_CURR_KEY, rawData, "events", rawData); // attesa random Thread.Sleep(rand.Next(minPeriod, maxPeriod)); @@ -251,7 +250,7 @@ void simActivityLog() // recupero uno stato simulato var newVal = currSimGen.getActLog(); string rawData = JsonConvert.SerializeObject(newVal); - saveAndSendMessage(Utils.mHash("Machine:ActivityLog:Current"), rawData, "activitylog", rawData); + saveAndSendMessage(Constants.ACT_LOG_CURR_KEY, rawData, "activitylog", rawData); // attesa random Thread.Sleep(rand.Next(minPeriod, maxPeriod));