Übersetzendie FinalizeDocumentJob-Funktion des EnvelopeGenerator.Service-Projekts in C# und kopieren sie.
This commit is contained in:
@@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Controllers\" />
|
<Folder Include="Controllers\" />
|
||||||
<Folder Include="Extensions\" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using EnvelopeGenerator.ServiceHost.Jobs;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.ServiceHost.Extensions;
|
||||||
|
|
||||||
|
public static class ServiceCollectionExtensions
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddFinalizeDocumentJob(this IServiceCollection services, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
services.Configure<FinalizeDocumentJobOptions>(configuration.GetSection("FinalizeDocumentJob"));
|
||||||
|
services.AddSingleton<FinalizeDocumentJob>();
|
||||||
|
services.AddSingleton<IFinalizeDocumentJobRunner, FinalizeDocumentJobRunner>();
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument;
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.ServiceHost.Jobs;
|
||||||
|
|
||||||
|
public class FinalizeDocumentJobOptions
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
using DigitalData.Modules.Logging;
|
||||||
|
using EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Quartz;
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.ServiceHost.Jobs;
|
||||||
|
|
||||||
|
public interface IFinalizeDocumentJobRunner
|
||||||
|
{
|
||||||
|
Task RunAsync(CancellationToken cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FinalizeDocumentJobRunner : IFinalizeDocumentJobRunner
|
||||||
|
{
|
||||||
|
private readonly FinalizeDocumentJob _job;
|
||||||
|
private readonly IOptions<FinalizeDocumentJobOptions> _options;
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
private readonly ILogger<FinalizeDocumentJobRunner> _logger;
|
||||||
|
|
||||||
|
public FinalizeDocumentJobRunner(
|
||||||
|
FinalizeDocumentJob job,
|
||||||
|
IOptions<FinalizeDocumentJobOptions> options,
|
||||||
|
IConfiguration configuration,
|
||||||
|
ILogger<FinalizeDocumentJobRunner> logger)
|
||||||
|
{
|
||||||
|
_job = job;
|
||||||
|
_options = options;
|
||||||
|
_configuration = configuration;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task RunAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var options = _options.Value;
|
||||||
|
var connectionString = options.ConnectionString;
|
||||||
|
if (string.IsNullOrWhiteSpace(connectionString))
|
||||||
|
{
|
||||||
|
connectionString = _configuration.GetConnectionString("Default") ?? string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(connectionString))
|
||||||
|
{
|
||||||
|
_logger.LogWarning("FinalizeDocumentJob skipped: missing connection string.");
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
var dataMap = new JobDataMap
|
||||||
|
{
|
||||||
|
{ JobDataKeys.GdPicture, options.GdPictureLicenseKey },
|
||||||
|
{ JobDataKeys.Database, connectionString },
|
||||||
|
{ JobDataKeys.LogConfig, new LogConfig { Debug = options.Debug } },
|
||||||
|
{ JobDataKeys.PdfBurnerParams, options.PdfBurnerParams }
|
||||||
|
};
|
||||||
|
|
||||||
|
return _job.Execute(dataMap, cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
EnvelopeGenerator.ServiceHost/Jobs/JobDataKeys.cs
Normal file
9
EnvelopeGenerator.ServiceHost/Jobs/JobDataKeys.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace EnvelopeGenerator.ServiceHost.Jobs;
|
||||||
|
|
||||||
|
public static class JobDataKeys
|
||||||
|
{
|
||||||
|
public const string GdPicture = "GDPICTURE";
|
||||||
|
public const string LogConfig = "LOGCONFIG";
|
||||||
|
public const string Database = "DATABASE";
|
||||||
|
public const string PdfBurnerParams = "PDF_BURNER_PARAMS";
|
||||||
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
using EnvelopeGenerator.ServiceHost;
|
using EnvelopeGenerator.ServiceHost;
|
||||||
|
using EnvelopeGenerator.ServiceHost.Extensions;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
builder.Services.AddFinalizeDocumentJob(builder.Configuration);
|
||||||
builder.Services.AddHostedService<Worker>();
|
builder.Services.AddHostedService<Worker>();
|
||||||
|
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ public class Worker : BackgroundService
|
|||||||
{
|
{
|
||||||
private readonly ILogger<Worker> _logger;
|
private readonly ILogger<Worker> _logger;
|
||||||
private readonly int _delayMilliseconds;
|
private readonly int _delayMilliseconds;
|
||||||
|
private readonly IFinalizeDocumentJobRunner _jobRunner;
|
||||||
|
|
||||||
public Worker(ILogger<Worker> logger, IConfiguration configuration)
|
public Worker(ILogger<Worker> logger, IConfiguration configuration, IFinalizeDocumentJobRunner jobRunner)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_delayMilliseconds = Math.Max(1, configuration.GetValue("Worker:DelayMilliseconds", 1000));
|
_delayMilliseconds = Math.Max(1, configuration.GetValue("Worker:DelayMilliseconds", 1000));
|
||||||
|
_jobRunner = jobRunner;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
@@ -19,6 +21,8 @@ public class Worker : BackgroundService
|
|||||||
{
|
{
|
||||||
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await _jobRunner.RunAsync(stoppingToken);
|
||||||
await Task.Delay(_delayMilliseconds, stoppingToken);
|
await Task.Delay(_delayMilliseconds, stoppingToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user