2 Commits

Author SHA1 Message Date
Developer 02
08e2e91e9a feat(program): Konfiguration aus appsettings.json laden
Die Anwendung lädt nun Konfigurationseinstellungen aus einer "appsettings.json"-Datei im Basisverzeichnis.
Dies ermöglicht eine externe Konfiguration ohne Codeänderungen und unterstützt das Neuladen der Einstellungen zur Laufzeit bei Änderungen der Datei.
2025-04-28 09:16:24 +02:00
Developer 02
2966d64455 feat(terminal): ReadDocument-Befehl um PDF-Speicheroptionen erweitert
Optionen `save`, `dir` und `fileName` zum `ReadDocument`-Befehl hinzugefügt.
Wenn `save` aktiviert ist, wird das PDF an dem angegebenen oder dem Standardpfad gespeichert.
Ermöglicht dem Benutzer mehr Kontrolle über Speicherort und Dateinamen.
2025-04-25 19:33:29 +02:00
13 changed files with 75 additions and 66 deletions

View File

@@ -3,23 +3,8 @@
/// <summary> /// <summary>
/// Represents the response for reading a document. /// Represents the response for reading a document.
/// </summary> /// </summary>
public class ReadDocumentResponse public class ReadDocumentResponse : ReadDocumentResponseBase
{ {
/// <summary>
/// The unique identifier of the document.
/// </summary>
public int Guid { get; init; }
/// <summary>
/// The identifier of the associated envelope.
/// </summary>
public int EnvelopeId { get; init; }
/// <summary>
/// The date and time when the document was added.
/// </summary>
public DateTime AddedWhen { get; init; }
/// <summary> /// <summary>
/// The binary data of the document, if available. /// The binary data of the document, if available.
/// </summary> /// </summary>

View File

@@ -0,0 +1,22 @@
namespace EnvelopeGenerator.Application.Documents.Queries.Read;
/// <summary>
/// Represents the response for reading a document.
/// </summary>
public class ReadDocumentResponseBase
{
/// <summary>
/// The unique identifier of the document.
/// </summary>
public int Guid { get; init; }
/// <summary>
/// The identifier of the associated envelope.
/// </summary>
public int EnvelopeId { get; init; }
/// <summary>
/// The date and time when the document was added.
/// </summary>
public DateTime AddedWhen { get; init; }
}

View File

@@ -4,7 +4,6 @@ Imports GdPicture14
Imports Newtonsoft.Json.Linq Imports Newtonsoft.Json.Linq
Imports EnvelopeGenerator.Common.Jobs Imports EnvelopeGenerator.Common.Jobs
Imports System.IO Imports System.IO
Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument
Public Class frmFinalizePDF Public Class frmFinalizePDF
Private Const CONNECTIONSTRING = "Server=sDD-VMP04-SQL17\DD_DEVELOP01;Database=DD_ECM;User Id=sa;Password=+bk8oAbbQP1AzoHtvZUbd+Mbok2f8Fl4miEx1qssJ5yEaEWoQJ9prg4L14fURpPnqi1WMNs9fE4=;" Private Const CONNECTIONSTRING = "Server=sDD-VMP04-SQL17\DD_DEVELOP01;Database=DD_ECM;User Id=sa;Password=+bk8oAbbQP1AzoHtvZUbd+Mbok2f8Fl4miEx1qssJ5yEaEWoQJ9prg4L14fURpPnqi1WMNs9fE4=;"
@@ -16,14 +15,14 @@ Public Class frmFinalizePDF
Private Manager As AnnotationManager Private Manager As AnnotationManager
Private PDFBurner As FinalizeDocument.PDFBurner Private PDFBurner As FinalizeDocument.PDFBurner
Private pGDPictureLicenseKey As String = "kG1Qf9PwmqgR8aDmIW2zI_ebj48RzqAJegRxcystEmkbTGQqfkNBdFOXIb6C_A00Ra8zZkrHdfjqzOPXK7kgkF2YDhvrqKfqh4WDug2vOt0qO31IommzkANSuLjZ4zmraoubyEVd25rE3veQ2h_j7tGIoH_LyIHmy24GaXsxdG0yCzIBMdiLbMMMDwcPY-809KeZ83Grv76OVhFvcbBWyYc251vou1N-kGg5_ZlHDgfWoY85gTLRxafjD3KS_i9ARW4BMiy36y8n7UP2jN8kGRnW_04ubpFtfjJqvtsrP_J9D0x7bqV8xtVtT5JI6dpKsVTiMgDCrIcoFSo5gCC1fw9oUopX4TDCkBQttO4-WHBlOeq9dG5Yb0otonVmJKaQA2tP6sMR-lZDs3ql_WI9t91yPWgpssrJUxSHDd27_LMTH_owJIqkF3NOJd9mYQuAv22oNKFYbH8e41pVKb8cT33Y9CgcQ_sy6YDA5PTuIRi67mjKge_nD9rd0IN213Ir9M_EFWqg9e4haWzIdHXQUo0md70kVhPX4UIH_BKJnxEEnFfoFRNMh77bB0N4jkcBEHPl-ghOERv8dOztf4vCnNpzzWvcLD2cqWIm6THy8XGGq9h4hp8aEreRleSMwv9QQAC7mjLwhQ1rBYkpUHlpTjhTLnMwHknl6HH0Z6zzmsgkRKVyfquv94Pd7QbQfZrRka0ss_48pf9p8hAywEn81Q==" Private pGDPictureLicenseKey As String = "kG1Qf9PwmqgR8aDmIW2zI_ebj48RzqAJegRxcystEmkbTGQqfkNBdFOXIb6C_A00Ra8zZkrHdfjqzOPXK7kgkF2YDhvrqKfqh4WDug2vOt0qO31IommzkANSuLjZ4zmraoubyEVd25rE3veQ2h_j7tGIoH_LyIHmy24GaXsxdG0yCzIBMdiLbMMMDwcPY-809KeZ83Grv76OVhFvcbBWyYc251vou1N-kGg5_ZlHDgfWoY85gTLRxafjD3KS_i9ARW4BMiy36y8n7UP2jN8kGRnW_04ubpFtfjJqvtsrP_J9D0x7bqV8xtVtT5JI6dpKsVTiMgDCrIcoFSo5gCC1fw9oUopX4TDCkBQttO4-WHBlOeq9dG5Yb0otonVmJKaQA2tP6sMR-lZDs3ql_WI9t91yPWgpssrJUxSHDd27_LMTH_owJIqkF3NOJd9mYQuAv22oNKFYbH8e41pVKb8cT33Y9CgcQ_sy6YDA5PTuIRi67mjKge_nD9rd0IN213Ir9M_EFWqg9e4haWzIdHXQUo0md70kVhPX4UIH_BKJnxEEnFfoFRNMh77bB0N4jkcBEHPl-ghOERv8dOztf4vCnNpzzWvcLD2cqWIm6THy8XGGq9h4hp8aEreRleSMwv9QQAC7mjLwhQ1rBYkpUHlpTjhTLnMwHknl6HH0Z6zzmsgkRKVyfquv94Pd7QbQfZrRka0ss_48pf9p8hAywEn81Q=="
Private ReadOnly _pdfBurnerParams As New PDFBurnerParams() Private ReadOnly _ignoredLabels As New List(Of String) From {"Date", "Datum", "ZIP", "PLZ", "Place", "Ort", "Position", "Stellung"}
Private Sub frmFinalizePDF_Load(sender As Object, e As EventArgs) Handles MyBase.Load Private Sub frmFinalizePDF_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LogConfig = New LogConfig(LogConfig.PathType.CustomPath, Application.StartupPath) LogConfig = New LogConfig(LogConfig.PathType.CustomPath, Application.StartupPath)
Database = New MSSQLServer(LogConfig, MSSQLServer.DecryptConnectionString(CONNECTIONSTRING)) Database = New MSSQLServer(LogConfig, MSSQLServer.DecryptConnectionString(CONNECTIONSTRING))
PDFBurner = New FinalizeDocument.PDFBurner(LogConfig, pGDPictureLicenseKey, _pdfBurnerParams) PDFBurner = New FinalizeDocument.PDFBurner(LogConfig, pGDPictureLicenseKey, _ignoredLabels)
Viewer = New GdViewer() Viewer = New GdViewer()
Manager = New AnnotationManager() Manager = New AnnotationManager()

View File

@@ -130,7 +130,7 @@
Public Const DATABASE = "DATABASE" Public Const DATABASE = "DATABASE"
Public Const LOGCONFIG = "LOGCONFIG" Public Const LOGCONFIG = "LOGCONFIG"
Public Const GDPICTURE = "GDPICTURE" Public Const GDPICTURE = "GDPICTURE"
Public Const PDF_BURNER_PARAMS = "PDFBurnerParams" Public Const IGNORED_LABELS = "IgnoredLabels"
Public Const GREEN_300 = "#bbf7d0" Public Const GREEN_300 = "#bbf7d0"
Public Const RED_300 = "#fecaca" Public Const RED_300 = "#fecaca"

View File

@@ -281,7 +281,6 @@
<Compile Include="Entities\ElementStatus.vb" /> <Compile Include="Entities\ElementStatus.vb" />
<Compile Include="Entities\EmailData.vb" /> <Compile Include="Entities\EmailData.vb" />
<Compile Include="Entities\EmailTemplate.vb" /> <Compile Include="Entities\EmailTemplate.vb" />
<Compile Include="Jobs\PDFBurnerParams.vb" />
<Compile Include="Services\TemplateService.vb" /> <Compile Include="Services\TemplateService.vb" />
<Compile Include="Entities\Envelope.vb" /> <Compile Include="Entities\Envelope.vb" />
<Compile Include="Entities\EnvelopeDocument.vb" /> <Compile Include="Entities\EnvelopeDocument.vb" />

View File

@@ -74,8 +74,8 @@ Namespace Jobs
InitializeServices(oState) InitializeServices(oState)
Logger.Debug("Loading PDFBurner..") Logger.Debug("Loading PDFBurner..")
Dim pdfBurnerParams As PDFBurnerParams = pContext.MergedJobDataMap.Item(Constants.PDF_BURNER_PARAMS) Dim ignoredLabels As List(Of String) = pContext.MergedJobDataMap.Item(Constants.IGNORED_LABELS)
PDFBurner = New PDFBurner(LogConfig, oGdPictureKey, pdfBurnerParams) PDFBurner = New PDFBurner(LogConfig, oGdPictureKey, ignoredLabels)
Logger.Debug("Loading PDFMerger..") Logger.Debug("Loading PDFMerger..")
PDFMerger = New PDFMerger(LogConfig, oGdPictureKey) PDFMerger = New PDFMerger(LogConfig, oGdPictureKey)

View File

@@ -16,9 +16,9 @@ Namespace Jobs.FinalizeDocument
Private Const ANNOTATION_TYPE_IMAGE = "pspdfkit/image" Private Const ANNOTATION_TYPE_IMAGE = "pspdfkit/image"
Private Const ANNOTATION_TYPE_INK = "pspdfkit/ink" Private Const ANNOTATION_TYPE_INK = "pspdfkit/ink"
Private Const ANNOTATION_TYPE_WIDGET = "pspdfkit/widget" Private Const ANNOTATION_TYPE_WIDGET = "pspdfkit/widget"
Private Property _pdfBurnerParams As PDFBurnerParams Private Property _ignoredLabels As List(Of String)
Public Sub New(pLogConfig As LogConfig, pGDPictureLicenseKey As String, pdfBurnerParams As PDFBurnerParams) Public Sub New(pLogConfig As LogConfig, pGDPictureLicenseKey As String, ignoredLabels As List(Of String))
MyBase.New(pLogConfig) MyBase.New(pLogConfig)
LicenseManager = New LicenseManager() LicenseManager = New LicenseManager()
@@ -26,7 +26,7 @@ Namespace Jobs.FinalizeDocument
Manager = New AnnotationManager() Manager = New AnnotationManager()
_pdfBurnerParams = pdfBurnerParams _ignoredLabels = ignoredLabels
End Sub End Sub
Public Function BurnInstantJSONAnnotationsToPDF(pSourceBuffer As Byte(), pInstantJSONList As List(Of String)) As Byte() Public Function BurnInstantJSONAnnotationsToPDF(pSourceBuffer As Byte(), pInstantJSONList As List(Of String)) As Byte()
@@ -68,8 +68,7 @@ Namespace Jobs.FinalizeDocument
Private Function AddInstantJSONAnnotationToPDF(pInstantJSON As String) As Boolean Private Function AddInstantJSONAnnotationToPDF(pInstantJSON As String) As Boolean
Try Try
Dim oAnnotationData = JsonConvert.DeserializeObject(Of AnnotationData)(pInstantJSON) Dim oAnnotationData = JsonConvert.DeserializeObject(Of AnnotationData)(pInstantJSON)
oAnnotationData.annotations.Reverse()
Dim formFieldIndex = 0
For Each oAnnotation In oAnnotationData.annotations For Each oAnnotation In oAnnotationData.annotations
Logger.Debug("Adding AnnotationID: " + oAnnotation.id) Logger.Debug("Adding AnnotationID: " + oAnnotation.id)
Select Case oAnnotation.type Select Case oAnnotation.type
@@ -82,12 +81,10 @@ Namespace Jobs.FinalizeDocument
Case ANNOTATION_TYPE_WIDGET Case ANNOTATION_TYPE_WIDGET
'Add form field values 'Add form field values
Dim formFieldValue = oAnnotationData.formFieldValues.FirstOrDefault(Function(fv) fv.name = oAnnotation.id) Dim formFieldValue = oAnnotationData.formFieldValues.FirstOrDefault(Function(fv) fv.name = oAnnotation.id)
If formFieldValue IsNot Nothing AndAlso Not _pdfBurnerParams.IgnoredLabels.Contains(formFieldValue.value) Then If formFieldValue IsNot Nothing AndAlso Not _ignoredLabels.Contains(formFieldValue.value) Then
AddFormFieldValue(oAnnotation, formFieldValue, formFieldIndex) AddFormFieldValue(oAnnotation, formFieldValue)
formFieldIndex += 1
End If End If
End Select End Select
Next Next
Return True Return True
@@ -147,13 +144,13 @@ Namespace Jobs.FinalizeDocument
End Function End Function
Private Function AddFormFieldValue(pAnnotation As Annotation, formFieldValue As FormFieldValue, index As Integer) As Boolean Private Function AddFormFieldValue(pAnnotation As Annotation, formFieldValue As FormFieldValue) As Boolean
Try Try
' Convert pixels to Inches ' Convert pixels to Inches
Dim oBounds = pAnnotation.bbox.Select(AddressOf ToInches).ToList() Dim oBounds = pAnnotation.bbox.Select(AddressOf ToInches).ToList()
Dim oX = oBounds.Item(0) Dim oX = oBounds.Item(0)
Dim oY = oBounds.Item(1) + _pdfBurnerParams.YOffset * index + _pdfBurnerParams.TopMargin Dim oY = oBounds.Item(1)
Dim oWidth = oBounds.Item(2) Dim oWidth = oBounds.Item(2)
Dim oHeight = oBounds.Item(3) Dim oHeight = oBounds.Item(3)
@@ -162,9 +159,9 @@ Namespace Jobs.FinalizeDocument
Dim ant = Manager.AddTextAnnot(oX, oY, oWidth, oHeight, formFieldValue.value) Dim ant = Manager.AddTextAnnot(oX, oY, oWidth, oHeight, formFieldValue.value)
' Set the font properties ' Set the font properties
ant.FontName = _pdfBurnerParams.FontName ant.FontName = "Arial"
ant.FontSize = _pdfBurnerParams.FontSize ant.FontSize = 8
ant.FontStyle = _pdfBurnerParams.FontStyle ant.FontStyle = FontStyle.Italic
Manager.SaveAnnotationsToPage() Manager.SaveAnnotationsToPage()
Return True Return True
Catch ex As Exception Catch ex As Exception

View File

@@ -1,16 +0,0 @@
Imports System.Drawing
Namespace Jobs.FinalizeDocument
Public Class PDFBurnerParams
Public Property IgnoredLabels As New List(Of String) From {"Date", "Datum", "ZIP", "PLZ", "Place", "Ort", "Position", "Stellung"}
Public Property TopMargin As Double = 0.1
Public Property YOffset As Double = -0.3
Public Property FontName As String = "Arial"
Public Property FontSize As Integer = 8
Public Property FontStyle As FontStyle = FontStyle.Italic
End Class
End Namespace

View File

@@ -1,13 +1,16 @@
Imports DigitalData.Modules.Config.ConfigAttributes Imports DigitalData.Modules.Config.ConfigAttributes
Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument
Public Class Config Public Class Config
<ConnectionString> <ConnectionString>
Public Property ConnectionString As String = "" Public Property ConnectionString As String = ""
Public Property Debug As Boolean = False Public Property Debug As Boolean = False
Public Property IntervalInMin As Integer = 1 Public Property IntervalInMin As Integer = 1
Public Property PDFBurnerParams As PDFBurnerParams = New PDFBurnerParams() Public Property IgnoredLabels As List(Of String) = New List(Of String) From {
"Date", "Datum",
"ZIP", "PLZ",
"Place", "Ort",
"Position", "Stellung"
}
End Class End Class

View File

@@ -3,7 +3,6 @@ Imports DigitalData.Modules.Base
Imports DigitalData.Modules.Database Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Imports EnvelopeGenerator.Common.Jobs Imports EnvelopeGenerator.Common.Jobs
Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument
Imports Quartz Imports Quartz
Public Class Scheduler Public Class Scheduler
@@ -12,15 +11,15 @@ Public Class Scheduler
Private Scheduler As IScheduler Private Scheduler As IScheduler
Private ReadOnly ConnectionString As String Private ReadOnly ConnectionString As String
Private ReadOnly LicenseKey As String Private ReadOnly LicenseKey As String
Private Property _pdfBurnerParams As PDFBurnerParams Private Property _ignoredLabels As List(Of String)
Private Const JobName = "CertificateDocumentJob" Private Const JobName = "CertificateDocumentJob"
Public Sub New(pLogConfig As LogConfig, pConnectionString As String, pLicenseKey As String, pdfBurnerParams As PDFBurnerParams) Public Sub New(pLogConfig As LogConfig, pConnectionString As String, pLicenseKey As String, ignoredLabels As List(Of String))
MyBase.New(pLogConfig) MyBase.New(pLogConfig)
ConnectionString = pConnectionString ConnectionString = pConnectionString
LicenseKey = pLicenseKey LicenseKey = pLicenseKey
_pdfBurnerParams = pdfBurnerParams _ignoredLabels = ignoredLabels
Dim oLogProvider = New LogProvider(Logger) Dim oLogProvider = New LogProvider(Logger)
Logging.LogProvider.SetCurrentLogProvider(oLogProvider) Logging.LogProvider.SetCurrentLogProvider(oLogProvider)
@@ -41,7 +40,7 @@ Public Class Scheduler
{Common.Constants.GDPICTURE, LicenseKey}, {Common.Constants.GDPICTURE, LicenseKey},
{Common.Constants.LOGCONFIG, LogConfig}, {Common.Constants.LOGCONFIG, LogConfig},
{Common.Constants.DATABASE, ConnectionString}, {Common.Constants.DATABASE, ConnectionString},
{Common.Constants.PDF_BURNER_PARAMS, _pdfBurnerParams} {Common.Constants.IGNORED_LABELS, _ignoredLabels}
} }
Logger.Debug("Initialized Job [{0}]", JobName) Logger.Debug("Initialized Job [{0}]", JobName)

View File

@@ -55,7 +55,7 @@ Public Class Service
Logger.Debug("Inititalize Quartz") Logger.Debug("Inititalize Quartz")
Scheduler = New Scheduler(LogConfig, Config.ConnectionString, oKey, Config.PDFBurnerParams) Scheduler = New Scheduler(LogConfig, Config.ConnectionString, oKey, Config.IgnoredLabels)
Await Scheduler.Start(Config.IntervalInMin) Await Scheduler.Start(Config.IntervalInMin)
Logger.Info("Started [{0}] !", ServiceName) Logger.Info("Started [{0}] !", ServiceName)

View File

@@ -32,11 +32,27 @@ public class CommandManager
[Subcommand] [Subcommand]
public IEnvelopeReceiverService EnvelopeReceiver => _envelopeReceiverService; public IEnvelopeReceiverService EnvelopeReceiver => _envelopeReceiverService;
[Command] [Command(ArgumentSeparatorStrategy = ArgumentSeparatorStrategy.EndOfOptions)]
public async Task ReadDocument(IConsole console, int? id = null, int? envelopeId = null) public async Task ReadDocument(IConsole console,
[Option(Description = "ID of the document.")] int? id = null,
[Option(Description = "ID of the envelope containing the document.")] int? envelopeId = null,
[Option(Description = "Path to save the PDF")] bool save = false,
[Option(Description = "Directory to save the PDF")] string? dir = null,
[Option(Description = "Name of file to save the PDF")] string? fileName = null)
{ {
ReadDocumentQuery query = new(id, envelopeId); ReadDocumentQuery query = new(id, envelopeId);
var document = await _mediator.Send(query); var document = await _mediator.Send(query);
console.WriteLine(JsonSerializer.Serialize(document, Options)); console.WriteLine(JsonSerializer.Serialize(save ? document as ReadDocumentResponseBase : document, Options));
if (save)
{
dir ??= AppContext.BaseDirectory;
fileName ??= $"D{document?.Guid}E{document?.EnvelopeId}.pdf";
var path = Path.Combine(dir, fileName);
console.WriteLine("Save to " + path);
File.WriteAllBytes(path, document?.ByteData ?? Array.Empty<byte>());
}
} }
} }

View File

@@ -1,4 +1,5 @@
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
namespace EnvelopeGenerator.Terminal; namespace EnvelopeGenerator.Terminal;
@@ -8,6 +9,10 @@ public class Program
{ {
var builder = Host.CreateApplicationBuilder(args); var builder = Host.CreateApplicationBuilder(args);
builder.Configuration
.SetBasePath(AppContext.BaseDirectory)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
var config = builder.Configuration; var config = builder.Configuration;
builder.Services.AddCommandManagerRunner(config); builder.Services.AddCommandManagerRunner(config);