Skip to content

Instantly share code, notes, and snippets.

@TheFo2sh
Created March 20, 2023 00:32
Show Gist options
  • Save TheFo2sh/23c66c0b95cd02a5ce2aeddc9025c402 to your computer and use it in GitHub Desktop.
Save TheFo2sh/23c66c0b95cd02a5ce2aeddc9025c402 to your computer and use it in GitHub Desktop.
public class PdfGenerationCommand : ICommand
{
public string HtmlContent { get; set; }
}
public class PdfGenerationCommandHandler : CommandHandler<PdfGenerationCommand>
{
private readonly IPdfGenerator _pdfGenerator;
private CancellationTokenSource _cancellationTokenSource;
public PdfGenerationCommandHandler(IPdfGenerator pdfGenerator)
{
_pdfGenerator = pdfGenerator;
}
public override async Task Handle(PdfGenerationCommand command)
{
// Generate the PDF using the provided HTML content
var pdfBytes = await _pdfGenerator.GeneratePdfAsync(command.HtmlContent);
// Generate a unique document ID
var documentId = Guid.NewGuid().ToString();
// Output the PDF content and document ID to the console
await Console.Out.WriteLineAsync($"Generated PDF with ID {documentId}: {pdfBytes}");
}
public override void Cancel()
{
// Cancel the operation by cancelling the token source
_cancellationTokenSource?.Cancel();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment