diff --git a/DocumentService.Client/DocumentService.Client.csproj b/DocumentService.Client/DocumentService.Client.csproj index 31e459e..4d1bed0 100644 --- a/DocumentService.Client/DocumentService.Client.csproj +++ b/DocumentService.Client/DocumentService.Client.csproj @@ -11,9 +11,9 @@ icon.png http://git.dd:3000/AppStd/Rec.git digital data document service api client - 1.1.0 - 1.1.0.0 - 1.1.0.0 + 1.2.0 + 1.2.0.0 + 1.2.0.0 enable enable diff --git a/DocumentService.Client/README.md b/DocumentService.Client/README.md index 8837861..402e046 100644 --- a/DocumentService.Client/README.md +++ b/DocumentService.Client/README.md @@ -189,6 +189,8 @@ Alle Beispiele nutzen ausschließlich den statischen `Client`-Einstiegspunkt. Vo #### Swiss QR Code – Validierung und Extraktion in einem Schritt +`InspectSwissQrCodeAsync` gibt immer ein `SwissQrCodeResult` zurück, das sowohl das Validierungsergebnis als auch den extrahierten QR-Code enthält. Für den Zugriff auf den QR-Code stehen zwei gleichwertige Varianten zur Verfügung: + ```csharp using DocumentService.Client; using DocumentService.Client.Models.Results; @@ -197,20 +199,27 @@ byte[] pdfBytes = await File.ReadAllBytesAsync("rechnung.pdf"); SwissQrCodeResult result = await Client.Workflows.InspectSwissQrCodeAsync(pdfBytes); // Validierungsergebnis ist immer verfügbar -Console.WriteLine($"Gültig: {result.Validation.IsValid}"); -Console.WriteLine($"Seiten: {result.Validation.PageCount}"); +Console.WriteLine($"Gültig: {result.Validation.IsValid}"); +Console.WriteLine($"Seiten: {result.Validation.PageCount}"); Console.WriteLine($"Verschlüsselt: {result.Validation.IsEncrypted}"); -// QR-Code nur auswerten wenn Dokument gültig war -if (result.QrCode is not null) +// Variante A: TryExtract – lesbarerer Code, kein expliziter Null-Check notwendig +// (optionale Hilfsmethode; Variante B ist gleichwertig) +if (result.TryExtract(out var qrCode)) { - Console.WriteLine($"Betrag: {result.QrCode.Bill?.Amount} {result.QrCode.Bill?.Currency}"); - Console.WriteLine($"Empfänger: {result.QrCode.Bill?.Creditor?.Name}"); + Console.WriteLine($"Betrag: {qrCode.Bill?.Amount} {qrCode.Bill?.Currency}"); + Console.WriteLine($"Empfänger: {qrCode.Bill?.Creditor?.Name}"); } else { Console.WriteLine("Kein Swiss QR Code gefunden oder Dokument ungültig."); } + +// Variante B: direkter Null-Check auf QrCode +if (result.QrCode is not null) +{ + Console.WriteLine($"Betrag: {result.QrCode.Bill?.Amount} {result.QrCode.Bill?.Currency}"); +} ``` ```vbnet @@ -224,12 +233,19 @@ Console.WriteLine($"Gültig: {result.Validation.IsValid}") Console.WriteLine($"Seiten: {result.Validation.PageCount}") Console.WriteLine($"Verschlüsselt: {result.Validation.IsEncrypted}") -If result.QrCode IsNot Nothing Then - Console.WriteLine($"Betrag: {result.QrCode.Bill?.Amount} {result.QrCode.Bill?.Currency}") - Console.WriteLine($"Empfänger: {result.QrCode.Bill?.Creditor?.Name}") +' Variante A: TryExtract +Dim qrCode As DocumentService.Application.Common.DTOs.SwissQrCodeExtractionResult = Nothing +If result.TryExtract(qrCode) Then + Console.WriteLine($"Betrag: {qrCode.Bill?.Amount} {qrCode.Bill?.Currency}") + Console.WriteLine($"Empfänger: {qrCode.Bill?.Creditor?.Name}") Else Console.WriteLine("Kein Swiss QR Code gefunden oder Dokument ungültig.") End If + +' Variante B: direkter Null-Check +If result.QrCode IsNot Nothing Then + Console.WriteLine($"Betrag: {result.QrCode.Bill?.Amount} {result.QrCode.Bill?.Currency}") +End If ``` ```powershell @@ -242,6 +258,8 @@ Write-Host "Gueltig: $($result.Validation.IsValid)" Write-Host "Seiten: $($result.Validation.PageCount)" Write-Host "Verschluesselt:$($result.Validation.IsEncrypted)" +# TryExtract ist in PowerShell nicht direkt nutzbar (out-Parameter). +# Direkter Null-Check ist hier die einzige Option: if ($null -ne $result.QrCode) { Write-Host "Betrag: $($result.QrCode.Bill.Amount) $($result.QrCode.Bill.Currency)" Write-Host "Empfaenger:$($result.QrCode.Bill.Creditor.Name)" @@ -250,6 +268,8 @@ if ($null -ne $result.QrCode) { } ``` +> **`TryExtract` – Hinweis:** Die Methode ist eine optionale Lesbarkeits-Hilfe und nicht zwingend erforderlich. Der direkte Null-Check auf `result.QrCode` ist gleichwertig. Gibt `TryExtract` `false` zurück, ist der `out`-Parameter `qrCode` `null` – er darf in diesem Fall nicht verwendet werden. + --- ### 1. PDF-Validierung