Skip to content
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

Update for Async Support & .NET 8 #54

Merged
merged 5 commits into from
May 29, 2024
Merged

Conversation

ReynoldsSoftware
Copy link

@ReynoldsSoftware ReynoldsSoftware commented May 28, 2024

Summary by CodeRabbit

  • New Features

    • Introduced asynchronous email sending functionality, enhancing performance and responsiveness.
  • Improvements

    • Updated to support .NET 8.0, ensuring compatibility with the latest framework and libraries.
    • Enhanced email sending methods to return Task<bool>, providing better handling of asynchronous operations.
  • Tests

    • Updated test framework and dependencies to support asynchronous methods and .NET 8.0.

Copy link

coderabbitai bot commented May 28, 2024

Walkthrough

The update modernizes the NetCore.Utilities.Email.Smtp library by transitioning all email sending functionalities to asynchronous methods and upgrading the project to target .NET 8.0. This includes updating package references, modifying method signatures, and ensuring compatibility with the latest .NET standards.

Changes

Files Change Summary
src/.../NetCore.Utilities.Email.Smtp.csproj Updated package references to icg.netcore.utilities.email 7.0.0 and other packages to .NET 8.0.
src/.../SmtpService.cs Converted synchronous email sending methods to asynchronous, renamed methods with Async suffix.
src/.../NetCore.Utilities.Email.Smtp.Tests.csproj Updated target framework to net8.0 and upgraded several package references to newer versions.
src/.../SmtpServiceTests.cs Updated test methods to be asynchronous, renamed methods with Async suffix.
src/.../MimeKitService.cs Replaced synchronous email sending methods with asynchronous versions using await keyword.

Assessment against linked issues

Objective Addressed Explanation
Update to support new Async Methods (#50)
Update to .NET 8 (#55)

In code we trust, with threads we weave,
Asynchronous flows, our goals achieve.
With .NET 8, we now align,
Sending emails, in async time.
Progress made, our tasks complete,
With modern tools, our code's elite.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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

Outside diff range and nitpick comments (2)
src/NetCore.Utilities.Email.Smtp/SmtpService.cs (2)

Line range hint 75-93: Consider using await directly instead of Task.Run for I/O-bound operations.

Using await directly with asynchronous I/O operations is more efficient than wrapping them in Task.Run. Task.Run is generally used for CPU-bound work to run it on a background thread, but I/O-bound work should directly leverage asynchronous APIs if available.

- await Task.Run(() => _mimeKitService.SendEmail(toSend));
+ await _mimeKitService.SendEmailAsync(toSend);

Ensure that _mimeKitService.SendEmail has an asynchronous counterpart (SendEmailAsync), and use it directly.

Also applies to: 99-116, 150-177


75-75: Optimize token replacement logic.

The current implementation of token replacement in the email body is straightforward but could be optimized or refactored for better clarity or performance, especially if the list of tokens is large.
Consider using a more efficient method for replacing multiple tokens, possibly using regular expressions or a dedicated templating library if performance becomes a concern.

Also applies to: 99-99, 150-150

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 72c38f7 and dbb541e.
Files selected for processing (2)
  • src/NetCore.Utilities.Email.Smtp/NetCore.Utilities.Email.Smtp.csproj (1 hunks)
  • src/NetCore.Utilities.Email.Smtp/SmtpService.cs (5 hunks)
Files skipped from review due to trivial changes (1)
  • src/NetCore.Utilities.Email.Smtp/NetCore.Utilities.Email.Smtp.csproj
Additional comments not posted (1)
src/NetCore.Utilities.Email.Smtp/SmtpService.cs (1)

37-40: Convert synchronous methods to asynchronous methods.

The conversion of synchronous methods to asynchronous ones is well implemented across the class. This change aligns with modern best practices for handling I/O-bound operations, such as sending emails, which can benefit from asynchronous execution to improve scalability and responsiveness of applications.

Also applies to: 44-46, 50-53, 57-59, 63-65, 69-71, 75-93, 99-116, 122-125, 129-132, 136-139, 143-146, 150-177

@mitchelsellers
Copy link
Contributor

@ReynoldsSoftware the best option would be to update the ICG website, as that is the only one that is utilizing this library internally. You can use the .NET 8 branch that I have out there for it to test.

@mitchelsellers mitchelsellers changed the title [not ready yet] Attempt for making things async Update for Async Support & .NET 8 May 29, 2024
Copy link
Contributor

@mitchelsellers mitchelsellers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with changes as implemented

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
69.2% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

Copy link

@coderabbitai coderabbitai bot left a 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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between dbb541e and eec645d.
Files selected for processing (5)
  • src/NetCore.Utilities.Email.Smtp.Tests/NetCore.Utilities.Email.Smtp.Tests.csproj (1 hunks)
  • src/NetCore.Utilities.Email.Smtp.Tests/SmtpServiceTests.cs (12 hunks)
  • src/NetCore.Utilities.Email.Smtp/MimeKitService.cs (3 hunks)
  • src/NetCore.Utilities.Email.Smtp/NetCore.Utilities.Email.Smtp.csproj (3 hunks)
  • src/NetCore.Utilities.Email.Smtp/SmtpService.cs (5 hunks)
Files not reviewed due to errors (1)
  • src/NetCore.Utilities.Email.Smtp.Tests/SmtpServiceTests.cs (no review received)
Additional Context Used
GitHub Check Runs (1)
Codacy Static Code Analysis action_required (1)

src/NetCore.Utilities.Email.Smtp/SmtpService.cs: [failure] 150-150: src/NetCore.Utilities.Email.Smtp/SmtpService.cs#L150
Use the overloading mechanism instead of the optional parameters.

Additional comments not posted (7)
src/NetCore.Utilities.Email.Smtp.Tests/NetCore.Utilities.Email.Smtp.Tests.csproj (2)

4-4: Updated target framework to .NET 8.0 aligns with the PR objectives to support .NET 8.


10-20: Updated package references to their latest versions compatible with .NET 8.0. Ensure that all dependencies are compatible and that there are no breaking changes in the major version updates.

src/NetCore.Utilities.Email.Smtp/MimeKitService.cs (2)

18-18: Updated SendEmail method to SendEmailAsync in the IMimeKitService interface to support asynchronous operations, aligning with modern best practices.


42-48: The implementation of SendEmailAsync uses asynchronous operations effectively. Ensure that the SmtpClient is properly disposed of after use to avoid resource leaks.

Verification successful

The using var client = new SmtpClient(); statement in the SendEmailAsync method ensures that the SmtpClient instance is properly disposed of after use, preventing resource leaks.

  • The using statement in C# ensures that the Dispose method is called on the SmtpClient instance when it goes out of scope.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify proper disposal of SmtpClient instances.

# Test: Search for SmtpClient disposal logic.
rg --type csharp "using var client = new SmtpClient()"

Length of output: 156

src/NetCore.Utilities.Email.Smtp/NetCore.Utilities.Email.Smtp.csproj (2)

4-4: Updated target framework to .NET 8.0 aligns with the PR objectives to support .NET 8.


36-43: Updated package references to their latest versions compatible with .NET 8.0. Ensure that all dependencies are compatible and that there are no breaking changes in the major version updates.

src/NetCore.Utilities.Email.Smtp/SmtpService.cs (1)

37-37: All methods have been correctly updated to asynchronous versions with appropriate naming conventions. Ensure that all calls to these methods are updated to use the new asynchronous signatures.

Also applies to: 44-44, 50-50, 57-57, 63-63, 69-69, 75-75, 99-99, 122-122, 129-129, 136-136, 143-143, 150-150

Verification successful

All calls to the updated methods have been correctly updated to use the new asynchronous signatures.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all calls to updated methods use new asynchronous signatures.

# Test: Search for outdated method calls.
rg --type csharp "SendMessage("

Length of output: 108



Script:

#!/bin/bash
# Description: Verify all calls to updated methods use new asynchronous signatures.

# Test: Search for outdated method calls.
rg --type csharp "SendMessage("

Length of output: 108



Script:

#!/bin/bash
# Description: Verify all calls to updated methods use new asynchronous signatures.

# Test: Search for outdated method calls.
rg --type csharp "SendMessage\("

Length of output: 34

@mitchelsellers mitchelsellers merged commit 99ce9c0 into develop May 29, 2024
2 of 4 checks passed
@mitchelsellers mitchelsellers deleted the task/fix-issue-50 branch May 29, 2024 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update to .NET 8 Update to support new Async Methods
2 participants