-
-
Notifications
You must be signed in to change notification settings - Fork 363
doc(ITcpSocketFactory): add ITcpSocketFactory documentation #6256
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
Conversation
Reviewer's GuideThis PR adds comprehensive documentation and a sample implementation for the ITcpSocketFactory service in the BootstrapBlazor.Server project by introducing a new demo page and code-behind, updating the navigation menu and localization resources, and registering the route in the documentation manifest. Class diagram for ITcpSocketFactory and related types in the documentation sampleclassDiagram
class ITcpSocketFactory {
+ITcpSocketClient GetOrCreate(string host, int port)
}
class ITcpSocketClient {
+Task ConnectAsync(string host, int port)
+Task SendAsync(byte[] data)
+void Close()
+void SetDataHandler(IDataPackageHandler handler)
}
class IDataPackageHandler {
<<interface>>
}
class DataPackageHandlerBase {
<<abstract>>
}
class FixLengthDataPackageHandler {
+FixLengthDataPackageHandler(int length)
+Func<byte[], Task> ReceivedCallBack
}
ITcpSocketFactory --> ITcpSocketClient : GetOrCreate
ITcpSocketClient --> IDataPackageHandler : SetDataHandler
DataPackageHandlerBase <|-- FixLengthDataPackageHandler
IDataPackageHandler <|-- DataPackageHandlerBase
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey @ArgoZhang - I've reviewed your changes - here's some feedback:
- It looks like the new
TcpSocketFactorymenu item isn’t localized yet – please add the corresponding keys and translations to en-US.json and zh-CN.json. - Please update docs.json to include the new SocketFactories sample so it appears in the generated documentation navigation.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- It looks like the new `TcpSocketFactory` menu item isn’t localized yet – please add the corresponding keys and translations to en-US.json and zh-CN.json.
- Please update docs.json to include the new SocketFactories sample so it appears in the generated documentation navigation.
## Individual Comments
### Comment 1
<location> `src/BootstrapBlazor.Server/Components/Samples/SocketFactories.razor:58` </location>
<code_context>
+ ReceivedCallBack = buffer =>
+ {
+ // 内部自动处理粘包分包问题,这里参数 buffer 一定是定长为 4 的业务数据
+ receivedBuffer = buffer;
+ return Task.CompletedTask;
+ }
</code_context>
<issue_to_address>
The variable 'receivedBuffer' is used without declaration in the example.
Please declare 'receivedBuffer' in the code snippet or clarify its purpose in the documentation to avoid confusion.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
// 创建 ITcpSocketClient 实例
var client = TcpSocketFactory.GetOrCreate("localhost", 0);
// 设置 FixLengthDataPackageHandler 数据处理器处理数据定长 4 的数据
client.SetDataHandler(new FixLengthDataPackageHandler(4)
{
// 设置接收数据回调方法
ReceivedCallBack = buffer =>
{
// 内部自动处理粘包分包问题,这里参数 buffer 一定是定长为 4 的业务数据
receivedBuffer = buffer;
return Task.CompletedTask;
}
});
// 连接远端节点 连接成功后自动开始接收数据
var connected = await client.ConnectAsync("192.168.10.100", 6688);
}
=======
// 用于存储接收到的数据包
byte[]? receivedBuffer = null;
// 创建 ITcpSocketClient 实例
var client = TcpSocketFactory.GetOrCreate("localhost", 0);
// 设置 FixLengthDataPackageHandler 数据处理器处理数据定长 4 的数据
client.SetDataHandler(new FixLengthDataPackageHandler(4)
{
// 设置接收数据回调方法
ReceivedCallBack = buffer =>
{
// 内部自动处理粘包分包问题,这里参数 buffer 一定是定长为 4 的业务数据
receivedBuffer = buffer;
return Task.CompletedTask;
}
});
// 连接远端节点 连接成功后自动开始接收数据
var connected = await client.ConnectAsync("192.168.10.100", 6688);
}
>>>>>>> REPLACE
</suggested_fix>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| // 创建 ITcpSocketClient 实例 | ||
| var client = TcpSocketFactory.GetOrCreate("localhost", 0); | ||
|
|
||
| // 设置 FixLengthDataPackageHandler 数据处理器处理数据定长 4 的数据 | ||
| client.SetDataHandler(new FixLengthDataPackageHandler(4) | ||
| { | ||
| // 设置接收数据回调方法 | ||
| ReceivedCallBack = buffer => | ||
| { | ||
| // 内部自动处理粘包分包问题,这里参数 buffer 一定是定长为 4 的业务数据 | ||
| receivedBuffer = buffer; | ||
| return Task.CompletedTask; | ||
| } | ||
| }); | ||
|
|
||
| // 连接远端节点 连接成功后自动开始接收数据 | ||
| var connected = await client.ConnectAsync("192.168.10.100", 6688); | ||
| } |
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.
suggestion: The variable 'receivedBuffer' is used without declaration in the example.
Please declare 'receivedBuffer' in the code snippet or clarify its purpose in the documentation to avoid confusion.
| // 创建 ITcpSocketClient 实例 | |
| var client = TcpSocketFactory.GetOrCreate("localhost", 0); | |
| // 设置 FixLengthDataPackageHandler 数据处理器处理数据定长 4 的数据 | |
| client.SetDataHandler(new FixLengthDataPackageHandler(4) | |
| { | |
| // 设置接收数据回调方法 | |
| ReceivedCallBack = buffer => | |
| { | |
| // 内部自动处理粘包分包问题,这里参数 buffer 一定是定长为 4 的业务数据 | |
| receivedBuffer = buffer; | |
| return Task.CompletedTask; | |
| } | |
| }); | |
| // 连接远端节点 连接成功后自动开始接收数据 | |
| var connected = await client.ConnectAsync("192.168.10.100", 6688); | |
| } | |
| // 用于存储接收到的数据包 | |
| byte[]? receivedBuffer = null; | |
| // 创建 ITcpSocketClient 实例 | |
| var client = TcpSocketFactory.GetOrCreate("localhost", 0); | |
| // 设置 FixLengthDataPackageHandler 数据处理器处理数据定长 4 的数据 | |
| client.SetDataHandler(new FixLengthDataPackageHandler(4) | |
| { | |
| // 设置接收数据回调方法 | |
| ReceivedCallBack = buffer => | |
| { | |
| // 内部自动处理粘包分包问题,这里参数 buffer 一定是定长为 4 的业务数据 | |
| receivedBuffer = buffer; | |
| return Task.CompletedTask; | |
| } | |
| }); | |
| // 连接远端节点 连接成功后自动开始接收数据 | |
| var connected = await client.ConnectAsync("192.168.10.100", 6688); | |
| } |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6256 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 710 710
Lines 31339 31339
Branches 4424 4424
=========================================
Hits 31339 31339
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Link issues
fixes #6255
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Add comprehensive documentation and sample implementation for the ITcpSocketFactory service
Enhancements:
Documentation: