Relocated the `WorkflowsClientExtensions` class from `WorkflowsClient.cs` to `IWorkflowsClient.cs` to improve discoverability by defining it alongside the `IWorkflowsClient` interface. The `InspectSwissQrCodeAsync` extension method was moved as part of this change. Its functionality remains unchanged, as it still opens a `FileStream` for the provided file path and delegates to the `IWorkflowsClient.InspectSwissQrCodeAsync(Stream, bool, CancellationToken)` method.
44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
using DocumentService.Application.Common.DTOs;
|
||
using DocumentService.Client.Interfaces;
|
||
using DocumentService.Client.Models.Results;
|
||
|
||
namespace DocumentService.Client.Clients;
|
||
|
||
/// <summary>
|
||
/// Orchestrated multi-step workflows that compose multiple DocumentService clients
|
||
/// into single, higher-level operations.
|
||
/// </summary>
|
||
public class WorkflowsClient(IPdfValidationClient validation, ISwissQrCodeClient swissQrCode) : IWorkflowsClient
|
||
{
|
||
/// <inheritdoc />
|
||
public async Task<SwissQrCodeResult> InspectSwissQrCodeAsync(
|
||
byte[] pdfBytes,
|
||
bool raw = false,
|
||
CancellationToken cancellationToken = default)
|
||
{
|
||
var validationResult = await validation.ValidateAsync(pdfBytes, cancellationToken);
|
||
var qrCode = validationResult.IsValid
|
||
? await swissQrCode.ExtractAsync(pdfBytes, raw, cancellationToken)
|
||
: null;
|
||
return new SwissQrCodeResult(qrCode, validationResult);
|
||
}
|
||
|
||
/// <inheritdoc />
|
||
public async Task<SwissQrCodeResult> InspectSwissQrCodeAsync(
|
||
Stream pdfStream,
|
||
bool raw = false,
|
||
CancellationToken cancellationToken = default)
|
||
{
|
||
var validationResult = await validation.ValidateAsync(pdfStream, cancellationToken);
|
||
|
||
if (!validationResult.IsValid)
|
||
return new SwissQrCodeResult(null, validationResult);
|
||
|
||
// Stream was consumed by validation – reset if possible, otherwise re-open is caller's responsibility.
|
||
if (pdfStream.CanSeek)
|
||
pdfStream.Position = 0;
|
||
|
||
var qrCode = await swissQrCode.ExtractAsync(pdfStream, raw, cancellationToken);
|
||
return new SwissQrCodeResult(qrCode, validationResult);
|
||
}
|
||
} |