From 187f4a42fcc237327a13dd6bd25c957461d72226 Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 3 Nov 2025 15:36:11 +0100 Subject: [PATCH] feat(GdPictureOptions): Created to configure parameters related to GdPicture. - Configure the GdPicture license key via a third-party module entity. --- .../Common/Dto/MappingProfile.cs | 2 +- .../Queries/ReadThirdPartyModuleQuery.cs | 2 +- .../Models/GdPictureOptions.cs | 9 +++++++++ EnvelopeGenerator.Finalizer/Program.cs | 17 +++++++++++++++++ EnvelopeGenerator.Infrastructure/EGDbContext.cs | 2 ++ 5 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 EnvelopeGenerator.Finalizer/Models/GdPictureOptions.cs diff --git a/EnvelopeGenerator.Application/Common/Dto/MappingProfile.cs b/EnvelopeGenerator.Application/Common/Dto/MappingProfile.cs index 58b7e50f..9d4ff32d 100644 --- a/EnvelopeGenerator.Application/Common/Dto/MappingProfile.cs +++ b/EnvelopeGenerator.Application/Common/Dto/MappingProfile.cs @@ -36,7 +36,7 @@ public class MappingProfile : Profile CreateMap(); CreateMap(); CreateMap(); - CreateMap(); + CreateMap(); // DTO to Entity mappings CreateMap(); diff --git a/EnvelopeGenerator.Application/ThirdPartyModules/Queries/ReadThirdPartyModuleQuery.cs b/EnvelopeGenerator.Application/ThirdPartyModules/Queries/ReadThirdPartyModuleQuery.cs index 14c53ddb..bbd0da92 100644 --- a/EnvelopeGenerator.Application/ThirdPartyModules/Queries/ReadThirdPartyModuleQuery.cs +++ b/EnvelopeGenerator.Application/ThirdPartyModules/Queries/ReadThirdPartyModuleQuery.cs @@ -79,7 +79,7 @@ public static class ReadThirdPartyModuleQueryExtensions /// /// /// - public static async Task ReadThirdPartyModuleLicense(this IMediator mediator, string name, bool active = true, CancellationToken cancel = default) + public static async Task ReadThirdPartyModuleLicenseAsync(this IMediator mediator, string name, bool active = true, CancellationToken cancel = default) { var modules = await mediator.Send(new ReadThirdPartyModuleQuery() { diff --git a/EnvelopeGenerator.Finalizer/Models/GdPictureOptions.cs b/EnvelopeGenerator.Finalizer/Models/GdPictureOptions.cs new file mode 100644 index 00000000..822fb2d9 --- /dev/null +++ b/EnvelopeGenerator.Finalizer/Models/GdPictureOptions.cs @@ -0,0 +1,9 @@ +namespace EnvelopeGenerator.Finalizer.Models; + +public class GdPictureOptions +{ + /// + /// + /// + public string License { get; set; } = null!; +} \ No newline at end of file diff --git a/EnvelopeGenerator.Finalizer/Program.cs b/EnvelopeGenerator.Finalizer/Program.cs index 61fe8df9..d52a7665 100644 --- a/EnvelopeGenerator.Finalizer/Program.cs +++ b/EnvelopeGenerator.Finalizer/Program.cs @@ -1,7 +1,11 @@ +using EnvelopeGenerator.Application.ThirdPartyModules.Queries; using EnvelopeGenerator.DependencyInjection; using EnvelopeGenerator.Finalizer; +using EnvelopeGenerator.Finalizer.Models; using EnvelopeGenerator.Infrastructure; +using MediatR; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; using Serilog; // Load Serilog from appsettings.json @@ -61,7 +65,20 @@ try ); #endregion Add DB Context, EG Inf. and Services + builder.Services.AddOptions() + .Configure((GdPictureOptions opt, IServiceProvider sp) => + { + var licenseKey = "GDPICTURE"; + using var scope = sp.CreateScope(); + var mediator = scope.ServiceProvider.GetRequiredService(); + opt.License = mediator.ReadThirdPartyModuleLicenseAsync(licenseKey).GetAwaiter().GetResult() + ?? throw new InvalidOperationException($"License record not found for key: {licenseKey}"); + }); + var host = builder.Build(); + + var licence = host.Services.GetRequiredService>().Value; + host.Run(); Log.Information("The worker was stopped."); diff --git a/EnvelopeGenerator.Infrastructure/EGDbContext.cs b/EnvelopeGenerator.Infrastructure/EGDbContext.cs index 468aaa4c..fd42c824 100644 --- a/EnvelopeGenerator.Infrastructure/EGDbContext.cs +++ b/EnvelopeGenerator.Infrastructure/EGDbContext.cs @@ -79,6 +79,8 @@ public abstract class EGDbContextBase : DbContext public DbSet ClientUsers { get; set; } + public DbSet ThirdPartyModules { get; set; } + private readonly DbTriggerParams _triggers; private readonly ILogger