feat(GdPictureOptions): Created to configure parameters related to GdPicture.

- Configure the GdPicture license key via a third-party module entity.
This commit is contained in:
tekh 2025-11-03 15:36:11 +01:00
parent 23d4b2f31e
commit 187f4a42fc
5 changed files with 30 additions and 2 deletions

View File

@ -36,7 +36,7 @@ public class MappingProfile : Profile
CreateMap<Domain.Entities.Receiver, ReceiverDto>(); CreateMap<Domain.Entities.Receiver, ReceiverDto>();
CreateMap<Domain.Entities.EnvelopeReceiverReadOnly, EnvelopeReceiverReadOnlyDto>(); CreateMap<Domain.Entities.EnvelopeReceiverReadOnly, EnvelopeReceiverReadOnlyDto>();
CreateMap<ElementAnnotation, AnnotationDto>(); CreateMap<ElementAnnotation, AnnotationDto>();
CreateMap<ThirdPartyModuleDto, ThirdPartyModule>(); CreateMap<ThirdPartyModule, ThirdPartyModuleDto>();
// DTO to Entity mappings // DTO to Entity mappings
CreateMap<ConfigDto, Config>(); CreateMap<ConfigDto, Config>();

View File

@ -79,7 +79,7 @@ public static class ReadThirdPartyModuleQueryExtensions
/// <param name="active"></param> /// <param name="active"></param>
/// <param name="cancel"></param> /// <param name="cancel"></param>
/// <returns></returns> /// <returns></returns>
public static async Task<string?> ReadThirdPartyModuleLicense(this IMediator mediator, string name, bool active = true, CancellationToken cancel = default) public static async Task<string?> ReadThirdPartyModuleLicenseAsync(this IMediator mediator, string name, bool active = true, CancellationToken cancel = default)
{ {
var modules = await mediator.Send(new ReadThirdPartyModuleQuery() var modules = await mediator.Send(new ReadThirdPartyModuleQuery()
{ {

View File

@ -0,0 +1,9 @@
namespace EnvelopeGenerator.Finalizer.Models;
public class GdPictureOptions
{
/// <summary>
///
/// </summary>
public string License { get; set; } = null!;
}

View File

@ -1,7 +1,11 @@
using EnvelopeGenerator.Application.ThirdPartyModules.Queries;
using EnvelopeGenerator.DependencyInjection; using EnvelopeGenerator.DependencyInjection;
using EnvelopeGenerator.Finalizer; using EnvelopeGenerator.Finalizer;
using EnvelopeGenerator.Finalizer.Models;
using EnvelopeGenerator.Infrastructure; using EnvelopeGenerator.Infrastructure;
using MediatR;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Serilog; using Serilog;
// Load Serilog from appsettings.json // Load Serilog from appsettings.json
@ -61,7 +65,20 @@ try
); );
#endregion Add DB Context, EG Inf. and Services #endregion Add DB Context, EG Inf. and Services
builder.Services.AddOptions<GdPictureOptions>()
.Configure((GdPictureOptions opt, IServiceProvider sp) =>
{
var licenseKey = "GDPICTURE";
using var scope = sp.CreateScope();
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
opt.License = mediator.ReadThirdPartyModuleLicenseAsync(licenseKey).GetAwaiter().GetResult()
?? throw new InvalidOperationException($"License record not found for key: {licenseKey}");
});
var host = builder.Build(); var host = builder.Build();
var licence = host.Services.GetRequiredService<IOptions<GdPictureOptions>>().Value;
host.Run(); host.Run();
Log.Information("The worker was stopped."); Log.Information("The worker was stopped.");

View File

@ -79,6 +79,8 @@ public abstract class EGDbContextBase : DbContext
public DbSet<ClientUser> ClientUsers { get; set; } public DbSet<ClientUser> ClientUsers { get; set; }
public DbSet<ThirdPartyModule> ThirdPartyModules { get; set; }
private readonly DbTriggerParams _triggers; private readonly DbTriggerParams _triggers;
private readonly ILogger private readonly ILogger