Aggiunti commenti tramite agente LLM locale su classe BaseServ

This commit is contained in:
Samuele Locatelli
2025-09-20 10:16:03 +02:00
parent 901aaddc7b
commit 7aacf2c226
+56 -18
View File
@@ -13,34 +13,42 @@ 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.
/// </summary>
public class BaseServ
{
#region Public Constructors
/// <summary>
/// Initializes a new instance of the BaseServ class.
/// </summary>
/// <param name="Configuration">Configuration object to retrieve application settings.</param>
/// <param name="RedisConn">Redis connection multiplexer for database operations.</param>
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<string>("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
/// <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.
/// </summary>
private string svgChannel = "";
/// <summary>
/// Configuration object for accessing application settings (e.g., connection strings, service parameters).
/// This is a static instance shared across all instances of BaseServ.
/// </summary>
protected static IConfiguration configuration = null!;
/// <summary>
/// JSON serialization settings to handle circular references (e.g., object references to themselves).
/// Prevents exceptions during serialization by ignoring loops.
/// </summary>
protected JsonSerializerSettings? JSSettings;
/// <summary>
/// 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.
/// </summary>
public MessagePipe CalcDonePipe { get; set; } = null!;
/// <summary>
/// Oggetto per connessione a REDIS
/// Redis connection multiplexer that provides access to Redis database operations.
/// Used for reading and writing data in Redis.
/// </summary>
protected IConnectionMultiplexer redisConn = null!;
//ISubscriber sub = redis.GetSubscriber();
/// <summary>
/// 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.
/// </summary>
protected IDatabase redisDb = null!;
@@ -73,7 +97,8 @@ namespace EgwCoreLib.Lux.Data.Services
#region Protected Properties
/// <summary>
/// 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.
/// </summary>
protected TimeSpan FastCache
{
@@ -81,7 +106,8 @@ namespace EgwCoreLib.Lux.Data.Services
}
/// <summary>
/// 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.
/// </summary>
protected TimeSpan LongCache
{
@@ -89,7 +115,8 @@ namespace EgwCoreLib.Lux.Data.Services
}
/// <summary>
/// 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.
/// </summary>
protected TimeSpan UltraFastCache
{
@@ -97,7 +124,8 @@ namespace EgwCoreLib.Lux.Data.Services
}
/// <summary>
/// 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.
/// </summary>
protected TimeSpan UltraLongCache
{
@@ -108,18 +136,28 @@ 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.
/// </summary>
private static Logger Log = LogManager.GetCurrentClassLogger();
/// <summary>
/// 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.
/// </summary>
private int cacheTtlLong = 60 * 5;
/// <summary>
/// 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.
/// </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.
/// </summary>
private Random rnd = new Random();
#endregion Private Fields