diff --git a/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocumentJob.cs b/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocumentJob.cs index a2478d84..f72d8107 100644 --- a/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocumentJob.cs +++ b/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocumentJob.cs @@ -8,15 +8,18 @@ using GdPicture14; using Microsoft.Data.SqlClient; using Microsoft.Extensions.Options; using EnvelopeGenerator.ServiceHost.Extensions; +using MediatR; +using EnvelopeGenerator.Application.Configuration.Queries; +using EnvelopeGenerator.Application.Common.Dto; namespace EnvelopeGenerator.ServiceHost.Jobs; [Obsolete("ActionService is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")] -public class FinalizeDocumentJob(IOptions options, IConfiguration config, ILogger logger, TempFiles tempFiles, ActionService actionService, PDFBurner pdfBurner, PDFMerger pdfMerger, ReportCreator reportCreator, ConfigModel _configModel, EnvelopeModel _envelopeModel, ReportModel _reportModel, MSSQLServer _database, GdViewer? _gdViewer, LicenseManager licenseManager) +public class FinalizeDocumentJob(IOptions options, IConfiguration config, ILogger logger, TempFiles tempFiles, ActionService actionService, PDFBurner pdfBurner, PDFMerger pdfMerger, ReportCreator reportCreator, EnvelopeModel _envelopeModel, ReportModel _reportModel, MSSQLServer _database, GdViewer? _gdViewer, LicenseManager licenseManager, IMediator mediator) { private readonly WorkerOptions _options = options.Value; - private DbConfig? _config; + private ConfigDto? _config; private const int CompleteWaitTime = 1; private string _parentFolderUid = string.Empty; @@ -30,7 +33,7 @@ public class FinalizeDocumentJob(IOptions options, IConfiguration public byte[]? DocAsByte { get; set; } } - public Task ExecuteAsync(CancellationToken cancellationToken = default) + public async Task ExecuteAsync(CancellationToken cancel = default) { var gdPictureKey = _options.GdPictureLicenseKey; tempFiles.Create(); @@ -40,7 +43,7 @@ public class FinalizeDocumentJob(IOptions options, IConfiguration try { logger.LogDebug("Loading Configuration.."); - _config = _configModel?.LoadConfiguration() ?? throw new InvalidOperationException("Configuration could not be loaded because there is no record"); + _config = await mediator.Send(new ReadDefaultConfigQuery(), cancel); logger.LogDebug("DocumentPath: [{documentPath}]", _config.DocumentPath); logger.LogDebug("ExportPath: [{exportPath}]", _config.ExportPath); @@ -174,8 +177,6 @@ public class FinalizeDocumentJob(IOptions options, IConfiguration { logger.LogDebug("Job execution for [{jobId}] ended", jobId); } - - return Task.FromResult(true); } private void UpdateFileDb(string filePath, long envelopeId) diff --git a/EnvelopeGenerator.ServiceHost/Jobs/State.cs b/EnvelopeGenerator.ServiceHost/Jobs/State.cs index 441ff185..a2f4fa5b 100644 --- a/EnvelopeGenerator.ServiceHost/Jobs/State.cs +++ b/EnvelopeGenerator.ServiceHost/Jobs/State.cs @@ -9,6 +9,5 @@ public class State public int UserId { get; set; } public FormUser? User { get; set; } public Config? Config { get; set; } - public DbConfig? DbConfig { get; set; } public MSSQLServer? Database { get; set; } } \ No newline at end of file