Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Jul 19, 2025

Link issues

fixes #6446

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Remove the abstract socket data converter base class in favor of a concrete generic SocketDataConverter, update adapter and sample code to use the new converter, and enhance examples and tests for attribute-driven data adaptation.

Bug Fixes:

Enhancements:

  • Introduce concrete generic SocketDataConverter with default TryConvertTo and CreateEntity implementations.
  • Refactor DataPackageAdapter and SetDataPackageAdapter usage in code samples and tests to use the new SocketDataConverter.
  • Enhance sample documentation to illustrate attribute-based socket data conversion using SocketDataConverterAttribute and SocketDataPropertyAttribute.
  • Clean up minor code style issues such as variable naming, IPEndPoint initialization, and Razor sample fixes.

Documentation:

  • Update server-side and BootstrapBlazor documentation samples to reflect the new data adapter approach and converter class names.

Tests:

  • Update existing tests to use SocketDataConverter and add a test for converter failure scenario.

@bb-auto bb-auto bot added the enhancement New feature or request label Jul 19, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jul 19, 2025

Reviewer's Guide

This PR replaces the abstract SocketDataConverterBase with a concrete generic SocketDataConverter (providing a default TryConvertTo and CreateEntity implementation), introduces a DataPackageAdapter abstraction in client samples to replace direct SetDataHandler usage, updates tests and sample components to reference the new converter and adapter types, and applies several minor C# syntax and style cleanups.

Class diagram for SocketDataConverter replacing SocketDataConverterBase

classDiagram
    class ISocketDataConverter~TEntity~ {
        <<interface>>
        +bool TryConvertTo(ReadOnlyMemory<byte> data, out TEntity? entity)
    }
    class SocketDataConverter~TEntity~ {
        +bool TryConvertTo(ReadOnlyMemory<byte> data, out TEntity? entity)
        +TEntity CreateEntity()
        +bool Parse(ReadOnlyMemory<byte> data, TEntity entity)
    }
    ISocketDataConverter~TEntity~ <|.. SocketDataConverter~TEntity~
Loading

Class diagram for DataPackageAdapter usage in client samples

classDiagram
    class DataPackageAdapter {
        +FixLengthDataPackageHandler DataPackageHandler
        +event ReceivedCallBack(ReadOnlyMemory<byte> data)
    }
    class FixLengthDataPackageHandler {
        +int Length
    }
    DataPackageAdapter o-- FixLengthDataPackageHandler : uses
Loading

Class diagram for SocketClientOptions minor property update

classDiagram
    class SocketClientOptions {
        +IPEndPoint LocalEndPoint
        +bool EnableLog
        +bool IsAutoReconnect
    }
    class IPEndPoint
    SocketClientOptions o-- IPEndPoint : uses
Loading

File-Level Changes

Change Details Files
Introduce DataPackageAdapter for socket data handling in samples
  • Instantiate DataPackageAdapter and set DataPackageHandler instead of using SetDataHandler
  • Use client.SetDataPackageAdapter(adapter, callback) with ValueTask callback signature
  • Rename sample callback parameters for consistency (Data -> data)
  • Update sample UI descriptions to reference '数据适配器' rather than '数据处理器'
src/BootstrapBlazor.Server/Components/Samples/SocketFactories.razor
src/BootstrapBlazor.Server/Components/Samples/Sockets/Adapters.razor.cs
src/BootstrapBlazor.Server/Components/Samples/Sockets/Adapters.razor
Convert abstract SocketDataConverterBase into concrete generic SocketDataConverter
  • Remove abstract keyword and rename class to SocketDataConverter
  • Implement default virtual TryConvertTo method and CreateEntity helper
  • Move implementation into new non-abstract file SocketDataConverter.cs
src/BootstrapBlazor/Services/TcpSocket/DataConverter/SocketDataConverter.cs
Update tests and sample entities to use generic SocketDataConverter
  • Replace MockEntitySocketDataConverter references with SocketDataConverter in tests
  • Remove old MockEntitySocketDataConverter class and add a MockSocketDataConverter deriving from new generic converter
  • Update SocketDataConverterAttribute on MockEntity in razor samples to point to SocketDataConverter
test/UnitTest/Services/TcpSocketFactoryTest.cs
src/BootstrapBlazor.Server/Components/Samples/Sockets/DataEntities.razor
Apply minor C# syntax and style cleanups
  • Simplify IPEndPoint initialization using target-typed new()
  • Remove redundant namespace qualifiers (e.g., Encoding.UTF8 instead of System.Text.Encoding)
  • Clean up XML comment formatting and whitespace in SocketClientOptions
src/BootstrapBlazor/Services/TcpSocket/SocketClientOptions.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#6446 Remove the 'abstract' keyword from the SocketDataConverter class (previously SocketDataConverterBase).

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto bot added this to the 9.8.0 milestone Jul 19, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @ArgoZhang - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Services/TcpSocket/DataConverter/SocketDataConverterBase.cs:34` </location>
<code_context>
+    /// 创建实体实例方法
+    /// </summary>
+    /// <returns></returns>
+    protected virtual TEntity CreateEntity() => Activator.CreateInstance<TEntity>();

     /// <summary>
</code_context>

<issue_to_address>
Using Activator.CreateInstance may throw if TEntity lacks a parameterless constructor.

Document the requirement for a public parameterless constructor or handle instantiation for types that lack one.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Jul 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (f1ad761) to head (f4fe42b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6447   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          748       748           
  Lines        32259     32266    +7     
  Branches      4560      4561    +1     
=========================================
+ Hits         32259     32266    +7     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ArgoZhang ArgoZhang merged commit 4bc092d into main Jul 19, 2025
7 checks passed
@ArgoZhang ArgoZhang deleted the refactor-socket branch July 19, 2025 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(SocketDataConveter): remove abstract keyword

2 participants