Compare commits
26 Commits
e5295b8302
...
feat/servi
| Author | SHA1 | Date | |
|---|---|---|---|
| cb7d154f64 | |||
| a3f404b9ae | |||
| 1f7eb5d4ea | |||
| e1ae3ffccb | |||
| 3e3bfaa904 | |||
| f8422ed94c | |||
| c64c63925e | |||
| 2c8ae23203 | |||
| b4be718994 | |||
| 33bf5b1a51 | |||
| 6a9792bb57 | |||
| 6954a86358 | |||
| d6c5b63c49 | |||
| 8ca360d47e | |||
| 2dadefecc5 | |||
| 162f066b08 | |||
| 6592642945 | |||
| 855f22cf87 | |||
| 726673e277 | |||
| 65d615f43e | |||
| f0f92c5400 | |||
| 7e34f01f6a | |||
| f449767bf9 | |||
| f8ec6065c2 | |||
| fabfe80666 | |||
| bdb3863c07 |
@@ -71,6 +71,7 @@ public class EnvelopeController : ControllerBase
|
|||||||
[HttpGet("doc-result")]
|
[HttpGet("doc-result")]
|
||||||
public async Task<IActionResult> GetDocResultAsync([FromQuery] ReadEnvelopeQuery query, [FromQuery] bool view = false)
|
public async Task<IActionResult> GetDocResultAsync([FromQuery] ReadEnvelopeQuery query, [FromQuery] bool view = false)
|
||||||
{
|
{
|
||||||
|
query.IncludeDocResult = true;
|
||||||
var envelopes = await _mediator.Send(query.Authorize(User.GetId()));
|
var envelopes = await _mediator.Send(query.Authorize(User.GetId()));
|
||||||
var envelope = envelopes.FirstOrDefault();
|
var envelope = envelopes.FirstOrDefault();
|
||||||
|
|
||||||
|
|||||||
@@ -14,4 +14,10 @@ public record EnvelopeQueryBase
|
|||||||
/// Die universell eindeutige Kennung des Umschlags.
|
/// Die universell eindeutige Kennung des Umschlags.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual string? Uuid { get; set; }
|
public virtual string? Uuid { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Wenn gesetzt, wird das DocResult-Feld in der Abfrage einbezogen.
|
||||||
|
/// Standardmäßig wird DocResult nicht geladen, um große Binärdaten zu vermeiden.
|
||||||
|
/// </summary>
|
||||||
|
public bool IncludeDocResult { get; set; } = false;
|
||||||
}
|
}
|
||||||
@@ -39,6 +39,7 @@ public class ReadSingleEnvelopeDocResultQueryHandler : IRequestHandler<ReadSingl
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<byte[]> Handle(ReadSingleEnvelopeDocResultQuery request, CancellationToken cancellationToken)
|
public async Task<byte[]> Handle(ReadSingleEnvelopeDocResultQuery request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
request.Envelope.IncludeDocResult = true;
|
||||||
var result = await _mediator.Send(request.Envelope, cancellationToken);
|
var result = await _mediator.Send(request.Envelope, cancellationToken);
|
||||||
return result.DocResult is byte[] docResult && docResult.Length > 0
|
return result.DocResult is byte[] docResult && docResult.Length > 0
|
||||||
? docResult
|
? docResult
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
using DigitalData.Core.Abstraction.Application.Repository;
|
||||||
|
using DigitalData.Core.Exceptions;
|
||||||
|
using EnvelopeGenerator.Domain.Entities;
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.Application.ThirdPartyModules.Queries;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query to read the license text of a third-party module.
|
||||||
|
/// Either <see cref="Id"/> or <see cref="Name"/> must be provided, but not both.
|
||||||
|
/// </summary>
|
||||||
|
public record ReadThirdPartyModuleLicenseQuery : IRequest<string>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The unique identifier of the third-party module (optional).
|
||||||
|
/// </summary>
|
||||||
|
public int? Id { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The name of the third-party module (optional).
|
||||||
|
/// </summary>
|
||||||
|
public string? Name { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether to filter only active modules. Defaults to <c>true</c>.
|
||||||
|
/// </summary>
|
||||||
|
public bool Active { get; init; } = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles <see cref="ReadThirdPartyModuleLicenseQuery"/> and returns the license text of a third-party module.
|
||||||
|
/// </summary>
|
||||||
|
public class ReadThirdPartyModuleLicenseQueryHandler : IRequestHandler<ReadThirdPartyModuleLicenseQuery, string>
|
||||||
|
{
|
||||||
|
private readonly IRepository<ThirdPartyModule> _repository;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ReadThirdPartyModuleLicenseQueryHandler"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="repository">The repository for accessing third-party modules.</param>
|
||||||
|
public ReadThirdPartyModuleLicenseQueryHandler(IRepository<ThirdPartyModule> repository)
|
||||||
|
{
|
||||||
|
_repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles the query by filtering on Id or Name and returning the license text.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">The query parameters.</param>
|
||||||
|
/// <param name="cancel">A cancellation token.</param>
|
||||||
|
/// <returns>The license text of the matching third-party module.</returns>
|
||||||
|
/// <exception cref="BadRequestException">
|
||||||
|
/// Thrown when neither Id nor Name is provided, or when both are provided.
|
||||||
|
/// </exception>
|
||||||
|
/// <exception cref="InvalidOperationException">
|
||||||
|
/// Thrown when multiple modules match the given criteria, indicating a data integrity issue.
|
||||||
|
/// </exception>
|
||||||
|
/// <exception cref="NotFoundException">
|
||||||
|
/// Thrown when no module matches the given criteria.
|
||||||
|
/// </exception>
|
||||||
|
public async Task<string> Handle(ReadThirdPartyModuleLicenseQuery request, CancellationToken cancel)
|
||||||
|
{
|
||||||
|
if (request.Id is null && request.Name is null)
|
||||||
|
throw new BadRequestException("Either Id or Name must be provided.");
|
||||||
|
|
||||||
|
if (request.Id is not null && request.Name is not null)
|
||||||
|
throw new BadRequestException("Only one of Id or Name must be provided, not both.");
|
||||||
|
|
||||||
|
var query = _repository.Query
|
||||||
|
.Where(m => m.Active == request.Active);
|
||||||
|
|
||||||
|
if (request.Id is int id)
|
||||||
|
query = query.Where(m => m.Id == id);
|
||||||
|
|
||||||
|
if (request.Name is string name)
|
||||||
|
query = query.Where(m => m.Name == name);
|
||||||
|
|
||||||
|
var modules = await query
|
||||||
|
.Take(2)
|
||||||
|
.ToListAsync(cancel);
|
||||||
|
|
||||||
|
if (modules.Count > 1)
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
$"Data integrity violation: multiple third-party modules found for the given criteria (Id={request.Id}, Name={request.Name}, Active={request.Active}).");
|
||||||
|
|
||||||
|
return modules.SingleOrDefault() is ThirdPartyModule module
|
||||||
|
? module.License
|
||||||
|
: throw new NotFoundException(
|
||||||
|
$"Third-party module not found for the given criteria (Id={request.Id}, Name={request.Name}, Active={request.Active}).");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -140,7 +140,9 @@ namespace EnvelopeGenerator.Domain.Entities
|
|||||||
= false;
|
= false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if NETFRAMEWORK
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
|
#endif
|
||||||
[Column("DOC_RESULT")]
|
[Column("DOC_RESULT")]
|
||||||
public byte[]
|
public byte[]
|
||||||
#if nullable
|
#if nullable
|
||||||
|
|||||||
61
EnvelopeGenerator.Domain/Entities/ThirdPartyModule.cs
Normal file
61
EnvelopeGenerator.Domain/Entities/ThirdPartyModule.cs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using EnvelopeGenerator.Domain.Interfaces.Auditing;
|
||||||
|
#if NETFRAMEWORK
|
||||||
|
using System;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.Domain.Entities
|
||||||
|
{
|
||||||
|
[Table("TBDD_3RD_PARTY_MODULES", Schema = "dbo")]
|
||||||
|
public class ThirdPartyModule : IHasChangedWhen, IHasChangedWho
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
|
[Column("GUID")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[Column("ACTIVE", TypeName = "bit")]
|
||||||
|
public bool Active { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[Column("NAME", TypeName = "varchar(50)")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[Column("DESCRIPTION", TypeName = "varchar(500)")]
|
||||||
|
public string
|
||||||
|
#if nullable
|
||||||
|
?
|
||||||
|
#endif
|
||||||
|
Description { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[Column("LICENSE", TypeName = "varchar(max)")]
|
||||||
|
public string License { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[Column("VERSION", TypeName = "varchar(20)")]
|
||||||
|
public string Version { get; set; }
|
||||||
|
|
||||||
|
[Column("ADDED_WHO", TypeName = "varchar(50)")]
|
||||||
|
public string
|
||||||
|
#if nullable
|
||||||
|
?
|
||||||
|
#endif
|
||||||
|
AddedWho { get; set; }
|
||||||
|
|
||||||
|
[Column("ADDED_WHEN", TypeName = "datetime")]
|
||||||
|
public DateTime? AddedWhen { get; set; }
|
||||||
|
|
||||||
|
[Column("CHANGED_WHO", TypeName = "varchar(50)")]
|
||||||
|
public string
|
||||||
|
#if nullable
|
||||||
|
?
|
||||||
|
#endif
|
||||||
|
ChangedWho { get; set; }
|
||||||
|
|
||||||
|
[Column("CHANGED_WHEN", TypeName = "datetime")]
|
||||||
|
public DateTime? ChangedWhen { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -81,6 +81,8 @@ public abstract class EGDbContextBase : DbContext
|
|||||||
|
|
||||||
public DbSet<EnvelopeReport> EnvelopeReports { get; set; }
|
public DbSet<EnvelopeReport> EnvelopeReports { get; set; }
|
||||||
|
|
||||||
|
public DbSet<ThirdPartyModule> ThirdPartyModules { get; set; }
|
||||||
|
|
||||||
private readonly DbTriggerParams _triggers;
|
private readonly DbTriggerParams _triggers;
|
||||||
|
|
||||||
private readonly ILogger
|
private readonly ILogger
|
||||||
|
|||||||
@@ -9,8 +9,13 @@ namespace EnvelopeGenerator.ServiceHost.Controllers;
|
|||||||
public class DocResultController(IMediator mediator) : ControllerBase
|
public class DocResultController(IMediator mediator) : ControllerBase
|
||||||
{
|
{
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> GetAsync([FromQuery] ReadSingleEnvelopeDocResultQuery query, CancellationToken cancel = default)
|
public async Task<IActionResult> GetAsync([FromQuery] ReadSingleEnvelopeDocResultQuery query, [FromQuery] bool download = false, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
return File(await mediator.Send(query, cancel), "application/pdf", $"envelope_{query.Envelope.Uuid}.pdf");
|
var bytes = await mediator.Send(query, cancel);
|
||||||
|
|
||||||
|
if (download)
|
||||||
|
return File(bytes, "application/pdf", $"envelope_{query.Envelope.Uuid}.pdf");
|
||||||
|
|
||||||
|
return File(bytes, "application/pdf");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,44 +1,21 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using EnvelopeGenerator.ServiceHost.Jobs;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.ServiceHost.Controllers;
|
namespace EnvelopeGenerator.ServiceHost.Controllers;
|
||||||
|
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class WorkerController(IEnumerable<IHostedService> hostedServices, ILogger<WorkerController> logger) : ControllerBase
|
public class WorkerController(JobStateManager jobStateManager) : ControllerBase
|
||||||
{
|
{
|
||||||
private Worker? Worker => hostedServices.OfType<Worker>().FirstOrDefault();
|
private readonly JobStateManager _jobStateManager = jobStateManager;
|
||||||
|
|
||||||
[HttpPost("stop")]
|
[HttpGet(nameof(FinalizeDocumentJob))]
|
||||||
public async Task<IActionResult> Stop(CancellationToken cancel)
|
public IActionResult GetStateOfFinalizeDocumentJob() => Ok(_jobStateManager.GetState<FinalizeDocumentJob>());
|
||||||
|
|
||||||
|
[HttpPost(nameof(FinalizeDocumentJob))]
|
||||||
|
public IActionResult SetStateOfFinalizeDocumentJob([FromQuery] State state)
|
||||||
{
|
{
|
||||||
if (Worker is null)
|
_jobStateManager.SetState<FinalizeDocumentJob>(state);
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
logger.LogInformation("Stopping Worker via API request.");
|
|
||||||
await Worker.StopAsync(cancel);
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost("start")]
|
|
||||||
public async Task<IActionResult> Start(CancellationToken cancel)
|
|
||||||
{
|
|
||||||
if (Worker is null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
logger.LogInformation("Starting Worker via API request.");
|
|
||||||
await Worker.StartAsync(cancel);
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost("restart")]
|
|
||||||
public async Task<IActionResult> Restart(CancellationToken cancel)
|
|
||||||
{
|
|
||||||
if (Worker is null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
logger.LogInformation("Restarting Worker via API request.");
|
|
||||||
await Worker.StopAsync(cancel);
|
|
||||||
await Worker.StartAsync(cancel);
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0-windows</TargetFramework>
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
@@ -20,7 +20,8 @@
|
|||||||
<PackageReference Include="System.Drawing.Common" Version="8.0.16" />
|
<PackageReference Include="System.Drawing.Common" Version="8.0.16" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
|
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
|
||||||
<PackageReference Include="DevExpress.Reporting.Core" Version="24.2.*" />
|
<PackageReference Include="DevExpress.Reporting.Core" Version="24.2.*" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Caching.SqlServer" Version="8.0.17" />
|
<PackageReference Include="Microsoft.Extensions.Caching.SqlServer" Version="8.0.17" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using EnvelopeGenerator.ServiceHost.Jobs;
|
using EnvelopeGenerator.ServiceHost.Jobs;
|
||||||
using EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument;
|
using EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument;
|
||||||
using EnvelopeGenerator.ServiceHost.Jobs.Infrastructure;
|
|
||||||
using GdPicture14;
|
using GdPicture14;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
@@ -11,23 +10,23 @@ public static class DependencyInjection
|
|||||||
[Obsolete("Check obsoleted services")]
|
[Obsolete("Check obsoleted services")]
|
||||||
public static IServiceCollection AddFinalizeDocumentJob(this IServiceCollection services, IConfiguration configuration)
|
public static IServiceCollection AddFinalizeDocumentJob(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
services.Configure<WorkerOptions>(configuration.GetSection(nameof(WorkerOptions)));
|
services.Configure<WorkerOptions>(configuration.GetSection("Worker"));
|
||||||
services.AddSingleton<FinalizeDocumentJob>();
|
services.AddSingleton(provider =>
|
||||||
|
{
|
||||||
|
var options = provider.GetRequiredService<IOptions<WorkerOptions>>().Value;
|
||||||
|
var manager = new JobStateManager(options.InitialJobState);
|
||||||
|
return manager;
|
||||||
|
});
|
||||||
|
services.AddScoped<FinalizeDocumentJob>();
|
||||||
services.AddScoped<ActionService>();
|
services.AddScoped<ActionService>();
|
||||||
services.AddSingleton<TempFiles>();
|
services.AddSingleton<TempFiles>();
|
||||||
services.AddScoped<PDFBurner>();
|
services.AddScoped<PDFBurner>();
|
||||||
services.AddScoped<PDFMerger>();
|
services.AddScoped<PDFMerger>();
|
||||||
|
services.AddScoped<ReportCreator>();
|
||||||
|
|
||||||
//TODO: Check lifetime of services. They might be singleton or scoped.
|
//TODO: Check lifetime of services. They might be singleton or scoped.
|
||||||
services.AddTransient<GdViewer>();
|
services.AddTransient<GdViewer>();
|
||||||
// Add LicenseManager
|
services.AddSingleton<LicenseManagerFactory>();
|
||||||
services.AddTransient(provider =>
|
|
||||||
{
|
|
||||||
var options = provider.GetRequiredService<IOptions<WorkerOptions>>().Value;
|
|
||||||
var licenseManager = new LicenseManager();
|
|
||||||
licenseManager.RegisterKEY(options.GdPictureLicenseKey);
|
|
||||||
return licenseManager;
|
|
||||||
});
|
|
||||||
services.AddTransient<AnnotationManager>();
|
services.AddTransient<AnnotationManager>();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using EnvelopeGenerator.Domain.Entities;
|
|||||||
using EnvelopeGenerator.Infrastructure;
|
using EnvelopeGenerator.Infrastructure;
|
||||||
using EnvelopeGenerator.PdfEditor;
|
using EnvelopeGenerator.PdfEditor;
|
||||||
using EnvelopeGenerator.ServiceHost.Exceptions;
|
using EnvelopeGenerator.ServiceHost.Exceptions;
|
||||||
|
using EnvelopeGenerator.ServiceHost.Jobs;
|
||||||
using GdPicture14;
|
using GdPicture14;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
@@ -11,16 +12,7 @@ using Newtonsoft.Json;
|
|||||||
|
|
||||||
namespace EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument;
|
namespace EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument;
|
||||||
|
|
||||||
//TODO: check if licence manager is needed as a dependency to
|
public class PDFBurner(IOptions<WorkerOptions> workerOptions, EGDbContext context, ILogger<PDFBurner> logger, LicenseManagerFactory licenseManagerFactory, AnnotationManager manager)
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="workerOptions"></param>
|
|
||||||
/// <param name="context2"></param>
|
|
||||||
/// <param name="logger2"></param>
|
|
||||||
/// <param name="licenseManager"></param>
|
|
||||||
/// <param name="annotationManager2"></param>
|
|
||||||
public class PDFBurner(IOptions<WorkerOptions> workerOptions, EGDbContext context, ILogger<PDFBurner> logger, LicenseManager licenseManager, AnnotationManager manager)
|
|
||||||
{
|
{
|
||||||
private readonly WorkerOptions.PDFBurnerOptions _options = workerOptions.Value.PdfBurner;
|
private readonly WorkerOptions.PDFBurnerOptions _options = workerOptions.Value.PdfBurner;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using EnvelopeGenerator.ServiceHost.Exceptions;
|
using EnvelopeGenerator.ServiceHost.Exceptions;
|
||||||
|
using EnvelopeGenerator.ServiceHost.Jobs;
|
||||||
using GdPicture14;
|
using GdPicture14;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
@@ -7,16 +8,16 @@ namespace EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument;
|
|||||||
public class PDFMerger
|
public class PDFMerger
|
||||||
{
|
{
|
||||||
private readonly AnnotationManager _manager;
|
private readonly AnnotationManager _manager;
|
||||||
private readonly LicenseManager _licenseManager;
|
private readonly LicenseManagerFactory _licenseManagerFactory;
|
||||||
|
|
||||||
private const bool AllowRasterization = true;
|
private const bool AllowRasterization = true;
|
||||||
private const bool AllowVectorization = true;
|
private const bool AllowVectorization = true;
|
||||||
|
|
||||||
private readonly PdfConversionConformance _pdfaConformanceLevel = PdfConversionConformance.PDF_A_1b;
|
private readonly PdfConversionConformance _pdfaConformanceLevel = PdfConversionConformance.PDF_A_1b;
|
||||||
|
|
||||||
public PDFMerger(LicenseManager licenseManager, AnnotationManager annotationManager)
|
public PDFMerger(LicenseManagerFactory licenseManagerFactory, AnnotationManager annotationManager)
|
||||||
{
|
{
|
||||||
_licenseManager = licenseManager;
|
_licenseManagerFactory = licenseManagerFactory;
|
||||||
_manager = annotationManager;
|
_manager = annotationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ public class FinalizeDocumentJob(IOptions<WorkerOptions> options, ILogger<Finali
|
|||||||
|
|
||||||
public async Task ExecuteAsync(IEnumerable<EnvelopeDto> envelopes, CancellationToken cancel = default)
|
public async Task ExecuteAsync(IEnumerable<EnvelopeDto> envelopes, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
var gdPictureKey = _options.GdPictureLicenseKey;
|
|
||||||
tempFiles.Create();
|
tempFiles.Create();
|
||||||
var jobId = typeof(FinalizeDocumentJob).FullName;
|
var jobId = typeof(FinalizeDocumentJob).FullName;
|
||||||
|
|
||||||
|
|||||||
19
EnvelopeGenerator.ServiceHost/Jobs/JobStateManager.cs
Normal file
19
EnvelopeGenerator.ServiceHost/Jobs/JobStateManager.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using AngleSharp.Common;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.ServiceHost.Jobs;
|
||||||
|
|
||||||
|
public class JobStateManager(Dictionary<string, State>? initialState = null)
|
||||||
|
{
|
||||||
|
private readonly ConcurrentDictionary<Type, State> _states = new();
|
||||||
|
|
||||||
|
public State GetState<TJob>() => _states.GetOrAdd(typeof(TJob), type => initialState?.GetOrDefault(type.Name, State.Stopped) ?? State.Stopped);
|
||||||
|
|
||||||
|
public State SetState<TJob>(State state) => _states[typeof(TJob)] = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum State
|
||||||
|
{
|
||||||
|
Running,
|
||||||
|
Stopped
|
||||||
|
}
|
||||||
39
EnvelopeGenerator.ServiceHost/Jobs/LicenseManagerFactory.cs
Normal file
39
EnvelopeGenerator.ServiceHost/Jobs/LicenseManagerFactory.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using EnvelopeGenerator.Application.ThirdPartyModules.Queries;
|
||||||
|
using GdPicture14;
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.ServiceHost.Jobs;
|
||||||
|
|
||||||
|
public class LicenseManagerFactory
|
||||||
|
{
|
||||||
|
private static readonly string _cacheKey = Guid.NewGuid().ToString();
|
||||||
|
private readonly IServiceScopeFactory scopeFactory;
|
||||||
|
private readonly IMemoryCache cache;
|
||||||
|
|
||||||
|
public LicenseManagerFactory(IServiceScopeFactory scopeFactory, IMemoryCache cache)
|
||||||
|
{
|
||||||
|
this.scopeFactory = scopeFactory;
|
||||||
|
this.cache = cache;
|
||||||
|
_ = CreateAsync(); // Preload the license key into the cache
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<LicenseManager> CreateAsync(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var key = await GetLicenseKeyAsync(cancellationToken);
|
||||||
|
var licenseManager = new LicenseManager();
|
||||||
|
licenseManager.RegisterKEY(key);
|
||||||
|
return licenseManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string> GetLicenseKeyAsync(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await cache.GetOrCreateAsync(_cacheKey, async entry =>
|
||||||
|
{
|
||||||
|
entry.Priority = CacheItemPriority.NeverRemove;
|
||||||
|
using var scope = scopeFactory.CreateScope();
|
||||||
|
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
|
||||||
|
return await mediator.Send(new ReadThirdPartyModuleLicenseQuery { Name = "GdPicture", Active =true }, cancellationToken);
|
||||||
|
}) ?? throw new InvalidOperationException("License key could not be retrieved.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,22 @@
|
|||||||
using EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument;
|
|
||||||
using System.Drawing;
|
|
||||||
|
|
||||||
namespace EnvelopeGenerator.ServiceHost.Jobs;
|
namespace EnvelopeGenerator.ServiceHost.Jobs;
|
||||||
|
|
||||||
public class WorkerOptions
|
public class WorkerOptions
|
||||||
{
|
{
|
||||||
public string GdPictureLicenseKey { get; set; } = null!;
|
private int _delayMilliseconds = 1000;
|
||||||
|
|
||||||
|
public int DelayMilliseconds
|
||||||
|
{
|
||||||
|
get => _delayMilliseconds;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value < 1)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(value), "Delay must be at least 1 millisecond.");
|
||||||
|
|
||||||
|
_delayMilliseconds = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dictionary<string, State> InitialJobState { get; set; } = [];
|
||||||
|
|
||||||
public PDFBurnerOptions PdfBurner { get; set; } = new();
|
public PDFBurnerOptions PdfBurner { get; set; } = new();
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using EnvelopeGenerator.Application;
|
|||||||
using EnvelopeGenerator.Infrastructure;
|
using EnvelopeGenerator.Infrastructure;
|
||||||
using EnvelopeGenerator.ServiceHost;
|
using EnvelopeGenerator.ServiceHost;
|
||||||
using EnvelopeGenerator.ServiceHost.Extensions;
|
using EnvelopeGenerator.ServiceHost.Extensions;
|
||||||
|
using EnvelopeGenerator.ServiceHost.Middleware;
|
||||||
using Microsoft.AspNetCore.Localization;
|
using Microsoft.AspNetCore.Localization;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
@@ -15,12 +16,12 @@ if (builder.Configuration.GetValue<bool>("UseWindowsService"))
|
|||||||
builder.Host.UseWindowsService();
|
builder.Host.UseWindowsService();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (builder.Configuration.GetValue<bool>("UseKestrelConfig"))
|
if (builder.Configuration.GetValue<bool>("UseCustomKestrelEndpoints"))
|
||||||
{
|
{
|
||||||
builder.WebHost.ConfigureKestrel((context, serverOptions) =>
|
builder.WebHost.ConfigureKestrel((context, serverOptions) =>
|
||||||
{
|
{
|
||||||
var kestrelSection = context.Configuration.GetSection("Kestrel");
|
var serverConfigSection = context.Configuration.GetSection("ServerConfig");
|
||||||
serverOptions.Configure(kestrelSection);
|
serverOptions.Configure(serverConfigSection);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@@ -65,6 +66,8 @@ builder.Services.AddSwaggerGen();
|
|||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
app.UseMiddleware<ExceptionHandlingMiddleware>();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,17 +1,20 @@
|
|||||||
using EnvelopeGenerator.ServiceHost.Jobs;
|
using EnvelopeGenerator.ServiceHost.Jobs;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.ServiceHost;
|
namespace EnvelopeGenerator.ServiceHost;
|
||||||
|
|
||||||
public class Worker : BackgroundService
|
public class Worker : BackgroundService
|
||||||
{
|
{
|
||||||
private readonly ILogger<Worker> _logger;
|
private readonly ILogger<Worker> _logger;
|
||||||
private readonly int _delayMilliseconds;
|
private readonly WorkerOptions _options;
|
||||||
|
private readonly JobStateManager _jobStateManager;
|
||||||
private readonly IServiceScopeFactory _scopeFactory;
|
private readonly IServiceScopeFactory _scopeFactory;
|
||||||
|
|
||||||
public Worker(ILogger<Worker> logger, IConfiguration configuration, IServiceScopeFactory scopeFactory)
|
public Worker(ILogger<Worker> logger, IOptions<WorkerOptions> options, JobStateManager jobStateManager, IServiceScopeFactory scopeFactory)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_delayMilliseconds = Math.Max(1, configuration.GetValue("Worker:DelayMilliseconds", 1000));
|
_options = options.Value;
|
||||||
|
_jobStateManager = jobStateManager;
|
||||||
_scopeFactory = scopeFactory;
|
_scopeFactory = scopeFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,11 +27,14 @@ public class Worker : BackgroundService
|
|||||||
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||||
}
|
}
|
||||||
|
|
||||||
using var scope = _scopeFactory.CreateScope();
|
if (_jobStateManager.GetState<FinalizeDocumentJob>() == State.Running)
|
||||||
var finalizeDocumentJob = scope.ServiceProvider.GetRequiredService<FinalizeDocumentJob>();
|
{
|
||||||
await finalizeDocumentJob.ExecuteAsync(stoppingToken);
|
using var scope = _scopeFactory.CreateScope();
|
||||||
|
var finalizeDocumentJob = scope.ServiceProvider.GetRequiredService<FinalizeDocumentJob>();
|
||||||
|
await finalizeDocumentJob.ExecuteAsync(stoppingToken);
|
||||||
|
}
|
||||||
|
|
||||||
await Task.Delay(_delayMilliseconds, stoppingToken);
|
await Task.Delay(_options.DelayMilliseconds, stoppingToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Information"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Worker": {
|
"Worker": {
|
||||||
"DelayMilliseconds": 1000
|
"DelayMilliseconds": 1000,
|
||||||
|
// InitialJobState: State values are 0 = Running, 1 = Stopped. Defaults to 1 (Stopped) if not specified.
|
||||||
|
"InitialJobState": {
|
||||||
|
"FinalizeDocumentJob": 0
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"SupportedCultures": [ "de-DE", "en-US" ],
|
"SupportedCultures": [ "de-DE", "en-US" ],
|
||||||
@@ -14,8 +18,8 @@
|
|||||||
"Default": "Server=SDD-VMP04-SQL17\\DD_DEVELOP01;Database=DD_ECM;User Id=sa;Password=dd;Encrypt=false;TrustServerCertificate=True;"
|
"Default": "Server=SDD-VMP04-SQL17\\DD_DEVELOP01;Database=DD_ECM;User Id=sa;Password=dd;Encrypt=false;TrustServerCertificate=True;"
|
||||||
},
|
},
|
||||||
"UseWindowsService": false,
|
"UseWindowsService": false,
|
||||||
"UseKestrelConfig": false,
|
"UseCustomKestrelEndpoints": false,
|
||||||
"Kestrel": {
|
"ServerConfig": {
|
||||||
"Endpoints": {
|
"Endpoints": {
|
||||||
"Http": {
|
"Http": {
|
||||||
"Url": "http://localhost:1111"
|
"Url": "http://localhost:1111"
|
||||||
|
|||||||
Reference in New Issue
Block a user