Continuo ottimizzazione oggetti in memoria
This commit is contained in:
@@ -216,6 +216,7 @@ namespace MP.SPEC.Components
|
||||
.Select(x => x.IdxMacchina)
|
||||
.ToHashSet();
|
||||
|
||||
|
||||
ListStati = await MDService.AnagStatiComm();
|
||||
ListArtKit = MDService.ArticoliGetByTipo("KIT", "*");
|
||||
string strMachRecipe = await MDService.ConfigTryGetAsync("MachineWithRecipe");
|
||||
@@ -354,6 +355,8 @@ namespace MP.SPEC.Components
|
||||
#region Private Fields
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private HashSet<string> _machinesWithArch = new();
|
||||
private HashSet<string> _machinesWithConf = new();
|
||||
private string currRecipeArchPath = "";
|
||||
|
||||
/// <summary>
|
||||
@@ -585,14 +588,8 @@ namespace MP.SPEC.Components
|
||||
private bool machineHasRecipeArch(string idxMacchina)
|
||||
{
|
||||
return _machinesWithArch.Contains(idxMacchina);
|
||||
//var recipeArchive = MDService.MacchineRecipeArchive(idxMacchina);
|
||||
//return !string.IsNullOrEmpty(recipeArchive);
|
||||
}
|
||||
|
||||
|
||||
private HashSet<string> _machinesWithConf = new();
|
||||
private HashSet<string> _machinesWithArch = new();
|
||||
|
||||
/// <summary>
|
||||
/// Verifica se la idxMaccSel abbia associata una ricetta (template)
|
||||
/// </summary>
|
||||
@@ -601,8 +598,6 @@ namespace MP.SPEC.Components
|
||||
private bool machineHasRecipeConf(string idxMacchina)
|
||||
{
|
||||
return _machinesWithConf.Contains(idxMacchina);
|
||||
//var recipePath = MDService.MacchineRecipeConf(idxMacchina);
|
||||
//return !string.IsNullOrEmpty(recipePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+113
-35
@@ -68,22 +68,6 @@ namespace MP.SPEC.Data
|
||||
Log.Info("MpDataService | INIT completed");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper trace messaggio log (SE abilitato)
|
||||
/// </summary>
|
||||
/// <param name="traceMsg"></param>
|
||||
private void LogTrace(string traceMsg, NLog.LogLevel? reqLevel = null)
|
||||
{
|
||||
if (!traceEnabled)
|
||||
return;
|
||||
|
||||
reqLevel ??= NLog.LogLevel.Debug;
|
||||
|
||||
// Loggo!
|
||||
Log.Log(reqLevel, traceMsg);
|
||||
}
|
||||
private bool traceEnabled = false;
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Events
|
||||
@@ -98,6 +82,7 @@ namespace MP.SPEC.Data
|
||||
#region Public Properties
|
||||
|
||||
public static MpSpecController dbController { get; set; } = null!;
|
||||
|
||||
public static MpMongoController mongoController { get; set; } = null!;
|
||||
|
||||
public MessagePipe BroadastMsgPipe { get; set; } = null!;
|
||||
@@ -688,6 +673,20 @@ namespace MP.SPEC.Data
|
||||
/// <returns></returns>
|
||||
public string ConfigTryGet(string keyName)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("ConfigTryGet");
|
||||
string source = "MEMORY";
|
||||
|
||||
EnsureConfigLoaded();
|
||||
|
||||
_configData.TryGetValue(keyName, out var value);
|
||||
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
|
||||
LogTrace($"ConfigTryGet Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
return value ?? "";
|
||||
|
||||
#if false
|
||||
string answ = "";
|
||||
using var activity = ActivitySource.StartActivity("ConfigTryGet");
|
||||
string source = "DB+REDIS";
|
||||
@@ -712,7 +711,8 @@ namespace MP.SPEC.Data
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
LogTrace($"ConfigTryGet Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
return answ;
|
||||
return answ;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -722,6 +722,20 @@ namespace MP.SPEC.Data
|
||||
/// <returns></returns>
|
||||
public async Task<string> ConfigTryGetAsync(string keyName)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("ConfigTryGetAsync");
|
||||
string source = "MEMORY";
|
||||
|
||||
await EnsureConfigLoadedAsync();
|
||||
|
||||
_configData.TryGetValue(keyName, out var value);
|
||||
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
|
||||
LogTrace($"ConfigTryGetAsync Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
return value ?? "";
|
||||
|
||||
#if false
|
||||
string answ = "";
|
||||
using var activity = ActivitySource.StartActivity("ConfigTryGetAsync");
|
||||
string source = "DB+REDIS";
|
||||
@@ -747,6 +761,7 @@ namespace MP.SPEC.Data
|
||||
activity?.Stop();
|
||||
LogTrace($"ConfigTryGetAsync Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
return answ;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1728,6 +1743,7 @@ namespace MP.SPEC.Data
|
||||
LogTrace($"MacchineGetFilt | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco di tutte le macchine filtrate x gruppo
|
||||
/// </summary>
|
||||
@@ -2037,6 +2053,24 @@ namespace MP.SPEC.Data
|
||||
using var activity = ActivitySource.StartActivity("ODLClose");
|
||||
string source = "DB";
|
||||
bool fatto = false;
|
||||
|
||||
await EnsureConfigLoadedAsync();
|
||||
bool confRett = false;
|
||||
_configData.TryGetValue("confRett", out var value);
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
bool.TryParse(value, out confRett);
|
||||
}
|
||||
int modoConfProd = 0;
|
||||
_configData.TryGetValue("modoConfProd", out var vModo);
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
int.TryParse(vModo, out modoConfProd);
|
||||
}
|
||||
// chiamo metodo conferma!
|
||||
fatto = await dbController.ODLClose(idxOdl, idxMacchina, matrOpr, confPezzi, confRett, modoConfProd);
|
||||
|
||||
#if false
|
||||
// recupero dati x conf modalità conferma
|
||||
var configData = await ConfigGetAllAsync();
|
||||
if (configData != null)
|
||||
@@ -2055,7 +2089,8 @@ namespace MP.SPEC.Data
|
||||
}
|
||||
// chiamo metodo conferma!
|
||||
fatto = await dbController.ODLClose(idxOdl, idxMacchina, matrOpr, confPezzi, confRett, modoConfProd);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
LogTrace($"ODLClose | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
@@ -2760,6 +2795,21 @@ namespace MP.SPEC.Data
|
||||
LogTrace($"ResetMicrostatoMacchina | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Statistiche ODL calcolate (da stored stp_STAT_ODL)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<List<StatODLModel>> StatOdl(int IdxOdl)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("StatOdl");
|
||||
string source = "DB";
|
||||
var result = dbController.OdlStart(IdxOdl);
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
LogTrace($"StatOdl | {source} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stato macchina
|
||||
/// </summary>
|
||||
@@ -2796,21 +2846,6 @@ namespace MP.SPEC.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Statistiche ODL calcolate (da stored stp_STAT_ODL)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<List<StatODLModel>> StatOdl(int IdxOdl)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("StatOdl");
|
||||
string source = "DB";
|
||||
var result = dbController.OdlStart(IdxOdl);
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
LogTrace($"StatOdl | {source} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il valore da REDIS associato al tag richiesto
|
||||
/// </summary>
|
||||
@@ -2982,7 +3017,7 @@ namespace MP.SPEC.Data
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update valore Dossier
|
||||
/// Update valore Dossier
|
||||
/// </summary>
|
||||
/// <param name="currDoss"></param>
|
||||
/// <param name="editFL"></param>
|
||||
@@ -3277,6 +3312,8 @@ namespace MP.SPEC.Data
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private Dictionary<string, string> _configData = new();
|
||||
|
||||
private string MpIoNS = "";
|
||||
|
||||
/// <summary>
|
||||
@@ -3303,14 +3340,18 @@ namespace MP.SPEC.Data
|
||||
|
||||
private int redisShortTimeCache = 2;
|
||||
|
||||
private bool traceEnabled = false;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Cache dati config
|
||||
/// </summary>
|
||||
private List<ConfigModel> configData { get; set; } = new List<ConfigModel>();
|
||||
private List<ConfigModel> configData { get; set; } = new List<ConfigModel>();
|
||||
#endif
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
@@ -3327,6 +3368,43 @@ namespace MP.SPEC.Data
|
||||
ExecFlushRedisPattern(pattern);
|
||||
}
|
||||
}
|
||||
private void EnsureConfigLoaded()
|
||||
{
|
||||
if (_configData.Count == 0)
|
||||
{
|
||||
var list = ConfigGetAll();
|
||||
|
||||
_configData = list
|
||||
.GroupBy(x => x.Chiave)
|
||||
.ToDictionary(g => g.Key, g => g.First().Valore);
|
||||
}
|
||||
}
|
||||
private async Task EnsureConfigLoadedAsync()
|
||||
{
|
||||
if (_configData.Count == 0)
|
||||
{
|
||||
var list = await ConfigGetAllAsync();
|
||||
|
||||
_configData = list
|
||||
.GroupBy(x => x.Chiave)
|
||||
.ToDictionary(g => g.Key, g => g.First().Valore);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper trace messaggio log (SE abilitato)
|
||||
/// </summary>
|
||||
/// <param name="traceMsg"></param>
|
||||
private void LogTrace(string traceMsg, NLog.LogLevel? reqLevel = null)
|
||||
{
|
||||
if (!traceEnabled)
|
||||
return;
|
||||
|
||||
reqLevel ??= NLog.LogLevel.Trace;
|
||||
|
||||
// Loggo!
|
||||
Log.Log(reqLevel, traceMsg);
|
||||
}
|
||||
|
||||
private async Task<bool> POdlFlushCache()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user