diff --git a/Jenkinsfile b/Jenkinsfile index b716ea9..eda458e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,7 +15,7 @@ pipeline { /* calcolo numero versione... diverso x branch MASTER/DEVELOP */ script { - withEnv(['NEXT_BUILD_NUMBER=325']) { + withEnv(['NEXT_BUILD_NUMBER=326']) { // env.versionNumber = VersionNumber(versionNumberString : '2.0.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true) env.versionNumber = VersionNumber(versionNumberString : '2.0.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}') env.APP_NAME = 'SCMA' diff --git a/MTC_Adapter/OPC-UA-REDIS/AdapterRed.cs b/MTC_Adapter/OPC-UA-REDIS/AdapterRed.cs index d8d8bec..199db99 100644 --- a/MTC_Adapter/OPC-UA-REDIS/AdapterRed.cs +++ b/MTC_Adapter/OPC-UA-REDIS/AdapterRed.cs @@ -110,10 +110,17 @@ namespace OPC_UA_REDIS /// public void Begin() { - mBegun = true; - foreach (DataItemRed di in mDataItems) + if (redisSrvOk) { - di.Begin(); + mBegun = true; + foreach (DataItemRed di in mDataItems) + { + di.Begin(); + } + } + else + { + lg.Error("Errore: redis server NON disponibile (Begin)"); } } /// @@ -195,12 +202,19 @@ namespace OPC_UA_REDIS } if (together.Count > 0) { - // salvo su REDIS!!! - foreach (DataItemRed di in together) + if (redisSrvOk) { - hashKey = machineHash(di.Name); - hashVal = di.Value.ToString(); - saveHashKeyVal(hashKey, hashVal); + // salvo su REDIS!!! + foreach (DataItemRed di in together) + { + hashKey = machineHash(di.Name); + hashVal = di.Value.ToString(); + saveHashKeyVal(hashKey, hashVal); + } + } + else + { + lg.Error("Attenzione! server REDIS non disponibile (SendChanged:toghether)"); } } @@ -217,6 +231,7 @@ namespace OPC_UA_REDIS // finito mBegun = false; + } /// /// Salva hask KeyVal in REDIS @@ -250,11 +265,18 @@ namespace OPC_UA_REDIS // ora il valore delle chaivi diventa unavailable... hashVal = availStatus.UNAVAILABLE.ToString(); - // percorro tutto l'albero nodi item ed allarmi e SCRIVO!!!! - foreach (var item in itemNodes) + if (redisSrvOk) { - hashKey = machineHash(item.Key); - saveHashKeyVal(hashKey, hashVal); + // percorro tutto l'albero nodi item ed allarmi e SCRIVO!!!! + foreach (var item in itemNodes) + { + hashKey = machineHash(item.Key); + saveHashKeyVal(hashKey, hashVal); + } + } + else + { + lg.Error("Attenzione! server REDIS non disponibile (Stop)"); } } @@ -262,73 +284,65 @@ namespace OPC_UA_REDIS /// Avvio adapter (popolamento iniziale su redis...) /// public void Start() - { - if (redisSrvOk) + { // var accessorie + string hashKey = ""; + string hashVal = ""; + var list = new List>(); + string nLevel = ""; + // Imposto CONF + hashKey = redUtil.redHash("Adp:Vers"); + hashVal = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); + saveHashKeyVal(hashKey, hashVal); + hashKey = redUtil.redHash("Adp:Status"); + hashVal = "started"; + saveHashKeyVal(hashKey, hashVal); + hashKey = redUtil.redHash("Adp:Heartbeat"); + hashVal = DateTime.Now.ToString(); + saveHashKeyVal(hashKey, hashVal); + // allarmi CNC + hashKey = confHash("CNC"); + foreach (var item in elencoAllarmi) { - // var accessorie - string hashKey = ""; - string hashVal = ""; - var list = new List>(); - string nLevel = ""; - // Imposto CONF - hashKey = redUtil.redHash("Adp:Vers"); - hashVal = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); - saveHashKeyVal(hashKey, hashVal); - hashKey = redUtil.redHash("Adp:Status"); - hashVal = "started"; - saveHashKeyVal(hashKey, hashVal); - hashKey = redUtil.redHash("Adp:Heartbeat"); - hashVal = DateTime.Now.ToString(); - saveHashKeyVal(hashKey, hashVal); - // allarmi CNC - hashKey = confHash("CNC"); - foreach (var item in elencoAllarmi) + // se è PLC aggiungo + if (item.gruppo == "CNC") { - // se è PLC aggiungo - if (item.gruppo == "CNC") - { - nLevel = item.livello == "FAULT" ? "900" : "500"; - list.Add(new KeyValuePair(item.codNum, nLevel + "|" + item.descrizione)); - } - } - redUtil.redSaveHashList(hashKey, list); - // allarmi PLC - hashKey = confHash("PLC"); - foreach (var item in elencoAllarmi) - { - // se è PLC aggiungo - if (item.gruppo == "PLC") - { - nLevel = item.livello == "FAULT" ? "900" : "500"; - list.Add(new KeyValuePair(item.codNum, nLevel + "|" + item.descrizione)); - } - } - redUtil.redSaveHashList(hashKey, list); - - // DataModel --> salvo in redis! - hashKey = confHash("DataModel"); - hashVal = DataModel; - saveHashKeyVal(hashKey, hashVal); - - // imposto VETO - hashKey = vetoHash("CNC"); - hashVal = "0"; - saveHashKeyVal(hashKey, hashVal); - hashKey = vetoHash("PLC"); - hashVal = "0"; - saveHashKeyVal(hashKey, hashVal); - - // Imposto DATI: percorro tutto l'albero nodi item ed allarmi e SCRIVO!!!! - foreach (var item in itemNodes) - { - hashKey = machineHash(item.Key); - hashVal = availStatus.UNAVAILABLE.ToString(); // item.Value.cObject.ToString(); - saveHashKeyVal(hashKey, hashVal); + nLevel = item.livello == "FAULT" ? "900" : "500"; + list.Add(new KeyValuePair(item.codNum, nLevel + "|" + item.descrizione)); } } - else + redUtil.redSaveHashList(hashKey, list); + // allarmi PLC + hashKey = confHash("PLC"); + foreach (var item in elencoAllarmi) { - lg.Error("Attenzione! server REDIS non disponibile"); + // se è PLC aggiungo + if (item.gruppo == "PLC") + { + nLevel = item.livello == "FAULT" ? "900" : "500"; + list.Add(new KeyValuePair(item.codNum, nLevel + "|" + item.descrizione)); + } + } + redUtil.redSaveHashList(hashKey, list); + + // DataModel --> salvo in redis! + hashKey = confHash("DataModel"); + hashVal = DataModel; + saveHashKeyVal(hashKey, hashVal); + + // imposto VETO + hashKey = vetoHash("CNC"); + hashVal = "0"; + saveHashKeyVal(hashKey, hashVal); + hashKey = vetoHash("PLC"); + hashVal = "0"; + saveHashKeyVal(hashKey, hashVal); + + // Imposto DATI: percorro tutto l'albero nodi item ed allarmi e SCRIVO!!!! + foreach (var item in itemNodes) + { + hashKey = machineHash(item.Key); + hashVal = availStatus.UNAVAILABLE.ToString(); // item.Value.cObject.ToString(); + saveHashKeyVal(hashKey, hashVal); } } diff --git a/MTC_Adapter/OPC-UA-REDIS/redUtil.cs b/MTC_Adapter/OPC-UA-REDIS/redUtil.cs index f519bc7..8bd8485 100644 --- a/MTC_Adapter/OPC-UA-REDIS/redUtil.cs +++ b/MTC_Adapter/OPC-UA-REDIS/redUtil.cs @@ -182,7 +182,7 @@ namespace OPC_UA_REDIS } else { - lg.Error("Server REDIS non disponibile per setRSV"); + lg.Error("Server REDIS non disponibile (setRSV)"); } return answ; } @@ -196,17 +196,24 @@ namespace OPC_UA_REDIS public bool setRSV(string chiave, string valore, int TTL_sec) { bool answ = false; - try + if (srvConnected) { - IDatabase cache = connRedis.GetDatabase(); - TimeSpan expT = new TimeSpan(0, 0, TTL_sec); - // salvo con expyry... - cache.StringSet(chiave, valore, expT); - answ = true; + try + { + IDatabase cache = connRedis.GetDatabase(); + TimeSpan expT = new TimeSpan(0, 0, TTL_sec); + // salvo con expyry... + cache.StringSet(chiave, valore, expT); + answ = true; + } + catch (Exception exc) + { + lg.Info(string.Format("Errore in setRSV:{0}{1}", Environment.NewLine, exc)); + } } - catch (Exception exc) + else { - lg.Info(string.Format("Errore in setRSV:{0}{1}", Environment.NewLine, exc)); + lg.Error("Server REDIS non disponibile (setRSV:TTL)"); } return answ; } @@ -442,23 +449,30 @@ namespace OPC_UA_REDIS public bool redSaveHash(string hashKey, KeyValuePair[] hashFields) { bool answ = false; - // cerco se ci sia valore in redis... - IDatabase cache = connRedis.GetDatabase(); - try + if (srvConnected) { - RedisKey chiave = hashKey; - HashEntry[] valori = new HashEntry[hashFields.Length]; - int i = 0; - foreach (KeyValuePair kvp in hashFields) + // cerco se ci sia valore in redis... + IDatabase cache = connRedis.GetDatabase(); + try { - valori[i] = new HashEntry(kvp.Key, kvp.Value); - i++; + RedisKey chiave = hashKey; + HashEntry[] valori = new HashEntry[hashFields.Length]; + int i = 0; + foreach (KeyValuePair kvp in hashFields) + { + valori[i] = new HashEntry(kvp.Key, kvp.Value); + i++; + } + cache.HashSet(chiave, valori); + answ = true; } - cache.HashSet(chiave, valori); - answ = true; + catch + { } + } + else + { + lg.Error("Server REDIS non disponibile (redSaveHash)"); } - catch - { } return answ; } /// @@ -470,23 +484,30 @@ namespace OPC_UA_REDIS public static bool redSaveHashList(string hashKey, List> hashListKVP) { bool answ = false; - // cerco se ci sia valore in redis... - IDatabase cache = connRedis.GetDatabase(); - try + if (srvConnected) { - RedisKey chiave = hashKey; - HashEntry[] valori = new HashEntry[hashListKVP.Count]; - int i = 0; - foreach (KeyValuePair kvp in hashListKVP) + // cerco se ci sia valore in redis... + IDatabase cache = connRedis.GetDatabase(); + try { - valori[i] = new HashEntry(kvp.Key, kvp.Value); - i++; + RedisKey chiave = hashKey; + HashEntry[] valori = new HashEntry[hashListKVP.Count]; + int i = 0; + foreach (KeyValuePair kvp in hashListKVP) + { + valori[i] = new HashEntry(kvp.Key, kvp.Value); + i++; + } + cache.HashSet(chiave, valori); + answ = true; } - cache.HashSet(chiave, valori); - answ = true; + catch + { } + } + else + { + lg.Error("Server REDIS non disponibile (redSaveHashList)"); } - catch - { } return answ; } /// diff --git a/MTC_Adapter/SCMA/AdapterCom/GatewaySOURS.cs b/MTC_Adapter/SCMA/AdapterCom/GatewaySOURS.cs index 65ae55c..ad5e43f 100644 --- a/MTC_Adapter/SCMA/AdapterCom/GatewaySOURS.cs +++ b/MTC_Adapter/SCMA/AdapterCom/GatewaySOURS.cs @@ -33,14 +33,7 @@ namespace SCMA.AdapterCom /// public override void sendChanged() { - if (mAdapter.redisSrvOk) - { - mAdapter.SendChanged(); - } - else - { - lg.Error("Errore: redis server NON disponibile in sendChanged"); - } + mAdapter.SendChanged(); } /// /// Wrapper metodo imposta tutto a UNAVAILABLE