-
Notifications
You must be signed in to change notification settings - Fork 6
feat: make the core functions asynchronous #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
… all related namespaces
WalkthroughThis update renames the project from "DocumentService" to "OsmoDoc" across all code, configuration, documentation, and Docker files. It deletes the old Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant OsmoDoc.API (Controller)
participant OsmoDoc.Pdf/Word (Generator)
participant FileSystem/Tools
Client->>OsmoDoc.API (Controller): POST /pdf or /word (with template & data)
OsmoDoc.API (Controller)->>OsmoDoc.Pdf/Word (Generator): await GeneratePdf/GenerateDocumentByTemplate(...)
OsmoDoc.Pdf/Word (Generator)->>FileSystem/Tools: (If EJS) Convert EJS to HTML (external process)
OsmoDoc.Pdf/Word (Generator)->>FileSystem/Tools: Replace placeholders in template
OsmoDoc.Pdf/Word (Generator)->>FileSystem/Tools: Generate PDF/Word document (external process for PDF)
OsmoDoc.Pdf/Word (Generator)-->>OsmoDoc.API (Controller): Return output file path
OsmoDoc.API (Controller)-->>Client: Return file or response
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🧰 Additional context used🪛 GitHub Check: buildOsmoDoc/Word/WordDocumentGenerator.cs[warning] 309-309: [warning] 309-309: [warning] 303-303: ⏰ Context from checks skipped due to timeout of 90000ms (1)
🔇 Additional comments (6)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 20
🧹 Nitpick comments (11)
CONTRIBUTING.md (1)
68-71
: Clean up markdown formatting
The embedded HTML (<strong style="color:black">�</strong>
) and unicode bullets may not render correctly. Replace with standard markdown list syntax or emojis for clarity.docs/site/10.0.2/api/OsmoDocWord.html (2)
8-9
: Remove newline in<title>
content.An embedded newline may break the attribute value. Combine on one line:
<title>Namespace OsmoDoc.Word | Some Documentation</title>
11-12
: Consolidatemeta name="title"
content.Remove the line break so the
content
attribute is a single string:<meta name="title" content="Namespace OsmoDoc.Word | Some Documentation">OsmoDoc.API/Helpers/Base64StringHelper.cs (2)
5-17
: UseGetValue<T>
for configuration binding
Instead of parsing the section value manually, leverageIConfiguration.GetValue<long>("CONFIG:UPLOAD_FILE_SIZE_LIMIT_BYTES")
for stronger typing and null-safety:- long uploadFileSizeLimitBytes = Convert.ToInt64(configuration.GetSection("CONFIG:UPLOAD_FILE_SIZE_LIMIT_BYTES").Value); + long uploadFileSizeLimitBytes = configuration.GetValue<long>("CONFIG:UPLOAD_FILE_SIZE_LIMIT_BYTES");
5-17
: Consider accepting aCancellationToken
To enable cancellation of file I/O operations, add an overload or parameter:public static async Task SaveBase64StringToFilePath( string base64String, string filePath, IConfiguration configuration, + CancellationToken cancellationToken = default) { // ... - await File.WriteAllBytesAsync(filePath, data); + await File.WriteAllBytesAsync(filePath, data, cancellationToken); }Repeat for
ConvertFileToBase64String
.Dockerfile (1)
17-18
: Simplify restore paths
The./
segments are redundant. You can streamline to:- RUN dotnet restore "OsmoDoc.API/OsmoDoc.API.csproj" - RUN dotnet restore "OsmoDoc/OsmoDoc.csproj"README.md (1)
126-127
: Inconsistent example file paths
The two paths use different folder names—OsmoDoc Component
vs.OsmoDoc Service Component
. Align these for clarity in the example.OsmoDoc/Pdf/Models/DocumentData.cs (1)
7-10
: Make the collection non-nullable and immutable to prevent null injectionBecause the setter is public, callers can still overwrite
Placeholders
withnull
, defeating the “non-null list” intent.-public List<ContentMetaData> Placeholders { get; set; } = new List<ContentMetaData>(); +public List<ContentMetaData> Placeholders { get; init; } = new();
init
keeps the property write-able for deserializers but prevents runtime reassignment, and the shorthandnew()
is cleaner.OsmoDoc.API/Program.cs (1)
70-76
: Prefer configuration binding over directEnvironment.GetEnvironmentVariable
Using
Environment.GetEnvironmentVariable
ties you to process-level vars only. Reading the key fromIConfiguration
keeps parity with other settings and allows JSON/User-Secrets overrides.-string JWT_KEY = Environment.GetEnvironmentVariable("JWT_KEY") ?? throw new InvalidOperationException("No JWT key specified"); +string jwtKey = builder.Configuration["JWT_KEY"] + ?? throw new InvalidOperationException("No JWT key specified");OsmoDoc.API/Models/WordGenerationRequestDTO.cs (1)
22-24
: Minor nit: use collection shorthand &init
for immutability-public List<WordContentDataRequestDTO> Placeholders { get; set; } = new List<WordContentDataRequestDTO>(); -public List<TableData> TablesData { get; set; } = new List<TableData>(); +public List<WordContentDataRequestDTO> Placeholders { get; init; } = new(); +public List<TableData> TablesData { get; init; } = new();OsmoDoc/Word/WordDocumentGenerator.cs (1)
125-135
: AvoidTask.Run
for pure I/O – use async streamsWrapping synchronous NPOI I/O in
Task.Run
offloads to the thread-pool but still blocks a thread per request. Consider using asynchronous file APIs (FileStream
withReadAsync/WriteAsync
) or accept synchronous work inside controllers instead of fire-and-forget background tasks.Also applies to: 142-150
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
OsmoDoc.API/wwwroot/Tools/wkhtmltopdf.exe
is excluded by!**/*.exe
📒 Files selected for processing (49)
.github/PULL_REQUEST_TEMPLATE/pull_request_template_api.md
(1 hunks)CONTRIBUTING.md
(7 hunks)Dockerfile
(2 hunks)DocumentService/DocumentService.csproj
(0 hunks)DocumentService/Pdf/Models/ContentMetaData.cs
(0 hunks)DocumentService/Pdf/Models/DocumentData.cs
(0 hunks)DocumentService/Pdf/PdfDocumentGenerator.cs
(0 hunks)DocumentService/Word/Models/ContentData.cs
(0 hunks)DocumentService/Word/Models/DocumentData.cs
(0 hunks)DocumentService/Word/Models/Enums.cs
(0 hunks)DocumentService/Word/Models/TableData.cs
(0 hunks)DocumentService/Word/WordDocumentGenerator.cs
(0 hunks)OsmoDoc.API/Controllers/PdfController.cs
(1 hunks)OsmoDoc.API/Controllers/WordController.cs
(1 hunks)OsmoDoc.API/DotEnv.cs
(1 hunks)OsmoDoc.API/Helpers/AuthenticationHelper.cs
(1 hunks)OsmoDoc.API/Helpers/AutoMappingProfile.cs
(1 hunks)OsmoDoc.API/Helpers/Base64StringHelper.cs
(1 hunks)OsmoDoc.API/Helpers/CommonMethodsHelper.cs
(1 hunks)OsmoDoc.API/Models/BaseResponse.cs
(1 hunks)OsmoDoc.API/Models/PdfGenerationRequestDTO.cs
(1 hunks)OsmoDoc.API/Models/WordGenerationRequestDTO.cs
(1 hunks)OsmoDoc.API/OsmoDoc.API.csproj
(1 hunks)OsmoDoc.API/OsmoDoc.API.sln
(1 hunks)OsmoDoc.API/Program.cs
(1 hunks)OsmoDoc.sln
(1 hunks)OsmoDoc/OsmoDoc.csproj
(1 hunks)OsmoDoc/Pdf/Models/ContentMetaData.cs
(1 hunks)OsmoDoc/Pdf/Models/DocumentData.cs
(1 hunks)OsmoDoc/Pdf/Models/OsmoDocPdfConfig.cs
(1 hunks)OsmoDoc/Pdf/PdfDocumentGenerator.cs
(1 hunks)OsmoDoc/Word/Models/ContentData.cs
(1 hunks)OsmoDoc/Word/Models/DocumentData.cs
(1 hunks)OsmoDoc/Word/Models/Enums.cs
(1 hunks)OsmoDoc/Word/Models/TableData.cs
(1 hunks)OsmoDoc/Word/WordDocumentGenerator.cs
(1 hunks)README.md
(6 hunks)docker-compose.yaml
(1 hunks)docs/site/10.0.2/api/OsmoDoc.Word.Models.ContentData.html
(5 hunks)docs/site/10.0.2/api/OsmoDoc.Word.Models.ContentType.html
(2 hunks)docs/site/10.0.2/api/OsmoDoc.Word.Models.DocumentData.html
(4 hunks)docs/site/10.0.2/api/OsmoDoc.Word.Models.ParentBody.html
(2 hunks)docs/site/10.0.2/api/OsmoDoc.Word.Models.TableData.html
(3 hunks)docs/site/10.0.2/api/OsmoDoc.Word.Models.html
(2 hunks)docs/site/10.0.2/api/OsmoDoc.Word.WordDocumentGenerator.html
(3 hunks)docs/site/10.0.2/api/OsmoDocWord.html
(2 hunks)docs/site/10.0.2/api/toc.html
(1 hunks)docs/site/manifest.json
(1 hunks)docs/site/xrefmap.yml
(1 hunks)
💤 Files with no reviewable changes (9)
- DocumentService/Pdf/Models/ContentMetaData.cs
- DocumentService/Word/Models/TableData.cs
- DocumentService/DocumentService.csproj
- DocumentService/Word/Models/Enums.cs
- DocumentService/Pdf/Models/DocumentData.cs
- DocumentService/Word/Models/DocumentData.cs
- DocumentService/Word/Models/ContentData.cs
- DocumentService/Word/WordDocumentGenerator.cs
- DocumentService/Pdf/PdfDocumentGenerator.cs
🧰 Additional context used
🪛 LanguageTool
README.md
[duplication] ~1-~1: Possible typo: you repeated a word.
Context: # OsmoDoc OsmoDoc is a library with the following functio...
(ENGLISH_WORD_REPEAT_RULE)
🪛 GitHub Check: build
OsmoDoc/Pdf/Models/ContentMetaData.cs
[warning] 6-6:
Non-nullable property 'Content' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
[warning] 5-5:
Non-nullable property 'Placeholder' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
OsmoDoc/Word/Models/DocumentData.cs
[warning] 22-22:
Non-nullable property 'TablesData' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
[warning] 16-16:
Non-nullable property 'Placeholders' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
OsmoDoc/Word/Models/ContentData.cs
[warning] 17-17:
Non-nullable property 'Content' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
[warning] 12-12:
Non-nullable property 'Placeholder' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
OsmoDoc/Word/Models/TableData.cs
[warning] 21-21:
Non-nullable property 'Data' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
OsmoDoc/Word/WordDocumentGenerator.cs
[warning] 300-300:
Possible null reference argument for parameter 'id' in 'OpenXmlPart OpenXmlPartContainer.GetPartById(string id)'.
[warning] 300-300:
Dereference of a possibly null reference.
[warning] 294-294:
Possible null reference argument for parameter 'key' in 'bool Dictionary<string, string>.ContainsKey(string key)'.
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (csharp)
🔇 Additional comments (43)
.github/PULL_REQUEST_TEMPLATE/pull_request_template_api.md (1)
5-5
: Update contributing URL to osmodoc repository
The link now correctly points to the OsmoDoc contributing guidelines.OsmoDoc.API/Helpers/CommonMethodsHelper.cs (2)
5-19
: CreateDirectoryIfNotExists implementation looks solid
The logic correctly handles file-only paths (empty directoryName) and ensures all necessary directories are created.
21-25
: GenerateRandomFileName utility is correct
Random filename generation with a GUID suffix is implemented as expected and avoids naming collisions.OsmoDoc/Pdf/Models/OsmoDocPdfConfig.cs (1)
3-7
: Introduce static PDF configuration holder
CentralizingWkhtmltopdfPath
in a dedicated config class is appropriate for global settings and simplifies PDF generator initialization.CONTRIBUTING.md (1)
16-49
: Consistently rename project references to osmodoc
All links and mentions ofdocument-service
have been updated toosmodoc
, ensuring the contributing guide reflects the new project name.Also applies to: 94-113
OsmoDoc.API/OsmoDoc.API.csproj (1)
15-15
: Update project reference to new core library
The API project now correctly referencesOsmoDoc.csproj
instead of the deprecatedDocumentService.csproj
.OsmoDoc.API/Models/BaseResponse.cs (1)
1-3
: Namespace update is consistent.The
using Microsoft.AspNetCore.Mvc
import and namespace rename toOsmoDoc.API.Models
align with the refactoring.OsmoDoc.API/Helpers/AutoMappingProfile.cs (1)
1-5
: Namespace and imports updated correctly.The profile now references
OsmoDoc.Word.Models
andOsmoDoc.API.Models
appropriately.OsmoDoc.API/DotEnv.cs (1)
1-3
: Namespace refactor approved.Renaming to
OsmoDoc.API
is consistent; the dotenv loader logic is unchanged.docs/site/10.0.2/api/OsmoDocWord.html (2)
70-72
: Namespace identifiers updated accurately.The
article
data-uid
and<h1>
data-uid
now correctly referenceOsmoDoc.Word
. Using an underscore in theid
is acceptable to avoid invalid characters.
80-80
: Class link updated.The
<a>
tag now points toOsmoDoc.Word.WordDocumentGenerator.html
, matching the refactored namespace.OsmoDoc.API/OsmoDoc.API.sln (2)
6-6
: Project reference renamed correctly.The solution now references
OsmoDoc.API.csproj
with the same GUID, ensuring continuity.
2-5
: Also applies to: 7-26OsmoDoc.API/Helpers/Base64StringHelper.cs (1)
1-31
: Inconsistent summary: Missing async changes
The AI-generated summary only mentions namespace renames but omits that both methods were converted to async/await.Likely an incorrect or invalid review comment.
docs/site/10.0.2/api/OsmoDoc.Word.Models.ContentType.html (2)
70-80
: Documentation update aligns with namespace rename
All namespace and assembly references have been correctly updated fromDocumentService
toOsmoDoc
.
96-100
: Enum member IDs updated correctly
Field IDs now use theOsmoDoc.Word.Models.ContentType
namespace and match the code.OsmoDoc.API/Models/PdfGenerationRequestDTO.cs (2)
1-1
: Import updated for new PDF models namespace
The using directive now points toOsmoDoc.Pdf.Models
, which matches the relocatedContentMetaData
andDocumentData
classes.
4-4
: Namespace corrected toOsmoDoc.API.Models
The DTO’s namespace has been renamed appropriately.docs/site/10.0.2/api/OsmoDoc.Word.Models.ParentBody.html (2)
70-75
: Consistent UID and ID namespace rename
Thedata-uid
andid
attributes have been correctly updated fromDocumentService.Word.Models.ParentBody
toOsmoDoc.Word.Models.ParentBody
. No residual references found.
79-80
: Assembly reference updated correctly
The<h6>
tag now points toOsmoDoc.dll
as expected. Documentation aligns with the new project name.docs/site/10.0.2/api/OsmoDoc.Word.Models.html (4)
8-12
: Head metadata updated for new namespace
The<title>
and<meta name="title">
entries reflectOsmoDoc.Word.Models
. Ensure these match all other docs pages.
70-73
: Articledata-uid
and heading IDs renamed
Theid
anddata-uid
on the<article>
and<h1>
have been updated toOsmoDoc.Word.Models
. Good consistency.
80-85
: Class links updated to OsmoDoc namespace
All<a href>
entries forContentData
,DocumentData
, andTableData
now point toOsmoDoc.Word.Models.*
. No old references detected.
89-92
: Enum links updated correctly
The links forContentType
andParentBody
have been updated to the new namespace. Documentation is in sync.docs/site/10.0.2/api/OsmoDoc.Word.Models.TableData.html (3)
70-75
: Article identifiers renamed
The<article>
data-uid
and<h1>
id
/data-uid
values now useOsmoDoc.Word.Models.TableData
. Looks consistent.
107-110
: Namespace, assembly, and syntax block updated
The namespace declaration, assembly name, and syntax section ID correctly referenceOsmoDoc.Word.Models.TableData
.
115-116
: Property anchors updated
The anchors and headings forData
andTablePos
have been updated to include the new namespace in theirdata-uid
values.OsmoDoc.API/Helpers/AuthenticationHelper.cs (1)
6-6
: Namespace updated for project rebrand
The namespace has been changed toOsmoDoc.API.Helpers
. Please verify that all dependent files and imports reference this updated namespace to prevent build errors.README.md (3)
27-27
: Clone command updated
The repository clone step now correctly instructs users to cloneosmodoc
instead of the olddocument-service
.
52-52
: Docker-compose instruction updated
The example command now targetsosmodoc
indocker-compose.yaml
, matching the new project name.
190-195
: License and contributor links updated
The license reference and contributors badge now point toosmodoc
on GitHub. All links appear correct.docs/site/manifest.json (1)
3-3
: Avoid absolute, user-specific paths in DocFX manifest
source_base_path
points to a local Windows user directory (C:/Users/user/Desktop/osmodoc
).
This breaks builds on CI agents and other developers’ machines.-"source_base_path": "C:/Users/user/Desktop/osmodoc", +"source_base_path": "../../..", // or any repo-relative pathConsider making the path repo-relative or leave it empty to let DocFX infer the path.
docs/site/10.0.2/api/OsmoDoc.Word.Models.ContentData.html (1)
70-76
: Namespace rename reflected correctly – no action requiredThe HTML shows the expected switch from
DocumentService
toOsmoDoc
; no broken anchors or mismatcheddata-uid
attributes detected in the touched lines.Also applies to: 107-110
docker-compose.yaml (1)
2-7
: Renaming looks goodService, image, and container names now align with the new branding; compose syntax unchanged.
OsmoDoc.sln (1)
6-8
: Solution file project references updated.
Project entries have been updated to referenceOsmoDoc
andOsmoDoc.API
. Ensure that no stale references to the oldDocumentService
remain in the solution file.docs/site/10.0.2/api/toc.html (1)
17-43
: TOC links updated correctly.
All entries have been renamed fromDocumentService
toOsmoDoc
. No stale or broken links detected in the table of contents.OsmoDoc/Word/Models/Enums.cs (1)
1-36
: Enums defined with correct namespace and documentation.
TheContentType
andParentBody
enums are properly scoped underOsmoDoc.Word.Models
and include clear XML documentation.docs/site/xrefmap.yml (1)
1-196
: Documentation only update – nothing to flag.docs/site/10.0.2/api/OsmoDoc.Word.Models.DocumentData.html (5)
70-70
: Confirm updateddata-uid
on<article>
Thedata-uid
attribute has been correctly changed toOsmoDoc.Word.Models.DocumentData
, matching the new namespace.
74-74
: Verify<h1>
ID anddata-uid
update
The<h1>
tag’sid
anddata-uid
now reflectOsmoDoc.Word.Models.DocumentData
—this aligns with the refactoring.
107-108
: Namespace and assembly references updated
Both the displayed namespace and assembly name have been changed toOsmoDoc
/OsmoDoc.dll
, which is consistent with the project-wide rename.
133-133
: ContentData link updated
TheContentData
type link now points toOsmoDoc.Word.Models.ContentData.html
, correctly reflecting its new location.
156-156
: TableData link updated
TheTableData
type link has been updated toOsmoDoc.Word.Models.TableData.html
, matching the renamed namespace.
e14780a
to
e0b3638
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
♻️ Duplicate comments (2)
OsmoDoc/Word/WordDocumentGenerator.cs (2)
43-60
: Duplicate-placeholder crash resolved – good improvementSwitching from
Dictionary.Add
toTryAdd
prevents runtime failures when a placeholder repeats. 👍
290-306
: Null-safety gaps when replacing images
docProperty.Name
,blip.Embed
, andMainDocumentPart
may all benull
, matching the static-analysis warnings.
Dereferencing them without checks can crash the generator.-if (docProperty != null && imagePlaceholders.ContainsKey(docProperty.Name)) +if (docProperty?.Name is { } name + && imagePlaceholders.TryGetValue(name, out var imagePath)) { - ... - OpenXmlPart imagePart = wordDocument.MainDocumentPart.GetPartById(blip.Embed); + var partId = blip?.Embed?.Value; + if (partId is null || !wordDocument.MainDocumentPart!.PartExists(partId)) + continue; + + OpenXmlPart imagePart = wordDocument.MainDocumentPart.GetPartById(partId);
🧹 Nitpick comments (2)
OsmoDoc/Word/WordDocumentGenerator.cs (2)
33-35
: Redundant try/catch that simply re-throwsThe
catch (Exception) { throw; }
block adds no value and obscures stack traces when future logging is added. Remove the wrapper or log/contextualize the exception before rethrowing.Also applies to: 114-117
142-150
: Task.Run around synchronous file I/O is sub-optimal
FileStream
/WriteAsync
already provide async APIs. Wrapping them inTask.Run
offloads work to the thread-pool without yielding true async I/O.Consider rewriting
WriteDocument
andGetXWPFDocument
to use the native async methods (File.OpenRead
,File.Create
,CopyToAsync
, etc.) withoutTask.Run
.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
OsmoDoc.API/Controllers/WordController.cs
(1 hunks)OsmoDoc/Word/WordDocumentGenerator.cs
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- OsmoDoc.API/Controllers/WordController.cs
🧰 Additional context used
🪛 GitHub Check: build
OsmoDoc/Word/WordDocumentGenerator.cs
[warning] 300-300:
Possible null reference argument for parameter 'id' in 'OpenXmlPart OpenXmlPartContainer.GetPartById(string id)'.
[warning] 300-300:
Dereference of a possibly null reference.
[warning] 294-294:
Possible null reference argument for parameter 'key' in 'bool Dictionary<string, string>.ContainsKey(string key)'.
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (csharp)
e0b3638
to
66031ed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
♻️ Duplicate comments (1)
OsmoDoc/Word/WordDocumentGenerator.cs (1)
290-299
: Potential null-reference and invalid key access during image replacement
docProperty.Name
,blip.Embed
, and their downstream uses can benull
, triggering runtime exceptions and static-analysis warnings.-if (docProperty != null && imagePlaceholders.ContainsKey(docProperty.Name)) +if (docProperty?.Name is { } placeholder + && imagePlaceholders.TryGetValue(placeholder, out var imagePath)) { - List<Blip> drawingBlips = drawing.Descendants<Blip>().ToList(); + foreach (Blip blip in drawing.Descendants<Blip>()) { - OpenXmlPart imagePart = wordDocument.MainDocumentPart.GetPartById(blip.Embed); + string? partId = blip.Embed?.Value; + if (partId is null) continue; + if (!wordDocument.MainDocumentPart!.PartExists(partId)) continue; + + OpenXmlPart imagePart = wordDocument.MainDocumentPart.GetPartById(partId); - string imagePath = imagePlaceholders[docProperty.Name]; + // imagePath already retrieved via TryGetValueThis guards all nullable access points and removes the illegal lookup with a possibly
null
key.
🧹 Nitpick comments (2)
OsmoDoc/Word/WordDocumentGenerator.cs (2)
125-132
: Avoid wrapping pure I/O inTask.Run
File.OpenRead
is non-blocking on modern OS file systems; the expensive work happens when the stream is consumed. Off-loading the open call to the thread-pool adds overhead without real benefit. Either keep it synchronous or return aValueTask<XWPFDocument>
that opens the stream directly.-private async static Task<XWPFDocument> GetXWPFDocument(string docFilePath) -{ - return await Task.Run(() => - { - FileStream readStream = File.OpenRead(docFilePath); - return new XWPFDocument(readStream); - }); -} +private static Task<XWPFDocument> GetXWPFDocument(string docFilePath) +{ + FileStream readStream = File.OpenRead(docFilePath); + return Task.FromResult(new XWPFDocument(readStream)); +}
74-81
: Placeholder regex too restrictive
@"{[a-zA-Z]+}"
fails for placeholders containing digits, underscores or hyphens (e.g.,{First_Name}
,{address1}
). Consider widening the character class:-if (!new Regex(@"{[a-zA-Z]+}").IsMatch(paragraph.ParagraphText)) +if (!Regex.IsMatch(paragraph.ParagraphText, @"{\w+}")
\w
matches letters, digits and underscore, covering common cases.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
OsmoDoc/Pdf/PdfDocumentGenerator.cs
(1 hunks)OsmoDoc/Word/WordDocumentGenerator.cs
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- OsmoDoc/Pdf/PdfDocumentGenerator.cs
🧰 Additional context used
🪛 GitHub Check: build
OsmoDoc/Word/WordDocumentGenerator.cs
[warning] 297-297:
Possible null reference argument for parameter 'id' in 'OpenXmlPart OpenXmlPartContainer.GetPartById(string id)'.
[warning] 297-297:
Dereference of a possibly null reference.
[warning] 291-291:
Possible null reference argument for parameter 'key' in 'bool Dictionary<string, string>.ContainsKey(string key)'.
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (csharp)
🔇 Additional comments (1)
OsmoDoc/Word/WordDocumentGenerator.cs (1)
39-60
: 👍 Duplicate-placeholder handling looks good
TryAdd
eliminates the crash path previously flagged in older reviews—nice fix.
5a6e3c6
to
76fcb3f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
♻️ Duplicate comments (3)
OsmoDoc/Word/WordDocumentGenerator.cs (3)
139-148
: Ensure output directory exists beforeFile.Create
Without guaranteeing the directory,File.Create
throwsDirectoryNotFoundException
for nested paths. This was flagged earlier but hasn’t been applied in the renamed file.private async static Task WriteDocument(XWPFDocument document, string filePath) { await Task.Run(() => { - using (FileStream writeStream = File.Create(filePath)) + // Ensure parent directory is present + string? dir = Path.GetDirectoryName(filePath); + if (!string.IsNullOrWhiteSpace(dir)) + { + Directory.CreateDirectory(dir); + } + + using (FileStream writeStream = File.Create(filePath)) { document.Write(writeStream); } }); }
286-306
: Add null-safety forDocProperties.Name
,blip.Embed
and part lookup
docProperty.Name
,blip.Embed
andwordDocument.MainDocumentPart.GetPartById
can all benull
, triggering runtime exceptions (the static-analysis warnings still fire).- // If drawing / image name is present in imagePlaceholders dictionary, then replace image - if (docProperty != null && imagePlaceholders.ContainsKey(docProperty.Name)) + // Safely resolve placeholder & part + if (docProperty?.Name is { } name + && imagePlaceholders.TryGetValue(name, out var imagePath)) { List<Blip> drawingBlips = drawing.Descendants<Blip>().ToList(); foreach (Blip blip in drawingBlips) { - OpenXmlPart imagePart = wordDocument.MainDocumentPart.GetPartById(blip.Embed); + string? partId = blip?.Embed?.Value; + if (partId is null || !wordDocument.MainDocumentPart!.PartExists(partId)) + continue; + + OpenXmlPart imagePart = wordDocument.MainDocumentPart.GetPartById(partId); - string imagePath = imagePlaceholders[docProperty.Name]; - // Asynchronously download image data using HttpClient byte[] imageData = await _httpClient.GetByteArrayAsync(imagePath);
236-250
: Row population still assumes cells already exist
Iterating overrow.GetTableCells().Count
on a freshly created row (often 0) leaves new rows blank. Iterate over the header’s column count and add cells on demand.- // For each cell in row - for (int cellNumber = 0; cellNumber < row.GetTableCells().Count; cellNumber++) + int columnCount = headerRow.GetTableCells().Count; + for (int cellNumber = 0; cellNumber < columnCount; cellNumber++) { - XWPFTableCell cell = row.GetCell(cellNumber); + // Ensure the row has enough cells + while (row.GetTableCells().Count <= cellNumber) + row.AddNewTableCell(); + + XWPFTableCell cell = row.GetCell(cellNumber);
🧹 Nitpick comments (3)
OsmoDoc/Word/WordDocumentGenerator.cs (1)
74-78
: Usestring.IsNullOrWhiteSpace
for clarity
A minor readability/nitpick: checkingparagraph.ParagraphText == string.Empty
ignores whitespace-only paragraphs.string.IsNullOrWhiteSpace
expresses the intent more clearly.OsmoDoc/Pdf/PdfDocumentGenerator.cs (2)
68-71
: Redundant catch / re-throw adds noiseCatching
Exception
only tothrow;
again provides no additional value and hides the real stack frame in some profilers. You can safely delete the wholetry/catch
block and let the original exception propagate.
100-148
:output
/errors
variables are read but never usedLines 146-147 read the process streams into
output
anderrors
, but onlyerrors
is later referenced inside the exit-code block.output
is dead code. Either log it or remove the read to avoid unnecessary buffering.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
OsmoDoc.API/Controllers/PdfController.cs
(1 hunks)OsmoDoc.API/Controllers/WordController.cs
(1 hunks)OsmoDoc/OsmoDoc.csproj
(1 hunks)OsmoDoc/Pdf/PdfDocumentGenerator.cs
(1 hunks)OsmoDoc/Word/WordDocumentGenerator.cs
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- OsmoDoc/OsmoDoc.csproj
🚧 Files skipped from review as they are similar to previous changes (2)
- OsmoDoc.API/Controllers/WordController.cs
- OsmoDoc.API/Controllers/PdfController.cs
🧰 Additional context used
🧠 Learnings (1)
OsmoDoc/Pdf/PdfDocumentGenerator.cs (1)
Learnt from: osm-Jatin
PR: OsmosysSoftware/osmodoc#40
File: OsmoDoc/Pdf/PdfDocumentGenerator.cs:24-37
Timestamp: 2025-06-18T14:03:39.722Z
Learning: In OsmoDoc PdfDocumentGenerator.GeneratePdf method, an empty metaDataList is a valid scenario when users want to convert HTML/EJS templates to PDF without any placeholder replacements. Only null metaDataList should be validated, not empty ones.
🪛 GitHub Check: build
OsmoDoc/Word/WordDocumentGenerator.cs
[warning] 297-297:
Possible null reference argument for parameter 'id' in 'OpenXmlPart OpenXmlPartContainer.GetPartById(string id)'.
[warning] 297-297:
Dereference of a possibly null reference.
[warning] 291-291:
Possible null reference argument for parameter 'key' in 'bool Dictionary<string, string>.ContainsKey(string key)'.
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (csharp)
🔇 Additional comments (1)
OsmoDoc/Word/WordDocumentGenerator.cs (1)
93-96
: ✅ Guard forTablePos
looks solidNice catch adding the
insertData.TablePos >= 1
lower-bound check—the off-by-one issue is gone.
af3e342
to
1997755
Compare
1997755
to
8944612
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (4)
OsmoDoc/Word/WordDocumentGenerator.cs (2)
307-313
: Implement null safety checks for image replacement.The code still has potential null reference issues that were flagged in previous reviews but not fully addressed:
Apply the suggested null safety pattern:
- if (docProperty != null && imagePlaceholders.ContainsKey(docProperty.Name)) + if (docProperty?.Name is { } name && imagePlaceholders.TryGetValue(name, out var imagePath)) { List<Blip> drawingBlips = drawing.Descendants<Blip>().ToList(); foreach (Blip blip in drawingBlips) { - OpenXmlPart imagePart = wordDocument.MainDocumentPart.GetPartById(blip.Embed); + var partId = blip?.Embed?.Value; + if (partId is not null && wordDocument.MainDocumentPart!.PartExists(partId)) + { + OpenXmlPart imagePart = wordDocument.MainDocumentPart.GetPartById(partId); - string imagePath = imagePlaceholders[docProperty.Name]; // ... rest of the logic + } } }
254-266
: Fix row cell-count mismatch when populating tables.This issue was identified in previous reviews but remains unaddressed.
row.GetTableCells().Count
on a newly created row may be0
, leaving the row blank.Apply the suggested fix:
- for (int cellNumber = 0; cellNumber < row.GetTableCells().Count; cellNumber++) + int columnCount = headerRow.GetTableCells().Count; + for (int cellNumber = 0; cellNumber < columnCount; cellNumber++) + { + // Ensure the row has enough cells + while (row.GetTableCells().Count <= cellNumber) + row.AddNewTableCell(); + XWPFTableCell cell = row.GetCell(cellNumber);OsmoDoc/Pdf/PdfDocumentGenerator.cs (2)
98-99
: Address concurrent access issues with fixed directory names.Using fixed directory names like
"Modified"
creates race conditions when multiple PDF generation requests execute concurrently. This was identified in previous reviews but remains unaddressed.Apply the suggested fix:
- string tempHtmlFilePath = Path.Combine(directoryPath, "Modified"); - string tempHtmlFile = Path.Combine(tempHtmlFilePath, "modifiedHtml.html"); + string uniqueId = Guid.NewGuid().ToString("N"); + string tempHtmlFilePath = Path.Combine(directoryPath, $"Modified_{uniqueId}"); + string tempHtmlFile = Path.Combine(tempHtmlFilePath, "modifiedHtml.html");
180-180
: Apply unique naming to "Temp" directory for concurrent safety.The fixed
"Temp"
directory name creates the same concurrency issues as mentioned for the"Modified"
directory.Apply similar fix:
- string tempDirectoryFilePath = Path.Combine(directoryPath, "Temp"); + string uniqueId = Guid.NewGuid().ToString("N"); + string tempDirectoryFilePath = Path.Combine(directoryPath, $"Temp_{uniqueId}");
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
OsmoDoc/Pdf/PdfDocumentGenerator.cs
(1 hunks)OsmoDoc/Word/WordDocumentGenerator.cs
(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
OsmoDoc/Pdf/PdfDocumentGenerator.cs (2)
Learnt from: osm-Jatin
PR: OsmosysSoftware/osmodoc#40
File: OsmoDoc/Pdf/PdfDocumentGenerator.cs:24-37
Timestamp: 2025-06-18T14:03:39.722Z
Learning: In OsmoDoc PdfDocumentGenerator.GeneratePdf method, an empty metaDataList is a valid scenario when users want to convert HTML/EJS templates to PDF without any placeholder replacements. Only null metaDataList should be validated, not empty ones.
Learnt from: osm-Jatin
PR: OsmosysSoftware/osmodoc#40
File: OsmoDoc/Pdf/PdfDocumentGenerator.cs:84-92
Timestamp: 2025-06-18T14:44:46.549Z
Learning: osm-Jatin prefers to document input requirements clearly in the README file rather than adding runtime validation code for scenarios like null/duplicate placeholders in the OsmoDoc PDF generation functionality.
🪛 GitHub Check: build
OsmoDoc/Word/WordDocumentGenerator.cs
[failure] 151-151:
'Path' is an ambiguous reference between 'DocumentFormat.OpenXml.Drawing.Path' and 'System.IO.Path'
[warning] 313-313:
Possible null reference argument for parameter 'id' in 'OpenXmlPart OpenXmlPartContainer.GetPartById(string id)'.
[warning] 313-313:
Dereference of a possibly null reference.
[warning] 307-307:
Possible null reference argument for parameter 'key' in 'bool Dictionary<string, string>.ContainsKey(string key)'.
[failure] 151-151:
'Path' is an ambiguous reference between 'DocumentFormat.OpenXml.Drawing.Path' and 'System.IO.Path'
🪛 GitHub Actions: Build and Test
OsmoDoc/Word/WordDocumentGenerator.cs
[error] 151-151: CS0104: 'Path' is an ambiguous reference between 'DocumentFormat.OpenXml.Drawing.Path' and 'System.IO.Path'.
🔇 Additional comments (2)
OsmoDoc/Pdf/PdfDocumentGenerator.cs (2)
262-262
: Path quoting properly implemented for Linux.Great! The file paths are now properly quoted in the Linux branch, addressing the previous concern about paths containing spaces.
23-23
: Excellent async implementation throughout the class.The asynchronous pattern is properly implemented with:
- Correct use of
async
/await
keywords- Proper use of
Task.Run
for CPU-bound operationsProcess.WaitForExitAsync()
for process waiting- Async file operations where available
This aligns well with the PR objective of making core functions asynchronous.
8944612
to
e0d94d6
Compare
e0d94d6
to
d189276
Compare
83181c8
to
e84b4b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (3)
OsmoDoc/Pdf/PdfDocumentGenerator.cs (1)
181-181
: Fix potential concurrency issue with fixed temp directory name.The method uses a fixed "Temp" directory name which could cause collisions during concurrent requests, similar to the issue that was resolved in
ReplaceFileElementsWithMetaData
.Apply the same unique directory approach:
- string tempDirectoryFilePath = Path.Combine(directoryPath, "Temp"); + string uniqueId = Guid.NewGuid().ToString("N"); + string tempDirectoryFilePath = Path.Combine(directoryPath, $"Temp_{uniqueId}");OsmoDoc/Word/WordDocumentGenerator.cs (2)
255-268
: Fix row cell count mismatch when populating tablesThe loop uses
row.GetTableCells().Count
on a newly created row, which can be zero because NPOI doesn't auto-create cells to match the header row. This results in no cells being populated.Apply this fix to ensure proper cell population:
-for (int cellNumber = 0; cellNumber < row.GetTableCells().Count; cellNumber++) +int columnCount = headerRow.GetTableCells().Count; +for (int cellNumber = 0; cellNumber < columnCount; cellNumber++) { + // Ensure the row has enough cells + while (row.GetTableCells().Count <= cellNumber) + row.AddNewTableCell(); + XWPFTableCell cell = row.GetCell(cellNumber);
308-314
: Add null safety checks for image replacementThe static analysis warnings are valid -
docProperty.Name
andblip.Embed
can be null, leading to runtime exceptions.Apply this fix to add proper null checks:
-if (docProperty != null && imagePlaceholders.ContainsKey(docProperty.Name)) +if (docProperty?.Name != null && imagePlaceholders.ContainsKey(docProperty.Name)) { List<Blip> drawingBlips = drawing.Descendants<Blip>().ToList(); foreach (Blip blip in drawingBlips) { + if (blip.Embed?.Value == null) + continue; + OpenXmlPart imagePart = wordDocument.MainDocumentPart.GetPartById(blip.Embed);
🧹 Nitpick comments (1)
OsmoDoc/Word/WordDocumentGenerator.cs (1)
301-301
: Consider performance optimization for image replacement loopThe FIXME comment suggests improving the nested loop operation. Consider caching the image placeholder lookups or using a more efficient approach.
You could optimize this by:
- Pre-filtering drawings that have DocProperties with names in the imagePlaceholders dictionary
- Using parallel processing for independent image downloads
- Implementing a lookup cache for repeated placeholder names
Would you like me to generate an optimized version of this image replacement logic?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
OsmoDoc/Pdf/PdfDocumentGenerator.cs
(1 hunks)OsmoDoc/Word/WordDocumentGenerator.cs
(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
OsmoDoc/Pdf/PdfDocumentGenerator.cs (2)
Learnt from: osm-Jatin
PR: OsmosysSoftware/osmodoc#40
File: OsmoDoc/Pdf/PdfDocumentGenerator.cs:24-37
Timestamp: 2025-06-18T14:03:39.722Z
Learning: In OsmoDoc PdfDocumentGenerator.GeneratePdf method, an empty metaDataList is a valid scenario when users want to convert HTML/EJS templates to PDF without any placeholder replacements. Only null metaDataList should be validated, not empty ones.
Learnt from: osm-Jatin
PR: OsmosysSoftware/osmodoc#40
File: OsmoDoc/Pdf/PdfDocumentGenerator.cs:84-92
Timestamp: 2025-06-18T14:44:46.549Z
Learning: osm-Jatin prefers to document input requirements clearly in the README file rather than adding runtime validation code for scenarios like null/duplicate placeholders in the OsmoDoc PDF generation functionality.
🪛 GitHub Check: build
OsmoDoc/Word/WordDocumentGenerator.cs
[warning] 314-314:
Possible null reference argument for parameter 'id' in 'OpenXmlPart OpenXmlPartContainer.GetPartById(string id)'.
[warning] 314-314:
Dereference of a possibly null reference.
[warning] 308-308:
Possible null reference argument for parameter 'key' in 'bool Dictionary<string, string>.ContainsKey(string key)'.
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (csharp)
🔇 Additional comments (10)
OsmoDoc/Pdf/PdfDocumentGenerator.cs (5)
1-14
: Class structure and imports look good.The using statements include all necessary namespaces for async PDF generation, JSON handling, and cross-platform operations. The class declaration is appropriate.
23-82
: Excellent async implementation of the main PDF generation method.The method properly implements asynchronous patterns with comprehensive input validation, appropriate exception handling, and resource cleanup. The conversion from synchronous to async is well-executed and aligns with the PR objectives.
84-109
: Good implementation with concurrency fix.The method correctly addresses the potential concurrency issue by using unique GUID-based directory names. The placeholder replacement logic is clean and functional.
111-171
: Well-implemented async PDF conversion with proper cross-platform support.The method demonstrates excellent async practices with proper process management, cross-platform compatibility, and resource cleanup. The quoted file paths address previous concerns about handling paths with spaces.
242-269
: Helper methods are well-implemented.The
IsValidJSON
method uses appropriate exception handling, and theEjsToHtmlArgumentsBasedOnOS
method properly handles cross-platform differences with quoted file paths for both Windows and Linux.OsmoDoc/Word/WordDocumentGenerator.cs (5)
1-128
: Inconsistency between PR objectives and actual changesThe PR objectives mention making core functions asynchronous, but the AI summary and code changes indicate this is actually a project rename from "DocumentService" to "OsmoDoc" with equivalent async functionality already implemented.
Likely an incorrect or invalid review comment.
24-24
: Good use of static HttpClientThe static HttpClient instance follows best practices for avoiding socket exhaustion and improves performance for multiple HTTP requests.
59-59
: Proper use of TryAdd prevents duplicate key exceptionsThe use of
TryAdd
correctly handles potential duplicate placeholders without throwing exceptions, addressing the previous review concern.Also applies to: 64-64, 69-69
104-104
: Correct bounds checking prevents off-by-one errorsThe condition
insertData.TablePos >= 1
properly guards against negative indexing, addressing the previous review concern.
152-156
: Proper directory creation and Path disambiguationThe directory creation logic and use of
IOPath
alias correctly address previous review comments about missing directories and ambiguous Path references.
…ding unique id in the filename
e84b4b3
to
325426a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Nitpick comments (2)
OsmoDoc/Word/WordDocumentGenerator.cs (2)
24-24
: Consider HttpClient lifecycle management.The static HttpClient instance will persist for the application lifetime. While this is generally acceptable, consider implementing IDisposable or using a factory pattern for better resource management in larger applications.
189-189
: Questionable paragraph spacing modification.Setting
SpacingAfter = 0
for every paragraph that contains placeholders may not be desirable, as it removes spacing that might be intentionally part of the document formatting.Consider removing this line or making it conditional based on the document requirements:
- paragraph.SpacingAfter = 0;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
OsmoDoc/Word/WordDocumentGenerator.cs
(1 hunks)
🧰 Additional context used
🪛 GitHub Check: build
OsmoDoc/Word/WordDocumentGenerator.cs
[warning] 316-316:
Possible null reference argument for parameter 'id' in 'OpenXmlPart OpenXmlPartContainer.GetPartById(string id)'.
[warning] 316-316:
Dereference of a possibly null reference.
[warning] 310-310:
Possible null reference argument for parameter 'key' in 'bool Dictionary<string, string>.ContainsKey(string key)'.
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (csharp)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
♻️ Duplicate comments (2)
OsmoDoc/Word/WordDocumentGenerator.cs (2)
83-83
: Extract regex pattern to a constant.The regex pattern
@"{[a-zA-Z]+}"
is duplicated in multiple locations (lines 83, 169, 204), violating the DRY principle.Extract it to a private constant:
public static class WordDocumentGenerator { + private const string PlaceholderPattern = @"{[a-zA-Z]+}"; - if (paragraph.ParagraphText == string.Empty || !new Regex(@"{[a-zA-Z]+}").IsMatch(paragraph.ParagraphText)) + if (paragraph.ParagraphText == string.Empty || !new Regex(PlaceholderPattern).IsMatch(paragraph.ParagraphText))
303-309
: Address null safety issues flagged by static analysis.The static analysis correctly identifies potential null reference issues that were previously flagged in past reviews.
The following null safety issues need to be addressed:
docProperty.Name
could be null when used as dictionary key (line 303)blip.Embed
could be null when passed toGetPartById
(line 309)These issues were mentioned as fixed in PR #43, but appear to still be present in this code version.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
OsmoDoc/Word/WordDocumentGenerator.cs
(1 hunks)
🧰 Additional context used
🪛 GitHub Check: build
OsmoDoc/Word/WordDocumentGenerator.cs
[warning] 309-309:
Dereference of a possibly null reference.
[warning] 303-303:
Possible null reference argument for parameter 'key' in 'bool Dictionary<string, string>.ContainsKey(string key)'.
[warning] 146-146:
This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (csharp)
🔇 Additional comments (2)
OsmoDoc/Word/WordDocumentGenerator.cs (2)
30-127
: Async conversion successfully implemented!The method signature and implementation correctly support asynchronous operations as intended by the PR objectives. The use of
TryAdd
properly handles duplicate placeholders, and the overall structure maintains good separation of concerns.The redundant try-catch block (lines 123-126) remains as previously discussed - understood this will be addressed later.
134-139
: Excellent fix for stream disposal issue!Using
File.ReadAllBytesAsync
with aMemoryStream
elegantly solves the premature stream disposal problem while maintaining async operation. The XWPFDocument now has reliable access to its data throughout its lifecycle.
36db8f2
to
5f0e3bf
Compare
Task Link
REST-1564
Description
PdfDocumentGenerator
class methods asynchronousGenerateDocumentByTemplate
class methods asynchronousSummary by CodeRabbit
Summary by CodeRabbit
New Features
Refactor
Bug Fixes
Documentation
Chores