From 45f71e06be9b5e5f23c504dbaea8ad720f444542 Mon Sep 17 00:00:00 2001 From: pitzm Date: Tue, 28 Jan 2025 14:20:04 +0100 Subject: [PATCH] ZUGFeRD Service - Verarbeitung von XML-Belegen --- GUIs.Test.ZUGFeRDTest/Form1.Designer.vb | 39 ++++++++++++----- GUIs.Test.ZUGFeRDTest/Form1.resx | 3 ++ GUIs.Test.ZUGFeRDTest/Form1.vb | 43 +++++++++++++++++-- .../Controllers/ValidationController.cs | 17 +++++++- 4 files changed, 87 insertions(+), 15 deletions(-) diff --git a/GUIs.Test.ZUGFeRDTest/Form1.Designer.vb b/GUIs.Test.ZUGFeRDTest/Form1.Designer.vb index 9bfb5051..ecee4e8f 100644 --- a/GUIs.Test.ZUGFeRDTest/Form1.Designer.vb +++ b/GUIs.Test.ZUGFeRDTest/Form1.Designer.vb @@ -23,13 +23,14 @@ Partial Class Form1 Private Sub InitializeComponent() Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog() - Me.Button1 = New System.Windows.Forms.Button() + Me.btRunJob = New System.Windows.Forms.Button() Me.ListBox1 = New System.Windows.Forms.ListBox() Me.Button2 = New System.Windows.Forms.Button() Me.Button3 = New System.Windows.Forms.Button() Me.Button4 = New System.Windows.Forms.Button() Me.GroupBox1 = New System.Windows.Forms.GroupBox() Me.GroupBox2 = New System.Windows.Forms.GroupBox() + Me.ButtonValidateXMLOnly = New System.Windows.Forms.Button() Me.Button7 = New System.Windows.Forms.Button() Me.GroupBox3 = New System.Windows.Forms.GroupBox() Me.txtMD5Checksum = New System.Windows.Forms.TextBox() @@ -39,6 +40,7 @@ Partial Class Form1 Me.FolderBrowserDialog1 = New System.Windows.Forms.FolderBrowserDialog() Me.GroupBox5 = New System.Windows.Forms.GroupBox() Me.Button5 = New System.Windows.Forms.Button() + Me.OpenFileDialog2 = New System.Windows.Forms.OpenFileDialog() Me.GroupBox1.SuspendLayout() Me.GroupBox2.SuspendLayout() Me.GroupBox3.SuspendLayout() @@ -50,14 +52,14 @@ Partial Class Form1 ' Me.OpenFileDialog1.FileName = "OpenFileDialog1" ' - 'Button1 + 'btRunJob ' - Me.Button1.Location = New System.Drawing.Point(6, 19) - Me.Button1.Name = "Button1" - Me.Button1.Size = New System.Drawing.Size(221, 23) - Me.Button1.TabIndex = 0 - Me.Button1.Text = "Run Job" - Me.Button1.UseVisualStyleBackColor = True + Me.btRunJob.Location = New System.Drawing.Point(6, 19) + Me.btRunJob.Name = "btRunJob" + Me.btRunJob.Size = New System.Drawing.Size(221, 23) + Me.btRunJob.TabIndex = 0 + Me.btRunJob.Text = "Run Job" + Me.btRunJob.UseVisualStyleBackColor = True ' 'ListBox1 ' @@ -99,7 +101,8 @@ Partial Class Form1 ' 'GroupBox1 ' - Me.GroupBox1.Controls.Add(Me.Button1) + Me.GroupBox1.Controls.Add(Me.ButtonValidateXMLOnly) + Me.GroupBox1.Controls.Add(Me.btRunJob) Me.GroupBox1.Location = New System.Drawing.Point(12, 12) Me.GroupBox1.Name = "GroupBox1" Me.GroupBox1.Size = New System.Drawing.Size(360, 92) @@ -119,6 +122,15 @@ Partial Class Form1 Me.GroupBox2.TabStop = False Me.GroupBox2.Text = "Run Functions on a single file (needs Breakpoint)" ' + 'ButtonValidateXMLOnly + ' + Me.ButtonValidateXMLOnly.Location = New System.Drawing.Point(6, 48) + Me.ButtonValidateXMLOnly.Name = "ButtonValidateXMLOnly" + Me.ButtonValidateXMLOnly.Size = New System.Drawing.Size(221, 23) + Me.ButtonValidateXMLOnly.TabIndex = 4 + Me.ButtonValidateXMLOnly.Text = "Run XML Job (spez. Configuration)" + Me.ButtonValidateXMLOnly.UseVisualStyleBackColor = True + ' 'Button7 ' Me.Button7.Location = New System.Drawing.Point(6, 77) @@ -194,6 +206,11 @@ Partial Class Form1 Me.Button5.Text = "Write Binary to PDF" Me.Button5.UseVisualStyleBackColor = True ' + 'OpenFileDialog2 + ' + Me.OpenFileDialog2.FileName = "OpenFileDialog2" + Me.OpenFileDialog2.Filter = "XML files (*.xml)|*.xml" + ' 'Form1 ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) @@ -219,7 +236,7 @@ Partial Class Form1 End Sub Friend WithEvents OpenFileDialog1 As OpenFileDialog - Friend WithEvents Button1 As Button + Friend WithEvents btRunJob As Button Friend WithEvents ListBox1 As ListBox Friend WithEvents Button2 As Button Friend WithEvents Button3 As Button @@ -235,4 +252,6 @@ Partial Class Form1 Friend WithEvents FolderBrowserDialog1 As FolderBrowserDialog Friend WithEvents GroupBox5 As GroupBox Friend WithEvents Button5 As Button + Friend WithEvents ButtonValidateXMLOnly As Button + Friend WithEvents OpenFileDialog2 As OpenFileDialog End Class diff --git a/GUIs.Test.ZUGFeRDTest/Form1.resx b/GUIs.Test.ZUGFeRDTest/Form1.resx index 038d372b..e47e59bf 100644 --- a/GUIs.Test.ZUGFeRDTest/Form1.resx +++ b/GUIs.Test.ZUGFeRDTest/Form1.resx @@ -123,4 +123,7 @@ 159, 17 + + 328, 17 + \ No newline at end of file diff --git a/GUIs.Test.ZUGFeRDTest/Form1.vb b/GUIs.Test.ZUGFeRDTest/Form1.vb index 978ee04d..f1226be1 100644 --- a/GUIs.Test.ZUGFeRDTest/Form1.vb +++ b/GUIs.Test.ZUGFeRDTest/Form1.vb @@ -1,11 +1,10 @@ Imports System.IO Imports System.Security.Cryptography -Imports DigitalData.Modules +Imports DigitalData.Modules.Config Imports DigitalData.Modules.Database Imports DigitalData.Modules.Interfaces Imports DigitalData.Modules.Jobs Imports DigitalData.Modules.Logging -Imports DigitalData.Modules.Config Public Class Form1 Private _logConfig As LogConfig @@ -67,7 +66,7 @@ Public Class Form1 End Try End Function - Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click + Private Sub btRunJob_Click(sender As Object, e As EventArgs) Handles btRunJob.Click Dim oInputPath As String = "E:\TestFiles\ZUGFERDService\Input" Dim DI As DirectoryInfo = New DirectoryInfo(oInputPath) @@ -95,7 +94,7 @@ Public Class Form1 } args = LoadPropertyMapFor(args) - Dim job As New Jobs.ImportZUGFeRDFiles(_logConfig, _mssql) + Dim job As New ImportZUGFeRDFiles(_logConfig, _mssql) job.Start(args) End If @@ -116,6 +115,40 @@ Public Class Form1 End If End Sub + Private Sub ButtonValidateXMLOnly_Click(sender As Object, e As EventArgs) Handles ButtonValidateXMLOnly.Click + Dim oInputPath As String = "E:\DocumentProcessing\Input\" + + Dim DI As DirectoryInfo = New DirectoryInfo(oInputPath) + + Dim oResult As DialogResult = DialogResult.OK + If DI.Exists = False Then + ' Nur öffnen, wenn Pfad ungültig ist + oResult = FolderBrowserDialog1.ShowDialog() + oInputPath = FolderBrowserDialog1.SelectedPath + End If + + If oResult = DialogResult.OK Then + Dim args As New WorkerArgs() With { + .MaxAttachmentSizeInMegaBytes = 10, + .IgnoreRejectionStatus = False, + .NamePortal = "XML TEST FROM FORM", + .WatchDirectory = oInputPath, + .SuccessDirectory = "E:\DocumentProcessing\Output\File\DocumentKindAssigned\ZUGFeRD\Success", + .ErrorDirectory = "E:\DocumentProcessing\Output\File\DocumentKindAssigned\ZUGFeRD\Error\", + .OriginalEmailDirectory = "E:\DocumentProcessing\Output\Original_Eml\", + .RejectedEmailDirectory = "E:\DocumentProcessing\Output\Rejected_eml", + .AttachmentsSubDirectory = "Attachments", + .RejectionTemplateId = 1, + .MinFileAgeInMinutes = 1 + } + args = LoadPropertyMapFor(args) + + Dim job As New ImportZUGFeRDFiles(_logConfig, _mssql) + + job.Start(args) + End If + End Sub + Public Sub WriteLog(pMessage As String, ParamArray pParams As String()) ListBox1.Items.Add(String.Format(pMessage, pParams)) End Sub @@ -246,4 +279,6 @@ Public Class Form1 Stream.Close() End Sub + + End Class diff --git a/WEBSERVICES/ZUGFeRDRESTService/Controllers/ValidationController.cs b/WEBSERVICES/ZUGFeRDRESTService/Controllers/ValidationController.cs index 86f9e6fd..63f32be8 100644 --- a/WEBSERVICES/ZUGFeRDRESTService/Controllers/ValidationController.cs +++ b/WEBSERVICES/ZUGFeRDRESTService/Controllers/ValidationController.cs @@ -10,6 +10,7 @@ using static DigitalData.Modules.Interfaces.ZUGFeRDInterface; using static DigitalData.Modules.Interfaces.PropertyValues; using System.Data.SqlClient; using Microsoft.Extensions.Configuration; +using System.Xml.Linq; namespace ZUGFeRDRESTService.Controllers { @@ -168,7 +169,21 @@ namespace ZUGFeRDRESTService.Controllers _logger.Info("Extracting ZUGFeRD Data from file [{0}]", file.FileName); - oZugferdResult = _zugferd.ExtractZUGFeRDFileWithGDPicture(oStream); + if (file.FileName.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase)) + { + oZugferdResult = _zugferd.ExtractZUGFeRDFileWithGDPicture(oStream); + } + else if (file.FileName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase)) + { + // Für die Verarbeitung von XML-Belegen + var oResult = new ZugferdResult() + { + DataFileName = file.FileName, + XElementObject = XElement.Load(oStream) + }; + + oZugferdResult = _zugferd.SerializeZUGFeRDDocument(oResult); + } _logger.Info("Detected Specification was: [{0}]", oZugferdResult.Specification);