Created
March 20, 2023 00:32
-
-
Save TheFo2sh/23c66c0b95cd02a5ce2aeddc9025c402 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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