Ancora fix dataadapter
This commit is contained in:
+107
-99
@@ -618,6 +618,14 @@ namespace MP.SPEC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
public async Task<bool> FlushRedisKey(string redKey)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
RedisValue pattern = Utils.RedValue(redKey);
|
||||
bool answ = await RedisFlushPatternAsync(pattern);
|
||||
return answ;
|
||||
}
|
||||
|
||||
public List<FluxLogDTO> FluxLogDtoGetByFlux(string Valore)
|
||||
{
|
||||
List<FluxLogDTO> answ = new List<FluxLogDTO>();
|
||||
@@ -655,7 +663,7 @@ namespace MP.SPEC.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string currKey = $"{redisFluxLogFilt}:{IdxMacchina}:{CodFlux}:{MaxRec}:{DtMax:yyyyMMddHHmm}:{DtMin:yyyyMMddHHmm}";
|
||||
string currKey = $"{Utils.redisFluxLogFilt}:{IdxMacchina}:{CodFlux}:{MaxRec}:{DtMax:yyyyMMddHHmm}:{DtMin:yyyyMMddHHmm}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
@@ -735,7 +743,7 @@ namespace MP.SPEC.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string currKey = $"{redisGiacenzaList}:{IdxOdl}";
|
||||
string currKey = $"{Utils.redisGiacenzaList}:{IdxOdl}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
@@ -771,26 +779,6 @@ namespace MP.SPEC.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
#if false
|
||||
string currKey = $"{redisGiacenzaList}:{IdxOdl}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<AnagGiacenzeModel>>($"{rawData}");
|
||||
readType = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
redisDb.StringSet(currKey, rawData, TimeSpan.FromSeconds(redisShortTimeCache));
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<AnagGiacenzeModel>();
|
||||
}
|
||||
#endif
|
||||
result = dbController.ListOdlAll();
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
@@ -815,7 +803,7 @@ namespace MP.SPEC.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string currKey = $"{redisOdlList}:{inCorso}:{codArt}:{keyRichPart}:{Reparto}:{IdxMacchina}:{startDate:yyyyMMdd_HHmmss}:{endDate:yyyyMMdd_HHmmss}";
|
||||
string currKey = $"{Utils.redisOdlList}:{inCorso}:{codArt}:{keyRichPart}:{Reparto}:{IdxMacchina}:{startDate:yyyyMMdd_HHmmss}:{endDate:yyyyMMdd_HHmmss}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
@@ -858,7 +846,7 @@ namespace MP.SPEC.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string currKey = $"{redisPOdlList}:{codGruppo}:{idxMacchina}:{keyRichPart}:{lanciato}:{startDate:yyyyMMdd_HHmmss}:{endDate:yyyyMMdd_HHmmss}";
|
||||
string currKey = $"{Utils.redisPOdlList}:{codGruppo}:{idxMacchina}:{keyRichPart}:{lanciato}:{startDate:yyyyMMdd_HHmmss}:{endDate:yyyyMMdd_HHmmss}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
@@ -895,7 +883,7 @@ namespace MP.SPEC.Data
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string keyGrp = codGruppo != "*" ? codGruppo : "ALL";
|
||||
string currKey = $"{redisMacList}:{keyGrp}";
|
||||
string currKey = $"{Utils.redisMacList}:{keyGrp}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
@@ -931,7 +919,7 @@ namespace MP.SPEC.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string currKey = $"{redisMacRecipe}:{idxMacchina}";
|
||||
string currKey = $"{Utils.redisMacRecipe}:{idxMacchina}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
@@ -967,7 +955,7 @@ namespace MP.SPEC.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string currKey = $"{redisMacByFlux}:{dtStart:yyyyMMddHHmm}:{dtEnd:yyyyMMddHHmm}";
|
||||
string currKey = $"{Utils.redisMacByFlux}:{dtStart:yyyyMMddHHmm}:{dtEnd:yyyyMMddHHmm}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
@@ -1003,7 +991,7 @@ namespace MP.SPEC.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string currKey = redisOdlByBatch;
|
||||
string currKey = Utils.redisOdlByBatch;
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
@@ -1039,26 +1027,6 @@ namespace MP.SPEC.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
#if false
|
||||
string currKey = $"{redisGiacenzaList}:{IdxOdl}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<AnagGiacenzeModel>>($"{rawData}");
|
||||
readType = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
redisDb.StringSet(currKey, rawData, TimeSpan.FromSeconds(redisShortTimeCache));
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<AnagGiacenzeModel>();
|
||||
}
|
||||
#endif
|
||||
result = dbController.OdlByKey(IdxOdl);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
@@ -1122,7 +1090,7 @@ namespace MP.SPEC.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string currKey = $"{redisOdlCurrByMac}";
|
||||
string currKey = $"{Utils.redisOdlCurrByMac}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
@@ -1163,7 +1131,7 @@ namespace MP.SPEC.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string currKey = $"{redisFluxByMac}:{IdxMacchina}";
|
||||
string currKey = $"{Utils.redisFluxByMac}:{IdxMacchina}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
@@ -1201,7 +1169,7 @@ namespace MP.SPEC.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string currKey = $"{redisPOdlByPOdl}:{idxPODL}";
|
||||
string currKey = $"{Utils.redisPOdlByPOdl}:{idxPODL}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
@@ -1248,7 +1216,7 @@ namespace MP.SPEC.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string currKey = $"{redisPOdlByOdl}:{idxODL}";
|
||||
string currKey = $"{Utils.redisPOdlByOdl}:{idxODL}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
@@ -1291,7 +1259,7 @@ namespace MP.SPEC.Data
|
||||
{
|
||||
var dbResult = await dbController.PODLDeleteRecord(currRec);
|
||||
// elimino cache redis...
|
||||
RedisValue pattern = new RedisValue($"{redisXdlData}:*");
|
||||
RedisValue pattern = new RedisValue($"{Utils.redisXdlData}:*");
|
||||
bool answ = await RedisFlushPatternAsync(pattern);
|
||||
await Task.Delay(1);
|
||||
return dbResult;
|
||||
@@ -1306,7 +1274,7 @@ namespace MP.SPEC.Data
|
||||
{
|
||||
var dbResult = await dbController.PODL_startSetup(currRec, 0, 1, 1, "");
|
||||
// elimino cache redis...
|
||||
RedisValue pattern = new RedisValue($"{redisXdlData}:*");
|
||||
RedisValue pattern = new RedisValue($"{Utils.redisXdlData}:*");
|
||||
bool answ = await RedisFlushPatternAsync(pattern);
|
||||
await Task.Delay(1);
|
||||
return dbResult;
|
||||
@@ -1321,7 +1289,7 @@ namespace MP.SPEC.Data
|
||||
{
|
||||
var dbResult = await dbController.PODLUpdateRecord(currRec);
|
||||
// elimino cache redis...
|
||||
RedisValue pattern = new RedisValue($"{redisXdlData}:*");
|
||||
RedisValue pattern = new RedisValue($"{Utils.redisXdlData}:*");
|
||||
bool answ = await RedisFlushPatternAsync(pattern);
|
||||
await Task.Delay(1);
|
||||
return dbResult;
|
||||
@@ -1358,7 +1326,83 @@ namespace MP.SPEC.Data
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue flush memoria redis dato pattern
|
||||
/// Effettua conteggio chaivi REDIS dato pattern ricerca
|
||||
/// </summary>
|
||||
/// <param name="keyPattern"></param>
|
||||
/// <returns></returns>
|
||||
public int RedisCountKey(string keyPattern)
|
||||
{
|
||||
int num = 0;
|
||||
keyPattern = (string.IsNullOrEmpty(keyPattern) ? "**" : keyPattern);
|
||||
try
|
||||
{
|
||||
var listEndpoints = redisConnAdmin.GetEndPoints();
|
||||
foreach (var endPoint in listEndpoints)
|
||||
{
|
||||
var server = redisConnAdmin.GetServer(endPoint);
|
||||
foreach (RedisKey item in server.Keys(pattern: keyPattern, database: redisDb.Database, pageSize: 250, cursor: 0L))
|
||||
{
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception arg)
|
||||
{
|
||||
Log.Error($"Eccezione in RedisCountKey{Environment.NewLine}{arg}");
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue eliminazione memoria redis keyVal
|
||||
/// </summary>
|
||||
/// <param name="keyVal"></param>
|
||||
/// <returns></returns>
|
||||
public bool RedisDelKey(string keyVal)
|
||||
{
|
||||
bool answ = false;
|
||||
var listEndpoints = redisConnAdmin.GetEndPoints();
|
||||
foreach (var endPoint in listEndpoints)
|
||||
{
|
||||
var server = redisConnAdmin.GetServer(endPoint);
|
||||
if (server != null)
|
||||
{
|
||||
redisDb.KeyDelete((RedisKey)keyVal);
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue flush memoria redis dato keyVal
|
||||
/// </summary>
|
||||
/// <param name="pattern"></param>
|
||||
/// <returns></returns>
|
||||
public bool RedisFlushPattern(string pattern)
|
||||
{
|
||||
bool answ = false;
|
||||
var listEndpoints = redisConnAdmin.GetEndPoints();
|
||||
foreach (var endPoint in listEndpoints)
|
||||
{
|
||||
//var server = redisConnAdmin.GetServer(listEndpoints[0]);
|
||||
var server = redisConnAdmin.GetServer(endPoint);
|
||||
if (server != null)
|
||||
{
|
||||
var keyList = server.Keys(redisDb.Database, pattern);
|
||||
foreach (var item in keyList)
|
||||
{
|
||||
redisDb.KeyDelete(item);
|
||||
}
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue flush memoria redis dato keyVal, async
|
||||
/// </summary>
|
||||
/// <param name="pattern"></param>
|
||||
/// <returns></returns>
|
||||
@@ -1485,7 +1529,7 @@ namespace MP.SPEC.Data
|
||||
List<VocabolarioModel>? result = new List<VocabolarioModel>();
|
||||
string source = "REDIS";
|
||||
// cerco in redis...
|
||||
RedisValue rawData = redisDb.StringGet(redisVocabolario);
|
||||
RedisValue rawData = redisDb.StringGet(Utils.redisVocabolario);
|
||||
if (!string.IsNullOrEmpty($"{rawData}"))
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<VocabolarioModel>>($"{rawData}");
|
||||
@@ -1495,7 +1539,7 @@ namespace MP.SPEC.Data
|
||||
result = dbController.VocabolarioGetAll();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
redisDb.StringSet(redisVocabolario, rawData, getRandTOut(redisLongTimeCache / 5));
|
||||
redisDb.StringSet(Utils.redisVocabolario, rawData, getRandTOut(redisLongTimeCache / 5));
|
||||
source = "DB";
|
||||
}
|
||||
stopWatch.Stop();
|
||||
@@ -1529,9 +1573,9 @@ namespace MP.SPEC.Data
|
||||
/// </summary>
|
||||
/// <param name="stdMinutes"></param>
|
||||
/// <returns></returns>
|
||||
protected TimeSpan getRandTOut(int stdMinutes)
|
||||
protected TimeSpan getRandTOut(double stdMinutes)
|
||||
{
|
||||
double rndValue = (double)stdMinutes + (double)rand.Next(1, 60) / 60;
|
||||
double rndValue = stdMinutes + (double)rand.Next(1, 60) / 60;
|
||||
return TimeSpan.FromMinutes(rndValue);
|
||||
}
|
||||
|
||||
@@ -1539,42 +1583,6 @@ namespace MP.SPEC.Data
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private const string redisActionReq = redisBaseAddr + "IO:Action:Req";
|
||||
private const string redisAnagGruppi = redisBaseAddrSpec + "Cache:AnagGruppi";
|
||||
|
||||
private const string redisArtByDossier = redisBaseAddrSpec + "Cache:ArtByDossier";
|
||||
|
||||
private const string redisArtList = redisBaseAddrSpec + "Cache:ArtList";
|
||||
|
||||
private const string redisBaseAddr = "MP:";
|
||||
private const string redisBaseAddrSpec = redisBaseAddr + "SPEC:";
|
||||
|
||||
private const string redisConfKey = redisBaseAddrSpec + "Cache:Config";
|
||||
|
||||
private const string redisDossByMac = redisBaseAddrSpec + "Cache:DossByMac";
|
||||
|
||||
private const string redisFluxByMac = redisBaseAddrSpec + "Cache:FluxByMac";
|
||||
|
||||
private const string redisFluxLogFilt = redisBaseAddrSpec + "Cache:FluxLogFilt";
|
||||
|
||||
private const string redisGiacenzaList = redisBaseAddrSpec + "Cache:GiacenzaList";
|
||||
private const string redisMacByFlux = redisBaseAddrSpec + "Cache:MacByFlux";
|
||||
|
||||
private const string redisMacList = redisBaseAddrSpec + "Cache:MacList";
|
||||
private const string redisMacRecipe = redisBaseAddrSpec + "Cache:Recipe";
|
||||
|
||||
private const string redisOdlByBatch = redisXdlData + "OdlByBatch";
|
||||
private const string redisOdlCurrByMac = redisXdlData + "OdlByMac";
|
||||
private const string redisOdlList = redisXdlData + "OdlList";
|
||||
private const string redisParamPageExp = redisBaseAddrSpec + "Cache:ParamPage";
|
||||
private const string redisPOdlByOdl = redisXdlData + "POdlByOdl";
|
||||
private const string redisPOdlByPOdl = redisXdlData + "POdlByPOdl";
|
||||
private const string redisPOdlList = redisXdlData + "POdlList";
|
||||
private const string redisRecipeConf = redisBaseAddrSpec + "Cache:Recipe:Conf";
|
||||
private const string redisStatoCom = redisBaseAddrSpec + "Cache:StatoCom";
|
||||
private const string redisTipoArt = redisBaseAddrSpec + "Cache:TipoArt";
|
||||
private const string redisVocabolario = redisBaseAddrSpec + "Cache:Vocabolario";
|
||||
private const string redisXdlData = redisBaseAddrSpec + "Cache:XDL:";
|
||||
private static IConfiguration _configuration = null!;
|
||||
private static ILogger<MpDataService> _logger = null!;
|
||||
|
||||
@@ -1601,7 +1609,7 @@ namespace MP.SPEC.Data
|
||||
private IDatabase redisDb = null!;
|
||||
|
||||
private int redisLongTimeCache = 5;
|
||||
private int redisShortTimeCache = 4;
|
||||
private int redisShortTimeCache = 2;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
@@ -1609,9 +1617,9 @@ namespace MP.SPEC.Data
|
||||
|
||||
private async Task resetCacheArticoli()
|
||||
{
|
||||
RedisValue pattern = new RedisValue($"{redisArtByDossier}:*");
|
||||
RedisValue pattern = new RedisValue($"{Utils.redisArtByDossier}:*");
|
||||
await RedisFlushPatternAsync(pattern);
|
||||
pattern = new RedisValue($"{redisArtList}:*");
|
||||
pattern = new RedisValue($"{Utils.redisArtList}:*");
|
||||
await RedisFlushPatternAsync(pattern);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user