From 9d5e2e6ad2298a1f2f1067275ea74e391b9dae8d Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 25 Feb 2026 13:27:01 +0100 Subject: [PATCH] Refactor FinalizeDocumentJob config to use WorkerOptions Replaces JobOptions and PDFBurnerParams with a new WorkerOptions class that encapsulates all job configuration, including PDF burning parameters as a nested record. Updates service registration and job constructor to use IOptions. Removes obsolete configuration classes and centralizes options management for improved maintainability. --- .../Extensions/ServiceCollectionExtensions.cs | 2 +- .../Jobs/FinalizeDocument/PDFBurnerParams.cs | 18 ------------ .../Jobs/FinalizeDocumentJob.cs | 6 ++-- .../Jobs/JobOptions.cs | 11 ------- .../Jobs/WorkerOptions.cs | 29 +++++++++++++++++++ 5 files changed, 34 insertions(+), 32 deletions(-) delete mode 100644 EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocument/PDFBurnerParams.cs delete mode 100644 EnvelopeGenerator.ServiceHost/Jobs/JobOptions.cs create mode 100644 EnvelopeGenerator.ServiceHost/Jobs/WorkerOptions.cs diff --git a/EnvelopeGenerator.ServiceHost/Extensions/ServiceCollectionExtensions.cs b/EnvelopeGenerator.ServiceHost/Extensions/ServiceCollectionExtensions.cs index 036e3e27..0f9d053f 100644 --- a/EnvelopeGenerator.ServiceHost/Extensions/ServiceCollectionExtensions.cs +++ b/EnvelopeGenerator.ServiceHost/Extensions/ServiceCollectionExtensions.cs @@ -8,7 +8,7 @@ public static class ServiceCollectionExtensions { public static IServiceCollection AddFinalizeDocumentJob(this IServiceCollection services, IConfiguration configuration) { - services.Configure(configuration.GetSection("FinalizeDocumentJob")); + services.Configure(configuration.GetSection(nameof(WorkerOptions))); services.AddSingleton(); services.AddSingleton(); return services; diff --git a/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocument/PDFBurnerParams.cs b/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocument/PDFBurnerParams.cs deleted file mode 100644 index 2d54c50c..00000000 --- a/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocument/PDFBurnerParams.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Drawing; - -namespace EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument; - -public class PDFBurnerParams -{ - public List IgnoredLabels { get; set; } = new() { "Date", "Datum", "ZIP", "PLZ", "Place", "Ort", "Position", "Stellung" }; - - public double TopMargin { get; set; } = 0.1; - - public double YOffset { get; set; } = -0.3; - - public string FontName { get; set; } = "Arial"; - - public int FontSize { get; set; } = 8; - - public FontStyle FontStyle { get; set; } = FontStyle.Italic; -} diff --git a/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocumentJob.cs b/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocumentJob.cs index 39a9eb88..7dfa7b55 100644 --- a/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocumentJob.cs +++ b/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocumentJob.cs @@ -9,12 +9,14 @@ using EnvelopeGenerator.ServiceHost.Exceptions; using EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument; using GdPicture14; using Microsoft.Data.SqlClient; -using Quartz; +using Microsoft.Extensions.Options; namespace EnvelopeGenerator.ServiceHost.Jobs; -public class FinalizeDocumentJob : IJob +public class FinalizeDocumentJob(IOptions options, IConfiguration config) { + private readonly WorkerOptions _options = options.Value; + private readonly LicenseManager _licenseManager = new(); private GdViewer? _gdViewer; diff --git a/EnvelopeGenerator.ServiceHost/Jobs/JobOptions.cs b/EnvelopeGenerator.ServiceHost/Jobs/JobOptions.cs deleted file mode 100644 index 4ae585d3..00000000 --- a/EnvelopeGenerator.ServiceHost/Jobs/JobOptions.cs +++ /dev/null @@ -1,11 +0,0 @@ -using EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument; - -namespace EnvelopeGenerator.ServiceHost.Jobs; - -public class JobOptions -{ - public string ConnectionString { get; set; } = string.Empty; - public string GdPictureLicenseKey { get; set; } = string.Empty; - public bool Debug { get; set; } - public PDFBurnerParams PdfBurnerParams { get; set; } = new(); -} diff --git a/EnvelopeGenerator.ServiceHost/Jobs/WorkerOptions.cs b/EnvelopeGenerator.ServiceHost/Jobs/WorkerOptions.cs new file mode 100644 index 00000000..ae89ff98 --- /dev/null +++ b/EnvelopeGenerator.ServiceHost/Jobs/WorkerOptions.cs @@ -0,0 +1,29 @@ +using EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument; +using System.Drawing; + +namespace EnvelopeGenerator.ServiceHost.Jobs; + +public class WorkerOptions +{ + public string GdPictureLicenseKey { get; set; } = null!; + + [Obsolete("Use ILogger.")] + public bool Debug { get; set; } + + public PDFBurnerParams PdfBurnerParams { get; set; } = new(); + + public record PDFBurnerParams + { + public List IgnoredLabels { get; set; } = ["Date", "Datum", "ZIP", "PLZ", "Place", "Ort", "Position", "Stellung"]; + + public double TopMargin { get; set; } = 0.1; + + public double YOffset { get; set; } = -0.3; + + public string FontName { get; set; } = "Arial"; + + public int FontSize { get; set; } = 8; + + public FontStyle FontStyle { get; set; } = FontStyle.Italic; + } +} \ No newline at end of file