Modules.Interfaces: Fehlerhandling beim Auslesen der Knoten verbessert (Komplexe Typen werden abgefangen, und Arrays werden geprüft und kontrolliert ausgelesen)

This commit is contained in:
2026-09-18 15:20:23 +02:00
parent 857e1366fe
commit 1615727352
2 changed files with 60 additions and 5 deletions

View File

@@ -209,10 +209,9 @@ Public Class ZUGFeRDInterface
Catch ex As Exception Catch ex As Exception
_logger.Error(ex) _logger.Error(ex)
End Try End Try
Else
Return Nothing
End If End If
Return Nothing
End Function End Function
Public Function GetSerializedXMLContentFromFile(oFileInfo As FileInfo) As ZugferdResult Public Function GetSerializedXMLContentFromFile(oFileInfo As FileInfo) As ZugferdResult

View File

@@ -3,6 +3,7 @@ Imports System.Reflection
Imports System.Text.RegularExpressions Imports System.Text.RegularExpressions
Imports System.Xml Imports System.Xml
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Imports GdPicture.Internal.MSOfficeBinary.translator.Spreadsheet.XlsFileFormat.Records
Imports GdPicture.Internal.MSOfficeBinary.translator.Tools Imports GdPicture.Internal.MSOfficeBinary.translator.Tools
Public Class PropertyValues Public Class PropertyValues
@@ -225,9 +226,15 @@ Public Class PropertyValues
' This should hopefully show config errors ' This should hopefully show config errors
If TypeOf oPropertyValue Is List(Of Object) Then If TypeOf oPropertyValue Is List(Of Object) Then
_logger.Warn("Item with specification [{0}] may be configured incorrectly", oTableColumn) _logger.Warn("Item [{0}] may be configured incorrectly", oTableColumn)
oPropertyValue = Nothing oPropertyValue = Nothing
End If End If
If IsComplexeObject(oPropertyValue) = True Then
_logger.Debug("Item Value [{0}] is complexe. cant be used.", oTableColumn)
oPropertyValue = Nothing
End If
End Select End Select
End If End If
Catch ex As Exception Catch ex As Exception
@@ -593,8 +600,21 @@ Public Class PropertyValues
firstElement = oList.FirstOrDefault() firstElement = oList.FirstOrDefault()
If firstElement IsNot Nothing AndAlso IsArray(firstElement) Then If firstElement IsNot Nothing AndAlso IsArray(firstElement) Then
' Attachments sind Byte-Arrays und müssen umgewandelt werden Dim oStr As String
Return Convert.ToBase64String(firstElement) ' Array behandeln -> erstes Element nehmen
If TypeOf firstElement Is String() Then
Dim arr As String() = CType(firstElement, String())
oStr = If(arr.Length > 0, arr(0), String.Empty)
Else
oStr = firstElement.ToString()
End If
If IsBase64String(oStr) Then
' Attachments sind Byte-Arrays und müssen umgewandelt werden
Return Convert.ToBase64String(firstElement)
Else
Return oStr
End If
Else Else
Return DoGetFinalPropValue(oList.First()) Return DoGetFinalPropValue(oList.First())
@@ -636,4 +656,40 @@ Public Class PropertyValues
Return Regex.IsMatch(Prop, _indexPattern) Return Regex.IsMatch(Prop, _indexPattern)
End Function End Function
Private Function IsComplexeObject(obj As Object) As Boolean
If obj Is Nothing Then Return False
Dim t As Type = obj.GetType()
' Einfache Typen ausschließen
If t.IsPrimitive OrElse
t.IsEnum OrElse
t Is GetType(String) OrElse
t Is GetType(Decimal) OrElse
t Is GetType(DateTime) Then
Return False
End If
' Wenn es öffentliche Properties hat, ist es "komplex"
Return t.GetProperties().Length > 0 OrElse t.IsClass
End Function
Function IsBase64String(str As String) As Boolean
If String.IsNullOrEmpty(str) Then Return False
' Base64 hat bestimmte Zeichen und meist Länge Vielfaches von 4
If str.Length Mod 4 <> 0 Then Return False
' Regex-Check für gültige Base64-Zeichen
If Not System.Text.RegularExpressions.Regex.IsMatch(str, "^[A-Za-z0-9+/]*={0,2}$") Then
Return False
End If
Try
Dim bytes As Byte() = Convert.FromBase64String(str)
Return True
Catch ex As FormatException
Return False
End Try
End Function
End Class End Class