mirror of
https://github.com/marcominerva/SqlDatabaseVectorSearch.git
synced 2026-06-20 12:23:10 +00:00
a0f1755c85
Introduce support for `CancellationToken` across various methods to allow for task cancellation and improve responsiveness. - Update `DecodeAsync` method in `DocxContentDecoder.cs`, `PdfContentDecoder.cs`, `TextContentDecoder.cs`, and `IContentDecoder.cs` to include an optional `CancellationToken` parameter. - Modify endpoint handlers in `Program.cs` to accept and pass `CancellationToken` parameters. - Update methods in `ChatService.cs` to include `CancellationToken` parameters. - Update methods in `DocumentService.cs` to include `CancellationToken` parameters. - Update methods in `VectorSearchService.cs` to include `CancellationToken` parameters. These changes ensure that long-running operations can be canceled if needed, improving the application's ability to handle cancellation requests gracefully.
26 lines
796 B
C#
26 lines
796 B
C#
using System.Text;
|
|
using DocumentFormat.OpenXml.Packaging;
|
|
using DocumentFormat.OpenXml.Wordprocessing;
|
|
|
|
namespace SqlDatabaseVectorSearch.ContentDecoders;
|
|
|
|
public class DocxContentDecoder : IContentDecoder
|
|
{
|
|
public Task<string> DecodeAsync(Stream stream, string contentType, CancellationToken cancellationToken = default)
|
|
{
|
|
// Open a Word document for read-only access.
|
|
using var document = WordprocessingDocument.Open(stream, false);
|
|
|
|
var body = document.MainDocumentPart?.Document.Body;
|
|
var content = new StringBuilder();
|
|
|
|
var paragraphs = body?.Descendants<Paragraph>() ?? [];
|
|
foreach (var p in paragraphs)
|
|
{
|
|
content.AppendLine(p.InnerText);
|
|
}
|
|
|
|
return Task.FromResult(content.ToString());
|
|
}
|
|
}
|