refactor(application): update processor interfaces for Stream API

- IPdfProcessor: ValidateAsync, ValidatePdfAAsync, CheckAttachmentsAsync now accept Stream
- ISwissQrCodeProcessor: ExtractSwissQrCodeAsync now accepts Stream
- Update XML documentation: Position=0 requirement, non-seekable stream support
- Exception documentation: BadRequestException for validation errors (stream empty/invalid/wrong position)
This commit is contained in:
2026-07-20 16:31:31 +02:00
parent c93488c29f
commit 5dc2e38507
2 changed files with 23 additions and 11 deletions

View File

@@ -7,30 +7,39 @@ public interface IPdfProcessor
/// <summary> /// <summary>
/// Validates a PDF and extracts metadata. /// Validates a PDF and extracts metadata.
/// </summary> /// </summary>
/// <param name="pdfStream">PDF content as stream (caller is responsible for disposal)</param> /// <param name="pdfStream">
/// PDF document stream. Must be readable and positioned at the beginning (Position = 0).
/// Non-seekable streams are supported. Caller is responsible for disposal.
/// </param>
/// <returns>PDF metadata (page count, size, version, attachments)</returns> /// <returns>PDF metadata (page count, size, version, attachments)</returns>
/// <exception cref="Domain.Common.Exceptions.BadRequestException"> /// <exception cref="Domain.Common.Exceptions.BadRequestException">
/// Thrown when stream is empty or invalid /// Thrown when stream is empty, invalid, or not positioned at the beginning
/// </exception> /// </exception>
Task<PdfMetadata> ValidateAsync(Stream pdfStream); Task<PdfMetadata> ValidateAsync(Stream pdfStream);
/// <summary> /// <summary>
/// Validates a PDF/A document and checks conformance level. /// Validates a PDF/A document and checks conformance level.
/// </summary> /// </summary>
/// <param name="pdfStream">PDF content as stream (caller is responsible for disposal)</param> /// <param name="pdfStream">
/// PDF document stream. Must be readable and positioned at the beginning (Position = 0).
/// Non-seekable streams are supported. Caller is responsible for disposal.
/// </param>
/// <returns>PDF/A metadata including conformance level and validation errors/warnings</returns> /// <returns>PDF/A metadata including conformance level and validation errors/warnings</returns>
/// <exception cref="Domain.Common.Exceptions.BadRequestException"> /// <exception cref="Domain.Common.Exceptions.BadRequestException">
/// Thrown when stream is empty or invalid /// Thrown when stream is empty, invalid, or not positioned at the beginning
/// </exception> /// </exception>
Task<PdfAMetadata> ValidatePdfAAsync(Stream pdfStream); Task<PdfAMetadata> ValidatePdfAAsync(Stream pdfStream);
/// <summary> /// <summary>
/// Checks for embedded files (attachments) in a PDF document and returns detailed metadata. /// Checks for embedded files (attachments) in a PDF document and returns detailed metadata.
/// </summary> /// </summary>
/// <param name="pdfStream">PDF content as stream (caller is responsible for disposal)</param> /// <param name="pdfStream">
/// PDF document stream. Must be readable and positioned at the beginning (Position = 0).
/// Non-seekable streams are supported. Caller is responsible for disposal.
/// </param>
/// <returns>Attachment information (count, file names, MIME types, sizes)</returns> /// <returns>Attachment information (count, file names, MIME types, sizes)</returns>
/// <exception cref="Domain.Common.Exceptions.BadRequestException"> /// <exception cref="Domain.Common.Exceptions.BadRequestException">
/// Thrown when stream is empty or invalid /// Thrown when stream is empty, invalid, or not positioned at the beginning
/// </exception> /// </exception>
Task<AttachmentInfo> CheckAttachmentsAsync(Stream pdfStream); Task<AttachmentInfo> CheckAttachmentsAsync(Stream pdfStream);
} }

View File

@@ -12,18 +12,21 @@ public interface ISwissQrCodeProcessor
/// Extracts and parses Swiss QR Code from a PDF document. /// Extracts and parses Swiss QR Code from a PDF document.
/// Returns both parsed Bill object and raw QR text lines. /// Returns both parsed Bill object and raw QR text lines.
/// </summary> /// </summary>
/// <param name="pdfBytes">PDF document as byte array</param> /// <param name="pdfStream">
/// PDF document stream. Must be readable and positioned at the beginning (Position = 0).
/// Non-seekable streams are supported. Caller is responsible for disposal.
/// </param>
/// <param name="pageNumbers">Optional: Specific page numbers to scan (1-indexed). If null, scans all pages starting with last page.</param> /// <param name="pageNumbers">Optional: Specific page numbers to scan (1-indexed). If null, scans all pages starting with last page.</param>
/// <param name="cancellationToken">Cancellation token</param> /// <param name="cancellationToken">Cancellation token</param>
/// <returns>Tuple: (Parsed Codecrete Bill, Raw QR lines as string array)</returns> /// <returns>Tuple: (Parsed Codecrete Bill, Raw QR lines as string array)</returns>
/// <exception cref="Domain.Exceptions.SwissQrCodeNotFoundException"> /// <exception cref="Domain.Common.Exceptions.NotFoundException">
/// Thrown when no Swiss QR Code is found in the specified pages /// Thrown when no Swiss QR Code is found in the specified pages
/// </exception> /// </exception>
/// <exception cref="Domain.Exceptions.PdfProcessingException"> /// <exception cref="ArgumentException">
/// Thrown when PDF processing fails /// Thrown when stream is empty or (for seekable streams) not positioned at the beginning
/// </exception> /// </exception>
Task<(Bill Bill, string[] RawLines)> ExtractSwissQrCodeAsync( Task<(Bill Bill, string[] RawLines)> ExtractSwissQrCodeAsync(
byte[] pdfBytes, Stream pdfStream,
int[]? pageNumbers = null, int[]? pageNumbers = null,
CancellationToken cancellationToken = default); CancellationToken cancellationToken = default);
} }