Merge branch 'release/FixMemLayer_02'
This commit is contained in:
+34
-22
@@ -31,6 +31,11 @@ namespace SteamWare.IO
|
||||
/// </summary>
|
||||
public Dictionary<string, string> AppConf;
|
||||
|
||||
/// <summary>
|
||||
/// Definisce il TTL x appConf (secondi)
|
||||
/// </summary>
|
||||
public int maxAgeAppConf = 5;
|
||||
|
||||
/// <summary>
|
||||
/// Table adapter accesso conf parameters
|
||||
/// </summary>
|
||||
@@ -60,6 +65,7 @@ namespace SteamWare.IO
|
||||
initTA();
|
||||
setupConnectionStringBase();
|
||||
setupMongo();
|
||||
setupParams();
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
@@ -196,27 +202,6 @@ namespace SteamWare.IO
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera il TTL x appConf (secondi)
|
||||
/// </summary>
|
||||
public int maxAgeAppConf
|
||||
{
|
||||
get
|
||||
{
|
||||
// default 5 minuti x refresh...
|
||||
int maxAge = 5;
|
||||
try
|
||||
{
|
||||
maxAge = confReadInt("maxAgeAppConf_min");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(string.Format("Errore in lettura valore maxAgeAppConf_min{0}{1}", Environment.NewLine, exc));
|
||||
}
|
||||
return maxAge * 60;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Numero record salvati in AppConf
|
||||
/// </summary>
|
||||
@@ -530,12 +515,14 @@ namespace SteamWare.IO
|
||||
public string configDbVal(string chiave)
|
||||
{
|
||||
string answ = "";
|
||||
bool cacheReloaded = false;
|
||||
if (confReadString("DbConfConnectionString") != "")
|
||||
{
|
||||
// verifico esista oggetto...
|
||||
if (AppConf == null)
|
||||
{
|
||||
resetAppConf();
|
||||
cacheReloaded = true;
|
||||
}
|
||||
if (AppConf != null)
|
||||
{
|
||||
@@ -543,9 +530,10 @@ namespace SteamWare.IO
|
||||
if (AppConf.Count == 0)
|
||||
{
|
||||
resetAppConf();
|
||||
cacheReloaded = true;
|
||||
}
|
||||
// controllo SE in redis ci sia ancora il valore, altrimenti rileggo...
|
||||
if (!redKeyPresent(ACBH))
|
||||
if (!cacheReloaded && DateTime.Now > vetoCacheCheck && !redKeyPresent(ACBH))
|
||||
{
|
||||
Log.Info($"Manca HASH in redis --> rileggo da DB --> REDIS --> Memoria | {ACBH} | {chiave}");
|
||||
resetAppConf();
|
||||
@@ -2400,6 +2388,8 @@ namespace SteamWare.IO
|
||||
}
|
||||
// salvo in redis valori (con TTL)
|
||||
redSaveHash(ACBH, valori, maxAgeAppConf);
|
||||
// salvo info cache riletta 2 sec prima della scadenza
|
||||
vetoCacheCheck = DateTime.Now.AddSeconds(maxAgeAppConf - 2);
|
||||
Log.Info("Completato procedura startupAppConf");
|
||||
}
|
||||
else
|
||||
@@ -2449,6 +2439,8 @@ namespace SteamWare.IO
|
||||
return ConnectionMultiplexer.Connect(RedisConnAdmin);
|
||||
});
|
||||
|
||||
private DateTime vetoCacheCheck = DateTime.Now;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
@@ -2492,6 +2484,26 @@ namespace SteamWare.IO
|
||||
currMongoClient = new MongoClient(mongoConnString);
|
||||
}
|
||||
|
||||
private void setupParams()
|
||||
{
|
||||
// default 5 minuti x refresh...
|
||||
int maxAge = 5;
|
||||
try
|
||||
{
|
||||
maxAge = confReadInt("maxAgeAppConf_min");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in lettura valore maxAgeAppConf_min{Environment.NewLine}{exc}");
|
||||
}
|
||||
// controllo maxage valida...
|
||||
if (maxAge < 1)
|
||||
{
|
||||
maxAge = 5;
|
||||
}
|
||||
maxAgeAppConf = maxAge * 60;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
+88
-39
@@ -7,6 +7,7 @@ using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
|
||||
namespace SteamWare
|
||||
@@ -28,6 +29,11 @@ namespace SteamWare
|
||||
/// </summary>
|
||||
public Dictionary<string, string> AppConf;
|
||||
|
||||
/// <summary>
|
||||
/// Definisce il TTL x appConf (secondi)
|
||||
/// </summary>
|
||||
public int maxAgeAppConf = 5;
|
||||
|
||||
/// <summary>
|
||||
/// Table adapter accesso conf parameters
|
||||
/// </summary>
|
||||
@@ -53,6 +59,7 @@ namespace SteamWare
|
||||
initTA();
|
||||
setupConnectionStringBase();
|
||||
setupMongo();
|
||||
setupParams();
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
@@ -189,27 +196,6 @@ namespace SteamWare
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera il TTL x appConf (secondi)
|
||||
/// </summary>
|
||||
public int maxAgeAppConf
|
||||
{
|
||||
get
|
||||
{
|
||||
// default 5 minuti x refresh...
|
||||
int maxAge = 5;
|
||||
try
|
||||
{
|
||||
maxAge = confReadInt("maxAgeAppConf_min");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(string.Format("Errore in lettura valore maxAgeAppConf_min{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
|
||||
}
|
||||
return maxAge * 60;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Numero record salvati in AppConf
|
||||
/// </summary>
|
||||
@@ -523,12 +509,14 @@ namespace SteamWare
|
||||
public string configDbVal(string chiave)
|
||||
{
|
||||
string answ = "";
|
||||
bool cacheReloaded = false;
|
||||
if (confReadString("DbConfConnectionString") != "")
|
||||
{
|
||||
// verifico esista oggetto...
|
||||
if (AppConf == null)
|
||||
{
|
||||
resetAppConf();
|
||||
cacheReloaded = true;
|
||||
}
|
||||
if (AppConf != null)
|
||||
{
|
||||
@@ -536,9 +524,10 @@ namespace SteamWare
|
||||
if (AppConf.Count == 0)
|
||||
{
|
||||
resetAppConf();
|
||||
cacheReloaded = true;
|
||||
}
|
||||
// controllo SE in redis ci sia ancora il valore, altrimenti rileggo...
|
||||
if (!redKeyPresent(ACBH))
|
||||
if (!cacheReloaded && DateTime.Now > vetoCacheCheck && !redKeyPresent(ACBH))
|
||||
{
|
||||
Log.Info($"Manca HASH in redis --> rileggo da DB --> REDIS --> Memoria | {ACBH} | {chiave}");
|
||||
resetAppConf();
|
||||
@@ -1082,14 +1071,25 @@ namespace SteamWare
|
||||
public bool isInSessionObject(string nomeVar)
|
||||
{
|
||||
bool answ = false;
|
||||
bool stringAnsw = false;
|
||||
// cerco se ci sia...
|
||||
try
|
||||
{
|
||||
answ = (HttpContext.Current.Session[nomeVar] != null);
|
||||
//stringAnsw = (string)HttpContext.Current.Session[nomeVar].ToString() != "";
|
||||
stringAnsw = HttpContext.Current.Session[nomeVar] != null;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in isInSessionObject:{Environment.NewLine}{exc}");
|
||||
Log.Error($"Errore 01 | isInSessionObject:{Environment.NewLine}{exc}");
|
||||
}
|
||||
// infine condizione doppia...
|
||||
try
|
||||
{
|
||||
answ = (HttpContext.Current.Session[nomeVar] != null && stringAnsw);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore 02 | isInSessionObject:{Environment.NewLine}{exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
@@ -2297,21 +2297,39 @@ namespace SteamWare
|
||||
Dictionary<string, string> answ = new Dictionary<string, string>();
|
||||
// istanzio un NUOVO oggetto x evitare problemi init contestuali
|
||||
memLayer nML = new memLayer();
|
||||
var tabDati = nML.taConfig.GetData();
|
||||
// carico
|
||||
foreach (DS_Utility.ConfigRow riga in tabDati)
|
||||
DS_Utility.ConfigDataTable tabDati = null;
|
||||
int waitMs = 100;
|
||||
int numTry = 5;
|
||||
do
|
||||
{
|
||||
try
|
||||
{
|
||||
answ.Add(riga.chiave, riga.valore);
|
||||
tabDati = nML.taConfig.GetData();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore procedura ricaricaAppConf per kvp: {riga.chiave} / {riga.valore}{Environment.NewLine}{exc}");
|
||||
numTry--;
|
||||
Log.Error($"Errore procedura nML.taConfig.GetData(), numTry = {numTry}, now {waitMs}ms wait{Environment.NewLine}{exc}");
|
||||
Thread.Sleep(waitMs);
|
||||
}
|
||||
} while (numTry > 0 && tabDati == null);
|
||||
if (tabDati != null)
|
||||
{
|
||||
// carico
|
||||
foreach (DS_Utility.ConfigRow riga in tabDati)
|
||||
{
|
||||
try
|
||||
{
|
||||
answ.Add(riga.chiave, riga.valore);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore procedura ricaricaAppConf per kvp: {riga.chiave} / {riga.valore}{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
// log ricarica
|
||||
Log.Info($"Effettuata procedura ricaricaAppConf per {answ.Count} records");
|
||||
}
|
||||
// log ricarica
|
||||
Log.Info($"Effettuata procedura ricaricaAppConf per {answ.Count} records");
|
||||
return answ;
|
||||
}
|
||||
|
||||
@@ -2353,16 +2371,25 @@ namespace SteamWare
|
||||
else
|
||||
{
|
||||
AppConf = ricaricaAppConf();
|
||||
KeyValuePair<string, string>[] valori = new KeyValuePair<string, string>[AppConf.Count];
|
||||
int i = 0;
|
||||
foreach (var item in AppConf)
|
||||
if (AppConf.Count > 0)
|
||||
{
|
||||
valori[i] = new KeyValuePair<string, string>(item.Key, item.Value);
|
||||
i++;
|
||||
KeyValuePair<string, string>[] valori = new KeyValuePair<string, string>[AppConf.Count];
|
||||
int i = 0;
|
||||
foreach (var item in AppConf)
|
||||
{
|
||||
valori[i] = new KeyValuePair<string, string>(item.Key, item.Value);
|
||||
i++;
|
||||
}
|
||||
// salvo in redis valori (con TTL)
|
||||
redSaveHash(ACBH, valori, maxAgeAppConf);
|
||||
// salvo info cache riletta 2 sec prima della scadenza
|
||||
vetoCacheCheck = DateTime.Now.AddSeconds(maxAgeAppConf - 2);
|
||||
Log.Info("Completato procedura startupAppConf");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error("Errore in procedura startupAppConf, ritornato insieme vuoto");
|
||||
}
|
||||
// salvo in redis valori (con TTL)
|
||||
redSaveHash(ACBH, valori, maxAgeAppConf);
|
||||
Log.Info("Completato procedura startupAppConf");
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
@@ -2406,6 +2433,8 @@ namespace SteamWare
|
||||
return ConnectionMultiplexer.Connect(RedisConnAdmin);
|
||||
});
|
||||
|
||||
private DateTime vetoCacheCheck = DateTime.Now;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
@@ -2449,6 +2478,26 @@ namespace SteamWare
|
||||
currMongoClient = new MongoClient(mongoConnString);
|
||||
}
|
||||
|
||||
private void setupParams()
|
||||
{
|
||||
// default 5 minuti x refresh...
|
||||
int maxAge = 5;
|
||||
try
|
||||
{
|
||||
maxAge = confReadInt("maxAgeAppConf_min");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in lettura valore maxAgeAppConf_min{Environment.NewLine}{exc}");
|
||||
}
|
||||
// controllo maxage valida...
|
||||
if (maxAge < 1)
|
||||
{
|
||||
maxAge = 5;
|
||||
}
|
||||
maxAgeAppConf = maxAge * 60;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,10 @@
|
||||
</startup>
|
||||
<appSettings>
|
||||
<!--Redis conn-->
|
||||
<add key="RedisConn" value="localhost,abortConnect=false,ssl=false" />
|
||||
<add key="RedisConnAdmin" value="localhost,abortConnect=false,ssl=false" />
|
||||
<add key="RedisConn" value="redis.ufficio:26379,serviceName=devel,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false" />
|
||||
<add key="RedisConnAdmin" value="redis.ufficio:26379,serviceName=devel,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true" />
|
||||
<!--<add key="RedisConn" value="localhost,abortConnect=false,ssl=false" />
|
||||
<add key="RedisConnAdmin" value="localhost,abortConnect=false,ssl=false" />-->
|
||||
<add key="cacheOnRedis" value="true" />
|
||||
<add key="redisDb" value="1" />
|
||||
<add key="_logDir" value="./logs/" />
|
||||
|
||||
Reference in New Issue
Block a user