Update controllers SPEC/IOC
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using MP.Data;
|
||||
using MP.Data;
|
||||
using MP.Data.Conf;
|
||||
using MP.Data.DatabaseModels;
|
||||
using MP.Data.DTO;
|
||||
@@ -63,9 +62,8 @@ namespace MP.IOC.Data
|
||||
#region Public Properties
|
||||
|
||||
public static MP.Data.Controllers.MpIocController IocDbController { get; set; } = null!;
|
||||
public static MP.Data.Controllers.MpSpecController SpecDbController { get; set; } = null!;
|
||||
public static MP.Data.Controllers.MpMongoController mongoController { get; set; } = null!;
|
||||
|
||||
public static MP.Data.Controllers.MpSpecController SpecDbController { get; set; } = null!;
|
||||
public MessagePipe BroadastMsgPipe { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
@@ -77,8 +75,6 @@ namespace MP.IOC.Data
|
||||
|
||||
#region Public Methods
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Recupera eventuali azioni richieste
|
||||
/// </summary>
|
||||
@@ -662,12 +658,12 @@ namespace MP.IOC.Data
|
||||
public async Task<bool> FlushRedisKey(string redKey)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
RedisValue pattern = Utils.RedValue(redKey);
|
||||
RedisValue pattern = Utils.RedValue(redKey);
|
||||
bool answ = await RedisFlushPatternAsync(pattern);
|
||||
return answ;
|
||||
}
|
||||
|
||||
public List<FluxLogDTO> FluxLogGetByFlux(string Valore)
|
||||
public List<FluxLogDTO> FluxLogDtoGetByFlux(string Valore)
|
||||
{
|
||||
List<FluxLogDTO> answ = new List<FluxLogDTO>();
|
||||
DossierFluxLogDTO? result = JsonConvert.DeserializeObject<DossierFluxLogDTO>(Valore);
|
||||
@@ -736,8 +732,6 @@ namespace MP.IOC.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Init ricetta
|
||||
/// </summary>
|
||||
@@ -1519,7 +1513,6 @@ namespace MP.IOC.Data
|
||||
var listEndpoints = redisConnAdmin.GetEndPoints();
|
||||
foreach (var endPoint in listEndpoints)
|
||||
{
|
||||
//var server = redisConnAdmin.GetServer(listEndpoints[0]);
|
||||
var server = redisConnAdmin.GetServer(endPoint);
|
||||
if (server != null)
|
||||
{
|
||||
@@ -1666,6 +1659,7 @@ namespace MP.IOC.Data
|
||||
bool answ = redisDb.StringSet(Utils.RedKeyHash(valKey), redVal);
|
||||
return answ;
|
||||
}
|
||||
|
||||
public bool RedisSetKey(RedisKey valKey, string redVal, int TTL_sec)
|
||||
{
|
||||
bool answ = redisDb.StringSet(Utils.RedKeyHash(valKey), redVal, TimeSpan.FromSeconds(TTL_sec));
|
||||
@@ -1778,37 +1772,6 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restitusice elenco KVP dei campi della State Machine ingressi nel formato
|
||||
/// key: cState_nVal (current MICRO-STATE + "_" + new Value)
|
||||
/// value: iTipoEv_nState (IdxTipoEv da trasmettere + New MICRO-STATE
|
||||
/// </summary>
|
||||
/// <param name="idxFamIn"></param>
|
||||
/// <returns></returns>
|
||||
public KeyValuePair<string, string>[] StateMachInByKey(int idxFamIn)
|
||||
{
|
||||
// hard coded dimensione vettore DatiMacchine
|
||||
KeyValuePair<string, string>[] answ = new KeyValuePair<string, string>[1];
|
||||
// iniziualizzo con un valore... 0/0
|
||||
answ[0] = new KeyValuePair<string, string>("0", "0");
|
||||
// ORA recupero da memoria redis...
|
||||
try
|
||||
{
|
||||
var currHash = Utils.hSMI(idxFamIn);
|
||||
answ = RedisGetHash(currHash);
|
||||
// se è vuoto... leggo da DB e popolo!
|
||||
if (answ.Length == 0)
|
||||
{
|
||||
answ = resetSMI(idxFamIn);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in compilazione State Machine Ingressi x Redis:{Environment.NewLine}{exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// scrive un evento di keepalive sulla tabella
|
||||
/// </summary>
|
||||
@@ -1845,6 +1808,37 @@ namespace MP.IOC.Data
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restitusice elenco KVP dei campi della State Machine ingressi nel formato
|
||||
/// key: cState_nVal (current MICRO-STATE + "_" + new Value)
|
||||
/// value: iTipoEv_nState (IdxTipoEv da trasmettere + New MICRO-STATE
|
||||
/// </summary>
|
||||
/// <param name="idxFamIn"></param>
|
||||
/// <returns></returns>
|
||||
public KeyValuePair<string, string>[] StateMachInByKey(int idxFamIn)
|
||||
{
|
||||
// hard coded dimensione vettore DatiMacchine
|
||||
KeyValuePair<string, string>[] answ = new KeyValuePair<string, string>[1];
|
||||
// iniziualizzo con un valore... 0/0
|
||||
answ[0] = new KeyValuePair<string, string>("0", "0");
|
||||
// ORA recupero da memoria redis...
|
||||
try
|
||||
{
|
||||
var currHash = Utils.hSMI(idxFamIn);
|
||||
answ = RedisGetHash(currHash);
|
||||
// se è vuoto... leggo da DB e popolo!
|
||||
if (answ.Length == 0)
|
||||
{
|
||||
answ = resetSMI(idxFamIn);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in compilazione State Machine Ingressi x Redis:{Environment.NewLine}{exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Statistiche ODL calcolate (da stored stp_STAT_ODL)
|
||||
/// </summary>
|
||||
@@ -1926,7 +1920,7 @@ namespace MP.IOC.Data
|
||||
{
|
||||
bool answ = false;
|
||||
// recupero intero set valori dossier deserializzando...
|
||||
var fluxLogList = FluxLogGetByFlux(currDoss.Valore);
|
||||
var fluxLogList = FluxLogDtoGetByFlux(currDoss.Valore);
|
||||
await Task.Delay(1);
|
||||
|
||||
// se tutto ok
|
||||
@@ -2042,7 +2036,6 @@ namespace MP.IOC.Data
|
||||
|
||||
#region Private Fields
|
||||
|
||||
|
||||
private static IConfiguration _configuration = null!;
|
||||
private static ILogger<MpDataService> _logger = null!;
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace MP.SPEC.Components
|
||||
await Task.Delay(1);
|
||||
if (currRecord != null)
|
||||
{
|
||||
listaFlux = MDService.getFluxLog(currRecord.Valore);
|
||||
listaFlux = MDService.FluxLogDtoGetByFlux(currRecord.Valore);
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
@@ -261,7 +261,7 @@ namespace MP.SPEC.Components
|
||||
{
|
||||
currRecord = selRec;
|
||||
await RecordSel.InvokeAsync(selRec);
|
||||
listaFlux = MDService.getFluxLog(selRec.Valore);
|
||||
listaFlux = MDService.FluxLogDtoGetByFlux(selRec.Valore);
|
||||
await toggleTableFlux();
|
||||
}
|
||||
|
||||
|
||||
@@ -73,8 +73,6 @@ namespace MP.SPEC.Data
|
||||
|
||||
#region Public Methods
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Recupera eventuali azioni richieste
|
||||
/// </summary>
|
||||
@@ -158,7 +156,7 @@ namespace MP.SPEC.Data
|
||||
string source = "DB";
|
||||
List<ListValues>? result = new List<ListValues>();
|
||||
// cerco in redis...
|
||||
RedisValue rawData = await redisDb.StringGetAsync(redisTipoArt);
|
||||
RedisValue rawData = await redisDb.StringGetAsync(Utils.redisTipoArt);
|
||||
if (!string.IsNullOrEmpty($"{rawData}"))
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<ListValues>>($"{rawData}");
|
||||
@@ -169,7 +167,7 @@ namespace MP.SPEC.Data
|
||||
result = await Task.FromResult(dbController.AnagTipoArtLV());
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(redisTipoArt, rawData, getRandTOut(redisLongTimeCache));
|
||||
await redisDb.StringSetAsync(Utils.redisTipoArt, rawData, getRandTOut(redisLongTimeCache));
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
@@ -191,7 +189,7 @@ namespace MP.SPEC.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string currKey = redisArtByDossier;
|
||||
string currKey = Utils.redisArtByDossier;
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
@@ -241,7 +239,7 @@ namespace MP.SPEC.Data
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string sKey = string.IsNullOrEmpty(searchVal) ? "***" : searchVal;
|
||||
string currKey = $"{redisArtList}:{azienda}:{sKey}";
|
||||
string currKey = $"{Utils.redisArtList}:{azienda}:{sKey}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
@@ -356,7 +354,7 @@ namespace MP.SPEC.Data
|
||||
stopWatch.Start();
|
||||
List<ConfigModel>? result = new List<ConfigModel>();
|
||||
// cerco in redis...
|
||||
RedisValue rawData = await redisDb.StringGetAsync(redisConfKey);
|
||||
RedisValue rawData = await redisDb.StringGetAsync(Utils.redisConfKey);
|
||||
if (!string.IsNullOrEmpty($"{rawData}"))
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<ConfigModel>>($"{rawData}");
|
||||
@@ -369,7 +367,7 @@ namespace MP.SPEC.Data
|
||||
result = await Task.FromResult(dbController.ConfigGetAll());
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(redisConfKey, rawData, getRandTOut(redisLongTimeCache));
|
||||
await redisDb.StringSetAsync(Utils.redisConfKey, rawData, getRandTOut(redisLongTimeCache));
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"ConfigGetAll Read from DB: {ts.TotalMilliseconds}ms");
|
||||
@@ -387,7 +385,7 @@ namespace MP.SPEC.Data
|
||||
/// <returns></returns>
|
||||
public async Task ConfigResetCache()
|
||||
{
|
||||
await redisDb.StringSetAsync(redisConfKey, "");
|
||||
await redisDb.StringSetAsync(Utils.redisConfKey, "");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -422,8 +420,8 @@ namespace MP.SPEC.Data
|
||||
stopWatch.Start();
|
||||
result = await dbController.DossiersDeleteRecord(selRecord);
|
||||
// elimino cache redis...
|
||||
RedisValue pattern = new RedisValue($"{redisDossByMac}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
RedisValue pattern = new RedisValue($"{Utils.redisDossByMac}:*");
|
||||
bool answ = await RedisFlushPatternAsync(pattern);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"DossiersDeleteRecord | IdxMacchina {selRecord.IdxMacchina} | DtRif {selRecord.DtRif} | IdxODL {selRecord.IdxODL} | {ts.TotalMilliseconds}ms");
|
||||
@@ -444,7 +442,7 @@ namespace MP.SPEC.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string currKey = $"{redisDossByMac}:{IdxMacchina}:{CodArticolo}:{DtStart:yyyyMMddHHmm}:{DtEnd:yyyyMMddHHmm}";
|
||||
string currKey = $"{Utils.redisDossByMac}:{IdxMacchina}:{CodArticolo}:{DtStart:yyyyMMddHHmm}:{DtEnd:yyyyMMddHHmm}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
@@ -497,8 +495,8 @@ namespace MP.SPEC.Data
|
||||
// chiamo stored x salvare parametri
|
||||
dbController.DossiersTakeParamsSnapshotLast(IdxMacchina, dtMin, dtMax);
|
||||
// elimino cache redis...
|
||||
RedisValue pattern = new RedisValue($"{redisDossByMac}:*");
|
||||
answ = await ExecFlushRedisPattern(pattern);
|
||||
RedisValue pattern = new RedisValue($"{Utils.redisDossByMac}:*");
|
||||
answ = await RedisFlushPatternAsync(pattern);
|
||||
Log.Info($"Svuotata cache dossier | {pattern}");
|
||||
return answ;
|
||||
}
|
||||
@@ -535,7 +533,7 @@ namespace MP.SPEC.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string readType = "DB";
|
||||
string currKey = $"{redisAnagGruppi}";
|
||||
string currKey = $"{Utils.redisAnagGruppi}";
|
||||
// cerco in redis dato valore sel macchina...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
@@ -587,7 +585,7 @@ namespace MP.SPEC.Data
|
||||
public DateTime ExpiryReloadParamGet()
|
||||
{
|
||||
DateTime dtRif = DateTime.Now;
|
||||
string currKey = $"{redisParamPageExp}";
|
||||
string currKey = $"{Utils.redisParamPageExp}";
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
@@ -604,7 +602,7 @@ namespace MP.SPEC.Data
|
||||
public bool ExpiryReloadParamSet(DateTime expTime)
|
||||
{
|
||||
bool fatto = false;
|
||||
string currKey = $"{redisParamPageExp}";
|
||||
string currKey = $"{Utils.redisParamPageExp}";
|
||||
string rawData = JsonConvert.SerializeObject(expTime);
|
||||
fatto = redisDb.StringSet(currKey, rawData);
|
||||
return fatto;
|
||||
@@ -613,13 +611,35 @@ namespace MP.SPEC.Data
|
||||
public async Task<bool> FlushRedisCache()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
RedisValue pattern = new RedisValue($"{redisBaseAddrSpec}*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
RedisValue pattern = Utils.RedValue("*");
|
||||
bool answ = await RedisFlushPatternAsync(pattern);
|
||||
// rileggo vocabolario.,..
|
||||
ObjVocabolario = VocabolarioGetAll();
|
||||
return answ;
|
||||
}
|
||||
|
||||
public List<FluxLogDTO> FluxLogDtoGetByFlux(string Valore)
|
||||
{
|
||||
List<FluxLogDTO> answ = new List<FluxLogDTO>();
|
||||
DossierFluxLogDTO? result = JsonConvert.DeserializeObject<DossierFluxLogDTO>(Valore);
|
||||
if (result != null)
|
||||
{
|
||||
if (result.ODL != null)
|
||||
{
|
||||
answ = result
|
||||
.ODL
|
||||
.OrderBy(x => x.CodFlux)
|
||||
.ToList();
|
||||
// inizializzo SE necessario
|
||||
foreach (var item in answ)
|
||||
{
|
||||
item.ValoreEdit = String.IsNullOrEmpty(item.ValoreEdit) ? item.Valore : item.ValoreEdit;
|
||||
}
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco ultimi n record flux log dato macchina e flusso (ordinato x data registrazione)
|
||||
/// </summary>
|
||||
@@ -676,28 +696,6 @@ namespace MP.SPEC.Data
|
||||
return Task.FromResult(currTagConf);
|
||||
}
|
||||
|
||||
public List<FluxLogDTO> getFluxLog(string Valore)
|
||||
{
|
||||
List<FluxLogDTO> answ = new List<FluxLogDTO>();
|
||||
DossierFluxLogDTO? result = JsonConvert.DeserializeObject<DossierFluxLogDTO>(Valore);
|
||||
if (result != null)
|
||||
{
|
||||
if (result.ODL != null)
|
||||
{
|
||||
answ = result
|
||||
.ODL
|
||||
.OrderBy(x => x.CodFlux)
|
||||
.ToList();
|
||||
// inizializzo SE necessario
|
||||
foreach (var item in answ)
|
||||
{
|
||||
item.ValoreEdit = String.IsNullOrEmpty(item.ValoreEdit) ? item.Valore : item.ValoreEdit;
|
||||
}
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// restituisce il valore da REDIS associato al tag richeisto
|
||||
/// </summary>
|
||||
@@ -1294,7 +1292,7 @@ namespace MP.SPEC.Data
|
||||
var dbResult = await dbController.PODLDeleteRecord(currRec);
|
||||
// elimino cache redis...
|
||||
RedisValue pattern = new RedisValue($"{redisXdlData}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
bool answ = await RedisFlushPatternAsync(pattern);
|
||||
await Task.Delay(1);
|
||||
return dbResult;
|
||||
}
|
||||
@@ -1309,7 +1307,7 @@ namespace MP.SPEC.Data
|
||||
var dbResult = await dbController.PODL_startSetup(currRec, 0, 1, 1, "");
|
||||
// elimino cache redis...
|
||||
RedisValue pattern = new RedisValue($"{redisXdlData}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
bool answ = await RedisFlushPatternAsync(pattern);
|
||||
await Task.Delay(1);
|
||||
return dbResult;
|
||||
}
|
||||
@@ -1324,7 +1322,7 @@ namespace MP.SPEC.Data
|
||||
var dbResult = await dbController.PODLUpdateRecord(currRec);
|
||||
// elimino cache redis...
|
||||
RedisValue pattern = new RedisValue($"{redisXdlData}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
bool answ = await RedisFlushPatternAsync(pattern);
|
||||
await Task.Delay(1);
|
||||
return dbResult;
|
||||
}
|
||||
@@ -1359,6 +1357,32 @@ namespace MP.SPEC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue flush memoria redis dato pattern
|
||||
/// </summary>
|
||||
/// <param name="pattern"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RedisFlushPatternAsync(RedisValue pattern)
|
||||
{
|
||||
bool answ = false;
|
||||
var listEndpoints = redisConnAdmin.GetEndPoints();
|
||||
foreach (var endPoint in listEndpoints)
|
||||
{
|
||||
var server = redisConnAdmin.GetServer(endPoint);
|
||||
if (server != null)
|
||||
{
|
||||
var keyList = server.Keys(redisDb.Database, pattern);
|
||||
foreach (var item in keyList)
|
||||
{
|
||||
await redisDb.KeyDeleteAsync(item);
|
||||
}
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Statistiche ODL calcolate (da stored stp_STAT_ODL)
|
||||
/// </summary>
|
||||
@@ -1414,7 +1438,7 @@ namespace MP.SPEC.Data
|
||||
{
|
||||
bool answ = false;
|
||||
// recupero intero set valori dossier deserializzando...
|
||||
var fluxLogList = getFluxLog(currDoss.Valore);
|
||||
var fluxLogList = FluxLogDtoGetByFlux(currDoss.Valore);
|
||||
await Task.Delay(1);
|
||||
|
||||
// se tutto ok
|
||||
@@ -1583,41 +1607,12 @@ namespace MP.SPEC.Data
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Esegue flush memoria redis dato pattern
|
||||
/// </summary>
|
||||
/// <param name="pattern"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> ExecFlushRedisPattern(RedisValue 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)
|
||||
{
|
||||
await redisDb.KeyDeleteAsync(item);
|
||||
}
|
||||
// brutalmente rimuovo intero contenuto DB... DANGER
|
||||
//await server.FlushDatabaseAsync();
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
private async Task resetCacheArticoli()
|
||||
{
|
||||
RedisValue pattern = new RedisValue($"{redisArtByDossier}:*");
|
||||
await ExecFlushRedisPattern(pattern);
|
||||
await RedisFlushPatternAsync(pattern);
|
||||
pattern = new RedisValue($"{redisArtList}:*");
|
||||
await ExecFlushRedisPattern(pattern);
|
||||
await RedisFlushPatternAsync(pattern);
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
Reference in New Issue
Block a user