using Quadarax.Foundation.Core.Thread; using Quadarax.Application.QLiberace.Base.Services; using Quadarax.Application.QLiberace.Processor.Settings; using Quadarax.Foundation.Core.Logging; using Microsoft.Extensions.Logging; namespace Quadarax.Application.QLiberace.Processor.Workers { internal abstract class QlbrcProcessorWorker : LoopWorker { #region *** Private fields *** protected SettingsService _srvService; protected static int _workerOrdinalCounter = 0; #endregion #region *** Properties *** protected ProcessorSetting? Settings => GetSettings(); #endregion #region *** Constructor *** protected QlbrcProcessorWorker(IWorkerContext context, SettingsService? srvSettings, string workerName, IQLogger logger) : base(workerName, context, logger) { _srvService = srvSettings ?? throw new ArgumentNullException(nameof(srvSettings)); } #endregion #region *** Protected Operations *** protected string GetName(string workerPrefix) { if (string.IsNullOrEmpty(workerPrefix)) workerPrefix = "Worker"; var result = $"{workerPrefix}#{_workerOrdinalCounter}"; Interlocked.Increment(ref _workerOrdinalCounter); return result; } #endregion #region *** Private Operations *** private ProcessorSetting? GetSettings() { var moduleCode = Base.Constants.Modules.Processor.Code; var result = _srvService.GetSettings(moduleCode); if (!result.IsSuccess){ Log(LogSeverityEnum.Error, $"Cannot obtain settings for module '{moduleCode}'!", result.ToAggregateException()); return null; } return result.Value; } #endregion } }