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<WorkerOptions>. Removes obsolete configuration classes and centralizes options management for improved maintainability.
This commit is contained in:
@@ -8,7 +8,7 @@ public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddFinalizeDocumentJob(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.Configure<FinalizeDocumentJobOptions>(configuration.GetSection("FinalizeDocumentJob"));
|
||||
services.Configure<WorkerOptions>(configuration.GetSection(nameof(WorkerOptions)));
|
||||
services.AddSingleton<FinalizeDocumentJob>();
|
||||
services.AddSingleton<IFinalizeDocumentJobRunner, FinalizeDocumentJobRunner>();
|
||||
return services;
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument;
|
||||
|
||||
public class PDFBurnerParams
|
||||
{
|
||||
public List<string> 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;
|
||||
}
|
||||
@@ -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<WorkerOptions> options, IConfiguration config)
|
||||
{
|
||||
private readonly WorkerOptions _options = options.Value;
|
||||
|
||||
private readonly LicenseManager _licenseManager = new();
|
||||
private GdViewer? _gdViewer;
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
29
EnvelopeGenerator.ServiceHost/Jobs/WorkerOptions.cs
Normal file
29
EnvelopeGenerator.ServiceHost/Jobs/WorkerOptions.cs
Normal file
@@ -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<string> 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user