diff --git a/EgwCoreLib.Lux.Data/Services/BaseServ.cs b/EgwCoreLib.Lux.Data/Services/BaseServ.cs index 1cb1d8c8..65a9fb33 100644 --- a/EgwCoreLib.Lux.Data/Services/BaseServ.cs +++ b/EgwCoreLib.Lux.Data/Services/BaseServ.cs @@ -13,34 +13,42 @@ using System.Threading.Tasks; namespace EgwCoreLib.Lux.Data.Services { + /// + /// 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. + /// public class BaseServ { #region Public Constructors + /// + /// Initializes a new instance of the BaseServ class. + /// + /// Configuration object to retrieve application settings. + /// Redis connection multiplexer for database operations. public BaseServ(IConfiguration Configuration, IConnectionMultiplexer RedisConn) { configuration = Configuration; - - // setup componenti REDIS -#if false - redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis") ?? "localhost"); -#endif redisConn = RedisConn; redisDb = redisConn.GetDatabase(); svgChannel = configuration.GetValue("ServerConf:SvgChannel") ?? "svg:img"; - // aggiungo ricerca generica ":*" al channel... + // Appends ":*" to the SVG channel to enable wildcard subscription for dynamic events if (!svgChannel.EndsWith(":*")) { svgChannel += ":*"; } - // json serializer... FIX errore loop circolare https://www.ryadel.com/en/jsonserializationexception-self-referencing-loop-detected-error-fix-entity-framework-asp-net-core/ + // JSON serializer settings to prevent circular reference errors during serialization + // ReferenceLoopHandling.Ignore ensures that circular references in objects are ignored instead of throwing exceptions JSSettings = new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; - // conf message pipe + + // Initializes a message pipe for communication between calculation services and UI components + // Messages are sent via the specified Redis channel (svgChannel) CalcDonePipe = new MessagePipe(redisConn, svgChannel); } @@ -48,23 +56,39 @@ namespace EgwCoreLib.Lux.Data.Services #region Protected Fields + /// + /// The Redis channel name used for subscribing to and publishing messages. + /// Default is "svg:img", with a wildcard suffix ":*" to enable dynamic message matching. + /// private string svgChannel = ""; + + /// + /// Configuration object for accessing application settings (e.g., connection strings, service parameters). + /// This is a static instance shared across all instances of BaseServ. + /// protected static IConfiguration configuration = null!; + + /// + /// JSON serialization settings to handle circular references (e.g., object references to themselves). + /// Prevents exceptions during serialization by ignoring loops. + /// protected JsonSerializerSettings? JSSettings; /// - /// Message pipe esecuzione elaborazione EgwCalc >> UI + /// Message pipe for delivering completion messages from calculation services to the UI. + /// Uses Redis to publish messages on the svgChannel for real-time updates. /// public MessagePipe CalcDonePipe { get; set; } = null!; /// - /// Oggetto per connessione a REDIS + /// Redis connection multiplexer that provides access to Redis database operations. + /// Used for reading and writing data in Redis. /// protected IConnectionMultiplexer redisConn = null!; - //ISubscriber sub = redis.GetSubscriber(); /// - /// Oggetto DB redis da impiegare x chiamate R/W + /// Redis database instance used for performing read/write operations. + /// This database is accessed via the redisConn.GetDatabase() method. /// protected IDatabase redisDb = null!; @@ -73,7 +97,8 @@ namespace EgwCoreLib.Lux.Data.Services #region Protected Properties /// - /// Durata cache breve (1 min circa + perturbazione percentuale +/-10%) + /// 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. /// protected TimeSpan FastCache { @@ -81,7 +106,8 @@ namespace EgwCoreLib.Lux.Data.Services } /// - /// Durata cache lunga (+ perturbazione percentuale +/-10%) + /// 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. /// protected TimeSpan LongCache { @@ -89,7 +115,8 @@ namespace EgwCoreLib.Lux.Data.Services } /// - /// Durata cache MOLTO breve (10 sec circa + perturbazione percentuale +/-10%) + /// Cache duration for very short-term operations (approximately 10 seconds with ±10% variation). + /// Used for transient data that needs to be refreshed frequently. /// protected TimeSpan UltraFastCache { @@ -97,7 +124,8 @@ namespace EgwCoreLib.Lux.Data.Services } /// - /// Durata cache MOLTO lunga (+ perturbazione percentuale +/-10%) + /// 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. /// protected TimeSpan UltraLongCache { @@ -108,18 +136,28 @@ namespace EgwCoreLib.Lux.Data.Services #region Private Fields + /// + /// Logger instance for logging events and errors at the class level. + /// Used to track application behavior and diagnose issues. + /// private static Logger Log = LogManager.GetCurrentClassLogger(); /// - /// Durata cache lunga IN SECONDI + /// Duration of long-term cache in seconds (default: 5 minutes). + /// Used in the LongCache property to define how long data should be cached. /// private int cacheTtlLong = 60 * 5; /// - /// Durata cache breve IN SECONDI + /// Duration of short-term cache in seconds (default: 1 minute). + /// Used in the FastCache and UltraFastCache properties to define short-term cache durations. /// private int cacheTtlShort = 60 * 1; + /// + /// Random number generator for introducing dynamic variability in cache durations. + /// Used to simulate real-world variations in data freshness and TTL. + /// private Random rnd = new Random(); #endregion Private Fields