|
|
|
@@ -14,19 +14,24 @@ using System.Threading.Tasks;
|
|
|
|
|
namespace EgwCoreLib.Lux.Data.Services
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// BaseServ class serves as a foundational service for handling Redis operations and message piping.
|
|
|
|
|
/// It provides common configurations, caching strategies, and message delivery mechanisms for derived services.
|
|
|
|
|
/// The class initializes Redis connections, sets up message channels, and manages JSON serialization with loop handling.
|
|
|
|
|
/// Classe base per i servizi che fornisce funzionalità comuni come
|
|
|
|
|
/// - connessione a Redis
|
|
|
|
|
/// - configurazione
|
|
|
|
|
/// - gestione dei messaggi
|
|
|
|
|
/// - strategie di caching.
|
|
|
|
|
///
|
|
|
|
|
/// Questa classe agisce come modello per altri servizi derivati.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class BaseServ
|
|
|
|
|
{
|
|
|
|
|
#region Public Constructors
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the BaseServ class.
|
|
|
|
|
/// Inizializza una nuova istanza della classe BaseServ.
|
|
|
|
|
/// Configura la connessione Redis, carica le impostazioni di configurazione e inizializza il serializzatore JSON.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Configuration">Configuration object to retrieve application settings.</param>
|
|
|
|
|
/// <param name="RedisConn">Redis connection multiplexer for database operations.</param>
|
|
|
|
|
/// <param name="Configuration">Oggetto di configurazione per recuperare le impostazioni dell'applicazione.</param>
|
|
|
|
|
/// <param name="RedisConn">Multiplexer di connessione Redis per operazioni sul database.</param>
|
|
|
|
|
public BaseServ(IConfiguration Configuration, IConnectionMultiplexer RedisConn)
|
|
|
|
|
{
|
|
|
|
|
_config = Configuration;
|
|
|
|
@@ -51,18 +56,14 @@ namespace EgwCoreLib.Lux.Data.Services
|
|
|
|
|
updateChannel += ":*";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// JSON serializer settings to prevent circular reference errors during serialization
|
|
|
|
|
// ReferenceLoopHandling.Ignore ensures that circular references in objects are ignored instead of throwing exceptions
|
|
|
|
|
// Configurazione serializzatore JSON per risolvere errore di loop circolare
|
|
|
|
|
JSSettings = new JsonSerializerSettings()
|
|
|
|
|
{
|
|
|
|
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Initializes a message pipe for communication between calculation services and UI components
|
|
|
|
|
// Messages are sent via the specified Redis channel (svgChannel)
|
|
|
|
|
// Configurazione pipe dei messaggi
|
|
|
|
|
CalcDonePipe = new MessagePipe(redisConn, svgChannel);
|
|
|
|
|
|
|
|
|
|
// init others channel
|
|
|
|
|
BomPipe = new MessagePipe(RedisConn, bomChannel);
|
|
|
|
|
UpdatePipe = new MessagePipe(RedisConn, updateChannel);
|
|
|
|
|
}
|
|
|
|
@@ -72,19 +73,18 @@ namespace EgwCoreLib.Lux.Data.Services
|
|
|
|
|
#region Public Properties
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Message pipe for BOM calculation update
|
|
|
|
|
/// Pipe dei messaggi per la comunicazione riguardo update calcolo BOM
|
|
|
|
|
/// </summary>
|
|
|
|
|
public MessagePipe BomPipe { get; set; } = null!;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Message pipe for delivering completion messages from calculation services to the UI.
|
|
|
|
|
/// Uses Redis to publish messages on the svgChannel for real-time updates.
|
|
|
|
|
/// Pipe dei messaggi per la comunicazione tra servizi di calcolo e interfaccia utente.
|
|
|
|
|
/// I messaggi vengono inviati sul canale Redis definito da svgChannel.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public MessagePipe CalcDonePipe { get; set; } = null!;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Message pipe for delivering generico update to the UI.
|
|
|
|
|
/// Uses Redis to publish messages on the updateChannel for real-time updates.
|
|
|
|
|
/// Pipe dei messaggi per la comunicazione riguardo update generico UI
|
|
|
|
|
/// </summary>
|
|
|
|
|
public MessagePipe UpdatePipe { get; set; } = null!;
|
|
|
|
|
|
|
|
|
@@ -93,26 +93,25 @@ namespace EgwCoreLib.Lux.Data.Services
|
|
|
|
|
#region Protected Fields
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Configuration object for accessing application settings (e.g., connection strings, service parameters).
|
|
|
|
|
/// This is a static instance shared across all instances of BaseServ.
|
|
|
|
|
/// Oggetto di configurazione statico per accedere alle impostazioni dell'applicazione (es. stringhe di connessione).
|
|
|
|
|
/// Condiviso tra tutte le istanze di BaseServ.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected static IConfiguration _config = null!;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// JSON serialization settings to handle circular references (e.g., object references to themselves).
|
|
|
|
|
/// Prevents exceptions during serialization by ignoring loops.
|
|
|
|
|
/// Impostazioni del serializzatore JSON utilizzato per gestire oggetti con riferimenti circolari
|
|
|
|
|
/// (es. oggetti che si fanno riferimento reciprocamente).
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected JsonSerializerSettings? JSSettings;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Redis connection multiplexer that provides access to Redis database operations.
|
|
|
|
|
/// Used for reading and writing data in Redis.
|
|
|
|
|
/// Oggetto per la connessione a Redis utilizzato per operazioni di lettura/scrittura.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected IConnectionMultiplexer redisConn = null!;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Redis database instance used for performing read/write operations.
|
|
|
|
|
/// This database is accessed via the redisConn.GetDatabase() method.
|
|
|
|
|
/// Database Redis utilizzato per le operazioni di lettura/scrittura
|
|
|
|
|
/// nb: ottenuto tramite redisConn.GetDatabase()
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected IDatabase redisDb = null!;
|
|
|
|
|
|
|
|
|
@@ -121,8 +120,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
|
|
|
|
#region Protected Properties
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Cache duration for short-term operations (approximately 1 minute with ±10% variation).
|
|
|
|
|
/// The actual duration is calculated dynamically with a random factor to avoid fixed TTLs.
|
|
|
|
|
/// Durata della cache breve (circa 1 minuto + variazione del +/-10%)
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected TimeSpan FastCache
|
|
|
|
|
{
|
|
|
|
@@ -130,8 +128,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Cache duration for long-term operations (5 minutes with ±10% variation).
|
|
|
|
|
/// Used for data that should be cached for longer periods but still allow some flexibility.
|
|
|
|
|
/// Durata della cache lunga (+ variazione del +/-10%)
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected TimeSpan LongCache
|
|
|
|
|
{
|
|
|
|
@@ -139,8 +136,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Cache duration for very short-term operations (approximately 10 seconds with ±10% variation).
|
|
|
|
|
/// Used for transient data that needs to be refreshed frequently.
|
|
|
|
|
/// Durata della cache molto breve (circa 10 secondi + variazione del +/-10%)
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected TimeSpan UltraFastCache
|
|
|
|
|
{
|
|
|
|
@@ -148,8 +144,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Cache duration for very long-term operations (up to 50 minutes with ±10% variation).
|
|
|
|
|
/// Designed for data that changes infrequently and requires long-term persistence.
|
|
|
|
|
/// Durata della cache molto lunga (+ variazione del +/-10%)
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected TimeSpan UltraLongCache
|
|
|
|
|
{
|
|
|
|
@@ -161,8 +156,8 @@ namespace EgwCoreLib.Lux.Data.Services
|
|
|
|
|
#region Private Fields
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Logger instance for logging events and errors at the class level.
|
|
|
|
|
/// Used to track application behavior and diagnose issues.
|
|
|
|
|
/// Oggetto logger utilizzato per registrare eventi e errori a livello di classe.
|
|
|
|
|
/// Utile per il monitoraggio del comportamento dell'applicazione e la risoluzione di problemi.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
|
@@ -172,31 +167,31 @@ namespace EgwCoreLib.Lux.Data.Services
|
|
|
|
|
private string bomChannel = "";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Duration of long-term cache in seconds (default: 5 minutes).
|
|
|
|
|
/// Used in the LongCache property to define how long data should be cached.
|
|
|
|
|
/// Durata della cache lunga in secondi (predefinito: 5 minuti)
|
|
|
|
|
/// Utilizzato nella proprietà LongCache per definire quanto a lungo i dati devono essere memorizzati in cache.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int cacheTtlLong = 60 * 5;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Duration of short-term cache in seconds (default: 1 minute).
|
|
|
|
|
/// Used in the FastCache and UltraFastCache properties to define short-term cache durations.
|
|
|
|
|
/// Durata della cache breve in secondi (predefinito: 1 minuto)
|
|
|
|
|
/// Utilizzato nelle proprietà FastCache e UltraFastCache per definire la durata della cache breve.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int cacheTtlShort = 60 * 1;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Random number generator for introducing dynamic variability in cache durations.
|
|
|
|
|
/// Used to simulate real-world variations in data freshness and TTL.
|
|
|
|
|
/// Generatore di numeri casuali utilizzato per introdurre variabilità dinamica nelle durate della cache
|
|
|
|
|
/// (simula variazioni reali nella freschezza dei dati e nei tempi di scadenza).
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Random rnd = new Random();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The Redis channel name used for subscribing to and publishing messages.
|
|
|
|
|
/// Default is "svg:img", with a wildcard suffix ":*" to enable dynamic message matching.
|
|
|
|
|
/// Nome del canale Redis utilizzato per l'invio/ricezione di messaggi relativi a img svg.
|
|
|
|
|
/// Predefinito a "svg:img" con suffisso ":*".
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string svgChannel = "";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Redis channel for generic update info
|
|
|
|
|
/// Nome del canale Redis utilizzato per l'invio/ricezione di messaggi di update
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string updateChannel = "";
|
|
|
|
|
|
|
|
|
|