Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
why the mirror lags one release, structurally, and why this bump is the first step rather than
an afterthought.
-->
<PackageReference Include="Ank.DocToolkit" Version="[0.34.0, )" />
<PackageReference Include="Ank.DocToolkit" Version="[0.36.1, )" />

<!--
8.0.2, not 8.0.0, since 0.15.0. PDFsharp raised Microsoft.Extensions.Logging.Abstractions
Expand Down
25 changes: 25 additions & 0 deletions src/DocToolkit.Extensions.DependencyInjection/DocxReviewService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace DocToolkit.Extensions.DependencyInjection;

/// <summary>Default <see cref="IDocxReview"/>, delegating to <see cref="DocToolkit.DocxReview"/>.</summary>
internal sealed class DocxReviewService : IDocxReview
{
public DocToolkit.DocxReviewReport Inspect(byte[] docx) => DocToolkit.DocxReview.Inspect(docx);

public Task<DocToolkit.DocxReviewReport> InspectAsync(Stream source, CancellationToken ct = default)
=> DocToolkit.DocxReview.InspectAsync(source, ct);

public byte[] RemoveComments(byte[] docx) => DocToolkit.DocxReview.RemoveComments(docx);

public Task RemoveCommentsAsync(Stream source, Stream destination, CancellationToken ct = default)
=> DocToolkit.DocxReview.RemoveCommentsAsync(source, destination, ct);

public byte[] AcceptRevisions(byte[] docx) => DocToolkit.DocxReview.AcceptRevisions(docx);

public Task AcceptRevisionsAsync(Stream source, Stream destination, CancellationToken ct = default)
=> DocToolkit.DocxReview.AcceptRevisionsAsync(source, destination, ct);

public byte[] RejectRevisions(byte[] docx) => DocToolkit.DocxReview.RejectRevisions(docx);

public Task RejectRevisionsAsync(Stream source, Stream destination, CancellationToken ct = default)
=> DocToolkit.DocxReview.RejectRevisionsAsync(source, destination, ct);
}
74 changes: 74 additions & 0 deletions src/DocToolkit.Extensions.DependencyInjection/IDocxReview.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
namespace DocToolkit.Extensions.DependencyInjection;

/// <summary>
/// Reads and resolves a Word document's review state — the comments and tracked changes it carries
/// from having been through review. Registered by
/// <see cref="ServiceCollectionExtensions.AddDocToolkit"/>.
/// </summary>
/// <remarks>
/// <b>Separate from <see cref="IDocxEditor"/> deliberately.</b> That interface is about a document's
/// content; this is about the record of people arguing over it.
///
/// <b>Read and resolve only.</b> There is no member here to add a comment or to record an edit as a
/// tracked change — the core library cannot create review state, so neither can this.
/// </remarks>
public interface IDocxReview
{
/// <summary>Reads the comments and tracked changes <paramref name="docx"/> carries.</summary>
/// <param name="docx">The document to inspect.</param>
/// <exception cref="ArgumentNullException"><paramref name="docx"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="docx"/> is empty.</exception>
/// <exception cref="DocToolkit.DocumentConversionException">It could not be opened or read.</exception>
DocToolkit.DocxReviewReport Inspect(byte[] docx);

/// <inheritdoc cref="Inspect(byte[])"/>
/// <param name="source">The document to inspect. Read to its end; never disposed or sought.</param>
/// <param name="ct">Cancels before the document is read.</param>
Task<DocToolkit.DocxReviewReport> InspectAsync(Stream source, CancellationToken ct = default);

/// <summary>A copy of <paramref name="docx"/> with every comment removed.</summary>
/// <param name="docx">The document to clean.</param>
/// <exception cref="ArgumentNullException"><paramref name="docx"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="docx"/> is empty.</exception>
/// <exception cref="DocToolkit.DocumentConversionException">It could not be read or written.</exception>
byte[] RemoveComments(byte[] docx);

/// <inheritdoc cref="RemoveComments(byte[])"/>
/// <param name="source">The document to clean. Read to its end; never disposed or sought.</param>
/// <param name="destination">Receives the cleaned document. Written; never disposed or sought.</param>
/// <param name="ct">Cancels before the document is read, and while it is written.</param>
Task RemoveCommentsAsync(Stream source, Stream destination, CancellationToken ct = default);

/// <summary>
/// A copy of <paramref name="docx"/> with every tracked change applied: insertions kept,
/// deletions dropped. <b>Cannot be undone from the result.</b>
/// </summary>
/// <param name="docx">The document to apply changes to.</param>
/// <exception cref="ArgumentNullException"><paramref name="docx"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="docx"/> is empty.</exception>
/// <exception cref="DocToolkit.DocumentConversionException">It could not be read or written.</exception>
byte[] AcceptRevisions(byte[] docx);

/// <inheritdoc cref="AcceptRevisions(byte[])"/>
/// <param name="source">The document to apply changes to. Read to its end; never disposed or sought.</param>
/// <param name="destination">Receives the result. Written; never disposed or sought.</param>
/// <param name="ct">Cancels before the document is read, and while it is written.</param>
Task AcceptRevisionsAsync(Stream source, Stream destination, CancellationToken ct = default);

/// <summary>
/// A copy of <paramref name="docx"/> with every tracked change discarded: insertions dropped,
/// deletions restored — the mirror of <see cref="AcceptRevisions(byte[])"/>. <b>Cannot be undone
/// from the result.</b>
/// </summary>
/// <param name="docx">The document to discard changes from.</param>
/// <exception cref="ArgumentNullException"><paramref name="docx"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="docx"/> is empty.</exception>
/// <exception cref="DocToolkit.DocumentConversionException">It could not be read or written.</exception>
byte[] RejectRevisions(byte[] docx);

/// <inheritdoc cref="RejectRevisions(byte[])"/>
/// <param name="source">The document to discard changes from. Read to its end; never disposed or sought.</param>
/// <param name="destination">Receives the result. Written; never disposed or sought.</param>
/// <param name="ct">Cancels before the document is read, and while it is written.</param>
Task RejectRevisionsAsync(Stream source, Stream destination, CancellationToken ct = default);
}
7 changes: 4 additions & 3 deletions src/DocToolkit.Extensions.DependencyInjection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
[![NuGet Downloads](https://img.shields.io/nuget/dt/Ank.DocToolkit.Extensions.DependencyInjection.svg)](https://www.nuget.org/packages/Ank.DocToolkit.Extensions.DependencyInjection/)

Dependency-injection registration for [Ank.DocToolkit](https://www.nuget.org/packages/Ank.DocToolkit) —
`services.AddDocToolkit()` registers fifteen injectable interfaces over the same pure-managed
HTML/DOCX/PDF/XLSX/PPTX/Markdown conversion and editing logic.
`services.AddDocToolkit()` registers an injectable interface per capability, over the same
pure-managed HTML/DOCX/PDF/XLSX/PPTX/Markdown conversion and editing logic. They are named in full
below.

```bash
dotnet add package Ank.DocToolkit.Extensions.DependencyInjection
Expand Down Expand Up @@ -154,7 +155,7 @@ Every interface — `IHtmlToDocxConverter`, `IDocxToPdfConverter`, `IHtmlToPdfCo
`IXlsxToPdfConverter`, `IPptxToPdfConverter`, `IDocxToHtmlConverter`,
`IDocxToMarkdownConverter`, `IMarkdownToDocxConverter`, `IMarkdownToPdfConverter`,
`IXlsxToCsvConverter`, `IXlsxToHtmlConverter`, `IDocToDocxConverter`, `IDocxEditor`,
`IWorkbookEditor`, `IPresentationEditor`, `IPdfEditor` — mirrors
`IWorkbookEditor`, `IPresentationEditor`, `IPdfEditor`, `IDocxReview` — mirrors
[`Ank.DocToolkit`](https://www.nuget.org/packages/Ank.DocToolkit)'s static API, including both its
`byte[]` and its `Stream`-based async overloads.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static IServiceCollection AddDocToolkit(
services.TryAddSingleton<IXlsxToCsvConverter, XlsxToCsvConverterService>();
services.TryAddSingleton<IXlsxToHtmlConverter, XlsxToHtmlConverterService>();
services.TryAddSingleton<IDocToDocxConverter, DocToDocxConverterService>();
services.TryAddSingleton<IDocxReview, DocxReviewService>();

return services;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ through Microsoft.Extensions.Options rather than through Ank.DocToolkit, so the
notices never covered it and the hand-written list had simply left it out.

--- BEGIN GENERATED (scripts/gen-third-party-notices.py) - do not edit by hand ---
- Ank.DocToolkit 0.34.0 - MIT (direct) - https://github.com/Ank-KhoaHo/DocToolkit
- Ank.DocToolkit 0.36.1 - MIT (direct) - https://github.com/Ank-KhoaHo/DocToolkit
- Microsoft.Extensions.Options 8.0.0 - MIT (direct) - https://github.com/dotnet/runtime
- Microsoft.Extensions.Primitives 8.0.0 - MIT (transitive) - https://github.com/dotnet/runtime

Expand Down
12 changes: 6 additions & 6 deletions src/DocToolkit.Extensions.DependencyInjection/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"net10.0": {
"Ank.DocToolkit": {
"type": "Direct",
"requested": "[0.34.0, )",
"resolved": "0.34.0",
"contentHash": "vwG9bd1x1KD9NAljaThHr1Y/UfPNhbVW/SICejpLDYBOKIZ6Go+CPewupqlqS+C3iKpxM9ihrmekLd64mwCL0g==",
"requested": "[0.36.1, )",
"resolved": "0.36.1",
"contentHash": "eIEAYc7n19tGqCv1bBNj+/3Kt19D/sGC+KOs+ciq11KBPIP6Lso5Wx++byPHCmnIQVodtYpiKOQ+06yLxNKOog==",
"dependencies": {
"AngleSharp": "1.7.1",
"ClosedXML": "0.105.1",
Expand Down Expand Up @@ -273,9 +273,9 @@
"net8.0": {
"Ank.DocToolkit": {
"type": "Direct",
"requested": "[0.34.0, )",
"resolved": "0.34.0",
"contentHash": "vwG9bd1x1KD9NAljaThHr1Y/UfPNhbVW/SICejpLDYBOKIZ6Go+CPewupqlqS+C3iKpxM9ihrmekLd64mwCL0g==",
"requested": "[0.36.1, )",
"resolved": "0.36.1",
"contentHash": "eIEAYc7n19tGqCv1bBNj+/3Kt19D/sGC+KOs+ciq11KBPIP6Lso5Wx++byPHCmnIQVodtYpiKOQ+06yLxNKOog==",
"dependencies": {
"AngleSharp": "1.7.1",
"ClosedXML": "0.105.1",
Expand Down
Loading
Loading