- Replace byte[] and Base64String with required Stream PdfStream - Simplify validators: remove XOR/Base64 validation, only check NotNull - Affected queries: ValidatePdfQuery, ValidatePdfAQuery, CheckPdfAttachmentsQuery, ExtractSwissQrCodeQuery - Memory efficiency: direct stream usage, no intermediate byte[] copies
38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using AutoMapper;
|
|
using DocumentOperator.Application.Common.DTOs;
|
|
using DocumentOperator.Application.Common.Interfaces;
|
|
using MediatR;
|
|
|
|
namespace DocumentOperator.Application.CheckPdfAttachments.Queries;
|
|
|
|
/// <summary>
|
|
/// Query for checking PDF attachments (Stream-based)
|
|
/// </summary>
|
|
public record CheckPdfAttachmentsQuery : IRequest<AttachmentCheckResult>
|
|
{
|
|
/// <summary>
|
|
/// PDF as stream (caller is responsible for disposal)
|
|
/// </summary>
|
|
public required Stream PdfStream { get; init; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handler for CheckPdfAttachmentsQuery
|
|
/// Orchestrates PDF attachment checking using IPdfProcessor and AutoMapper
|
|
/// </summary>
|
|
public class CheckPdfAttachmentsQueryHandler(IPdfProcessor PdfProcessor, IMapper Mapper)
|
|
: IRequestHandler<CheckPdfAttachmentsQuery, AttachmentCheckResult>
|
|
{
|
|
/// <summary>
|
|
/// Checks PDF attachments and returns detailed metadata
|
|
/// </summary>
|
|
public async Task<AttachmentCheckResult> Handle(CheckPdfAttachmentsQuery request, CancellationToken cancellationToken)
|
|
{
|
|
// Call DevExpress service directly with stream (exceptions propagate naturally)
|
|
var attachmentInfo = await PdfProcessor.CheckAttachmentsAsync(request.PdfStream);
|
|
|
|
// Map DTO to response DTO using AutoMapper
|
|
return Mapper.Map<AttachmentCheckResult>(attachmentInfo);
|
|
}
|
|
}
|