Update IobWinStatus
- nuovi metodi pubblicazione nuove info da IOB (channels) - nuovi campi - mitigazione registrazione in cache
This commit is contained in:
@@ -123,6 +123,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Eurom63.cs" />
|
||||
<Compile Include="IobWinStatus.cs" />
|
||||
<Compile Include="TCMan.cs" />
|
||||
<Compile Include="ToMapo.cs" />
|
||||
<Compile Include="baseUtils.cs" />
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace IOB_UT_NEXT
|
||||
{
|
||||
/// <summary>
|
||||
/// Rappresentazione dello stato corrente dell'IOB
|
||||
/// </summary>
|
||||
public class IobWinStatus
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// ID univoco
|
||||
/// </summary>
|
||||
public string CodIob { get; set; } = "0";
|
||||
|
||||
/// <summary>
|
||||
/// Contatore IOB
|
||||
/// </summary>
|
||||
public float counterIOB { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Contatore Macchina
|
||||
/// </summary>
|
||||
public float counterMAC { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Ultimo stato noto dei parametri in memoria letti dalla macchina
|
||||
/// </summary>
|
||||
public Dictionary<string, string> currParams { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
/// <summary>
|
||||
/// Note (libere) da child a controller
|
||||
/// </summary>
|
||||
public string freeNotes { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Tipo IOB
|
||||
/// </summary>
|
||||
public string IobType { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// DataOra ultima comunicazione IN (con PLC)
|
||||
/// </summary>
|
||||
public DateTime lastDataIn { get; set; } = DateTime.Now.AddMinutes(-1);
|
||||
|
||||
/// <summary>
|
||||
/// DataOra ultima comunicazione OUT (con MP Server)
|
||||
/// </summary>
|
||||
public DateTime lastDataOut { get; set; } = DateTime.Now.AddDays(-1);
|
||||
|
||||
/// <summary>
|
||||
/// DataOra ultima comunicazione OUT (con MP Server)
|
||||
/// </summary>
|
||||
public DateTime lastUpdate { get; set; } = DateTime.Now.AddDays(-1);
|
||||
|
||||
/// <summary>
|
||||
/// Status del SINGOLO IOB
|
||||
/// </summary>
|
||||
public bool online { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Lungh coda ALLARMI in uscita
|
||||
/// </summary>
|
||||
public int queueAlLen { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Lunghezza coda EVENTI in uscita
|
||||
/// </summary>
|
||||
public int queueEvLen { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Lunghezza coda FluxLog in uscita
|
||||
/// </summary>
|
||||
public int queueFlLen { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Lungh coda MESSAGGI in uscita
|
||||
/// </summary>
|
||||
public int queueMsLen { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Lungh coda UserLog in uscita
|
||||
/// </summary>
|
||||
public int queueRawTransfLen { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Lungh coda UserLog in uscita
|
||||
/// </summary>
|
||||
public int queueUlLen { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Semaforo IN (IOB-Macchina)
|
||||
/// </summary>
|
||||
public string semIn { get; set; } = "ND";
|
||||
|
||||
/// <summary>
|
||||
/// Semaforo OUT (IOB-MPServer)
|
||||
/// </summary>
|
||||
public string semOut { get; set; } = "ND";
|
||||
|
||||
/// <summary>
|
||||
/// Parametri configurazione (es IP target, porta, ...)
|
||||
/// </summary>
|
||||
public Dictionary<string, string> setupParams { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Override metodo di equality
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is IobWinStatus item))
|
||||
return false;
|
||||
|
||||
if (online != item.online)
|
||||
return false;
|
||||
if (lastDataIn != item.lastDataIn)
|
||||
return false;
|
||||
if (lastDataOut != item.lastDataOut)
|
||||
return false;
|
||||
if (semIn != item.semIn)
|
||||
return false;
|
||||
if (semOut != item.semOut)
|
||||
return false;
|
||||
if (currParams != item.currParams)
|
||||
return false;
|
||||
if (counterIOB != item.counterIOB)
|
||||
return false;
|
||||
if (counterMAC != item.counterMAC)
|
||||
return false;
|
||||
if (queueAlLen != item.queueAlLen)
|
||||
return false;
|
||||
if (queueEvLen != item.queueEvLen)
|
||||
return false;
|
||||
if (queueFlLen != item.queueFlLen)
|
||||
return false;
|
||||
if (queueMsLen != item.queueMsLen)
|
||||
return false;
|
||||
if (queueRawTransfLen != item.queueRawTransfLen)
|
||||
return false;
|
||||
if (queueUlLen != item.queueUlLen)
|
||||
return false;
|
||||
if (freeNotes != item.freeNotes)
|
||||
return false;
|
||||
if (setupParams != item.setupParams)
|
||||
return false;
|
||||
if (IobType != item.IobType)
|
||||
return false;
|
||||
if (CodIob != item.CodIob)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -205,6 +205,7 @@ namespace IOB_UT_NEXT
|
||||
#endregion Public Properties
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Rappresentazione dello stato corrente dell'IOB
|
||||
/// </summary>
|
||||
@@ -321,7 +322,8 @@ namespace IOB_UT_NEXT
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Elenco oggetti del monitoraggio (DynData, Status) per WPS
|
||||
|
||||
+82
-4
@@ -168,7 +168,32 @@ namespace IOB_UT_NEXT
|
||||
set
|
||||
{
|
||||
string rawData = JsonConvert.SerializeObject(value);
|
||||
setRSV(redIobKey, rawData);
|
||||
saveAndSendMessage(redIobKey, "", rawData);
|
||||
//setRSV(redIobKey, rawData);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MEssage Dispatcher: oggetto comunicazione pub/sub via REDIS channels corrente
|
||||
/// </summary>
|
||||
public ISubscriber messageDisp
|
||||
{
|
||||
get
|
||||
{
|
||||
ISubscriber answ;
|
||||
// se già valorizzato uso oggetto private...
|
||||
if (_currSub != null)
|
||||
{
|
||||
answ = _currSub;
|
||||
}
|
||||
else
|
||||
{
|
||||
// init DB (sullo 0)
|
||||
answ = connRedis.GetSubscriber();
|
||||
_currSub = answ;
|
||||
}
|
||||
// restituisco oggetto DB
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -897,6 +922,43 @@ namespace IOB_UT_NEXT
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invia un messaggio tramite notify channel + salva in cache (se scaduto periodo veto)
|
||||
/// </summary>
|
||||
/// <param name="memKey"></param>
|
||||
/// <param name="notifyChannel"></param>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
public bool saveAndSendMessage(string memKey, string notifyChannel, string message)
|
||||
{
|
||||
bool fatto = false;
|
||||
// effettuo la scrittura nell'area di memoria indicata SE passato intervallo minimo
|
||||
bool doSave = true;
|
||||
if (LastKeySave.ContainsKey(memKey))
|
||||
{
|
||||
if (DateTime.Now.Subtract(LastKeySave[memKey]).TotalSeconds < 30)
|
||||
{
|
||||
doSave = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LastKeySave.Add(memKey, DateTime.Now);
|
||||
}
|
||||
if (doSave)
|
||||
{
|
||||
cache.StringSet(memKey, message);
|
||||
LastKeySave[memKey] = DateTime.Now;
|
||||
Logging.Instance.Trace($"Redis Cache Key: {memKey}");
|
||||
}
|
||||
|
||||
// invio notifica tramite il canale richiesto
|
||||
messageDisp.Publish(notifyChannel, message);
|
||||
|
||||
// restituisco!
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializzazione di un oggetto generico
|
||||
/// </summary>
|
||||
@@ -1042,12 +1104,17 @@ namespace IOB_UT_NEXT
|
||||
protected string currIobType = "ND";
|
||||
|
||||
/// <summary>
|
||||
/// Hash redis x dati IOB
|
||||
/// Hash REDIS x dati IOB
|
||||
/// </summary>
|
||||
protected string redIobKey = "";
|
||||
|
||||
/// <summary>
|
||||
/// Hash redis x dati server
|
||||
/// Nome del channel REDIS x dati IOB
|
||||
/// </summary>
|
||||
protected string redIobChannel = "IobChannel";
|
||||
|
||||
/// <summary>
|
||||
/// Hash REDIS x dati server
|
||||
/// </summary>
|
||||
protected string redServKey = "";
|
||||
|
||||
@@ -1055,6 +1122,11 @@ namespace IOB_UT_NEXT
|
||||
|
||||
#region Private Fields
|
||||
|
||||
/// <summary>
|
||||
/// Dizionario delle ultime scritture in cache redis dei messaggi
|
||||
/// </summary>
|
||||
private Dictionary<string, DateTime> LastKeySave = new Dictionary<string, DateTime>();
|
||||
|
||||
/// <summary>
|
||||
/// Connessione lazy a redis...
|
||||
/// </summary>
|
||||
@@ -1088,10 +1160,15 @@ namespace IOB_UT_NEXT
|
||||
#region Private Properties
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto currentDb locale
|
||||
/// Oggetto currentDb REDIS locale
|
||||
/// </summary>
|
||||
private IDatabase _currDB { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto subscriber x pubblicazione/sottoscrizione canali REDIS
|
||||
/// </summary>
|
||||
private ISubscriber _currSub { get; set; }
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
#region Private Methods
|
||||
@@ -1123,6 +1200,7 @@ namespace IOB_UT_NEXT
|
||||
// init dati di base...
|
||||
redServKey = redHash($"MP");
|
||||
redIobKey = redHash($"IOB:{currCodIob}");
|
||||
redIobChannel = $"IobChannel_{currCodIob}";
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
Reference in New Issue
Block a user