Rimozione obj inutili di connessione redis da MainForm + obj Admin (da 12 a 4...)
This commit is contained in:
+21
-15
@@ -1,4 +1,5 @@
|
||||
using StackExchange.Redis;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -8,7 +9,7 @@ namespace IOB_UT_NEXT
|
||||
/// <summary>
|
||||
/// Classe gestione code, a seconda della conf come LIST redis o come concurrent queue in memoria
|
||||
/// </summary>
|
||||
public class DataQueue
|
||||
public class DataQueue : IDisposable
|
||||
{
|
||||
#region Public Fields
|
||||
|
||||
@@ -23,14 +24,23 @@ namespace IOB_UT_NEXT
|
||||
UseRedis = useRedis;
|
||||
CodIOB = codIOB;
|
||||
QueueName = qName;
|
||||
redisMan = redisCacheMan;
|
||||
KeyName = redisMan.redHash($"IOB:QUEUE:{CodIOB}:{QueueName}");
|
||||
if (UseRedis)
|
||||
{
|
||||
redisMan = redisCacheMan;
|
||||
KeyName = redisMan.redHash($"IOB:QUEUE:{CodIOB}:{QueueName}");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
redisMan = null;
|
||||
KeyName = "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Accodamento elemento
|
||||
/// </summary>
|
||||
@@ -42,7 +52,7 @@ namespace IOB_UT_NEXT
|
||||
Count = redisMan.redQueuePush(KeyName, item);
|
||||
#if false
|
||||
redisMan.redQueuePush(KeyName, item);
|
||||
Count = (long)redisMan.redQueueCount(KeyName);
|
||||
Count = (long)redisMan.redQueueCount(KeyName);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
@@ -62,7 +72,7 @@ namespace IOB_UT_NEXT
|
||||
if (UseRedis)
|
||||
{
|
||||
// recupero in blocco...
|
||||
answ = redisMan.redQueuePopAll(KeyName)
|
||||
answ = redisMan.redQueuePopAll(KeyName)
|
||||
.Select(x => $"{x}")
|
||||
.ToList();
|
||||
#if false
|
||||
@@ -72,7 +82,7 @@ namespace IOB_UT_NEXT
|
||||
{
|
||||
answ.Add(redisMan.redQueuePop(KeyName));
|
||||
Count = (int)redisMan.redQueueCount(KeyName);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
@@ -120,20 +130,16 @@ namespace IOB_UT_NEXT
|
||||
|
||||
private string QueueName = "NA";
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto connessione REDIS
|
||||
/// </summary>
|
||||
private RedisIobCache redisMan;
|
||||
|
||||
/// <summary>
|
||||
/// Indica se usare redis come datastore vs memoria
|
||||
/// </summary>
|
||||
private bool UseRedis = false;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto connessione REDIS
|
||||
/// </summary>
|
||||
private RedisIobCache redisMan; // { get; set; } = new RedisIobCache();
|
||||
|
||||
#endregion Private Properties
|
||||
}
|
||||
}
|
||||
@@ -1129,31 +1129,6 @@ namespace IOB_UT_NEXT
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce info dei server connessi...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IServer[] redServInfo()
|
||||
{
|
||||
IServer[] answ = new IServer[1];
|
||||
try
|
||||
{
|
||||
answ = new IServer[connRedisAdmin.GetEndPoints().Length];
|
||||
int i = 0;
|
||||
foreach (var ep in connRedisAdmin.GetEndPoints())
|
||||
{
|
||||
var server = connRedisAdmin.GetServer(ep);
|
||||
answ[i] = server;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logging.Instance.Error($"redServInfo {exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Conteggio elementi in QUEUE (LIFO)
|
||||
/// </summary>
|
||||
@@ -1469,36 +1444,6 @@ namespace IOB_UT_NEXT
|
||||
/// </summary>
|
||||
private Dictionary<string, DateTime> LastKeySave = new Dictionary<string, DateTime>();
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Connessione lazy a redis...
|
||||
/// </summary>
|
||||
private Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
|
||||
{
|
||||
string RedisConn = baseUtils.CRS("RedisConn");
|
||||
if (string.IsNullOrEmpty(RedisConn))
|
||||
{
|
||||
RedisConn = "localhost,abortConnect=false,ssl=false";
|
||||
}
|
||||
|
||||
return ConnectionMultiplexer.Connect(RedisConn);
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// Connessione lazy a redis...
|
||||
/// </summary>
|
||||
private Lazy<ConnectionMultiplexer> lazyConnectionAdmin = new Lazy<ConnectionMultiplexer>(() =>
|
||||
{
|
||||
string RedisConnAdmin = baseUtils.CRS("RedisConnAdmin");
|
||||
if (string.IsNullOrEmpty(RedisConnAdmin))
|
||||
{
|
||||
RedisConnAdmin = "localhost,abortConnect=false,ssl=false,allowAdmin=true";
|
||||
}
|
||||
|
||||
return ConnectionMultiplexer.Connect(RedisConnAdmin);
|
||||
});
|
||||
#endif
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
@@ -1517,27 +1462,6 @@ namespace IOB_UT_NEXT
|
||||
/// Oggetto statico connessione redis
|
||||
/// </summary>
|
||||
private ConnectionMultiplexer connRedis { get; set; }
|
||||
#if false
|
||||
{
|
||||
get
|
||||
{
|
||||
return lazyConnection.Value;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto statico connessione redis
|
||||
/// </summary>
|
||||
private ConnectionMultiplexer connRedisAdmin { get; set; }
|
||||
#if false
|
||||
{
|
||||
get
|
||||
{
|
||||
return lazyConnectionAdmin.Value;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
@@ -1587,46 +1511,8 @@ namespace IOB_UT_NEXT
|
||||
}
|
||||
connRedis = ConnectionMultiplexer.Connect(RedisConn);
|
||||
Logging.Instance.Info($"Apertura di un Redis Multiplexer");
|
||||
|
||||
// initi obj admin
|
||||
string RedisConnAdmin = baseUtils.CRS("RedisConnAdmin");
|
||||
if (string.IsNullOrEmpty(RedisConnAdmin))
|
||||
{
|
||||
RedisConnAdmin = "localhost,abortConnect=false,ssl=false,allowAdmin=true";
|
||||
}
|
||||
connRedisAdmin = ConnectionMultiplexer.Connect(RedisConnAdmin);
|
||||
Logging.Instance.Info($"Apertura di un Redis Multiplexer Admin");
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Incremento conteggio di un valore dentro una hash
|
||||
/// </summary>
|
||||
/// <param name="hashKey">chiave</param>
|
||||
/// <param name="hashField">valore con conteggio da tracciare</param>
|
||||
/// <param name="hashExpire">scadenza preimpostata hash datetime, se null NON scade</param>
|
||||
/// <returns></returns>
|
||||
public bool redIncrHashCount(string hashKey, string hashField, DateTime? hashExpire)
|
||||
{
|
||||
bool answ = false;
|
||||
// cerco se ci sia valore in redis...
|
||||
try
|
||||
{
|
||||
RedisKey chiave = hashKey;
|
||||
cache.HashIncrement(chiave, hashField, 1);
|
||||
if (hashExpire != null)
|
||||
{
|
||||
cache.KeyExpire(chiave, hashExpire);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logging.Instance.Error($"redIncrHashCount {exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
+691
-603
File diff suppressed because it is too large
Load Diff
@@ -5213,6 +5213,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
string codIob = IOBConfFull.General.FilenameIOB;
|
||||
bool useRedis = IOBConfFull.General.EnabRedisQue;
|
||||
QueueAlarm = new DataQueue(codIob, "QueueAlarm", false, redisMan);
|
||||
QueueIN.Dispose();
|
||||
QueueIN = new DataQueue(codIob, "QueueIN", useRedis, redisMan);
|
||||
// no coda redis
|
||||
QueueFLog = new DataQueue(codIob, "QueueFLog", false, redisMan);
|
||||
|
||||
@@ -32,10 +32,12 @@ namespace IOB_WIN_FORM
|
||||
/// </summary>
|
||||
public DateTime lastComCheck;
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Oggetto connessione REDIS
|
||||
/// </summary>
|
||||
public RedisIobCache redisMan;
|
||||
public RedisIobCache redisMan;
|
||||
#endif
|
||||
|
||||
#endregion Public Fields
|
||||
|
||||
@@ -998,6 +1000,7 @@ namespace IOB_WIN_FORM
|
||||
{
|
||||
firstIob = IOB2START[0];
|
||||
}
|
||||
#if false
|
||||
try
|
||||
{
|
||||
redisMan = new RedisIobCache(MPIP, firstIob, "NA", MinDeltaSec);
|
||||
@@ -1005,7 +1008,8 @@ namespace IOB_WIN_FORM
|
||||
catch (Exception exc)
|
||||
{
|
||||
lgError($"Eccezione in salvataggio stato su redis{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1149,8 +1153,10 @@ namespace IOB_WIN_FORM
|
||||
{
|
||||
openChild(item);
|
||||
}
|
||||
#if false
|
||||
// effettuo upload dei file di configurazione...
|
||||
uploadIobConfFile();
|
||||
uploadIobConfFile();
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1178,6 +1184,7 @@ namespace IOB_WIN_FORM
|
||||
}
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Effettua upload dei file di configurazione IOB
|
||||
/// </summary>
|
||||
@@ -1253,11 +1260,14 @@ namespace IOB_WIN_FORM
|
||||
lgError($"Eccezione in upload IOB conf files{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private void uploadIOBConfToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
uploadIobConfFile();
|
||||
#if false
|
||||
uploadIobConfFile();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
@@ -59,6 +59,7 @@ CHANGE_ODL_MODE=PZCOUNT_RESET
|
||||
PZCOUNT_MODE=OPC
|
||||
ENABLE_PZ_RESET=TRUE
|
||||
ENABLE_PZ_RESET_ENDPROD=TRUE
|
||||
ENABLE_PZ_RESET_stopSetup=TRUE
|
||||
DISABLE_PZCOUNT=FALSE
|
||||
ENABLE_SEND_PZC_BLOCK=TRUE
|
||||
MIN_SEND_PZC_BLOCK=0
|
||||
|
||||
@@ -366,16 +366,6 @@
|
||||
"index": 0,
|
||||
"size": 1
|
||||
},
|
||||
"OPC_acProg": {
|
||||
"name": "OPC_acProg",
|
||||
"description": "Program",
|
||||
"func": "MEDIAN",
|
||||
"period": 600,
|
||||
"tipoMem": "Int",
|
||||
"memAddr": "ns=2;s=/Channel/State/acProg",
|
||||
"index": 0,
|
||||
"size": 1
|
||||
},
|
||||
"OPC_oldProgNetTime": {
|
||||
"name": "OPC_oldProgNetTime",
|
||||
"description": "Ultimo TCiclo",
|
||||
|
||||
@@ -366,16 +366,6 @@
|
||||
"index": 0,
|
||||
"size": 1
|
||||
},
|
||||
"OPC_acProg": {
|
||||
"name": "OPC_acProg",
|
||||
"description": "Program",
|
||||
"func": "MEDIAN",
|
||||
"period": 600,
|
||||
"tipoMem": "Int",
|
||||
"memAddr": "ns=2;s=/Channel/State/acProg",
|
||||
"index": 0,
|
||||
"size": 1
|
||||
},
|
||||
"OPC_oldProgNetTime": {
|
||||
"name": "OPC_oldProgNetTime",
|
||||
"description": "Ultimo TCiclo",
|
||||
|
||||
Reference in New Issue
Block a user