![]() |
VOOZH | about |
dotnet add package CodeWF.NetWrapper --version 2.1.2.3
NuGet\Install-Package CodeWF.NetWrapper -Version 2.1.2.3
<PackageReference Include="CodeWF.NetWrapper" Version="2.1.2.3" />
<PackageVersion Include="CodeWF.NetWrapper" Version="2.1.2.3" />Directory.Packages.props
<PackageReference Include="CodeWF.NetWrapper" />Project file
paket add CodeWF.NetWrapper --version 2.1.2.3
#r "nuget: CodeWF.NetWrapper, 2.1.2.3"
#:package CodeWF.NetWrapper@2.1.2.3
#addin nuget:?package=CodeWF.NetWrapper&version=2.1.2.3Install as a Cake Addin
#tool nuget:?package=CodeWF.NetWrapper&version=2.1.2.3Install as a Cake Tool
CodeWF.NetWeaver 是网络数据包序列化与反序列化的核心库。
CodeWF.NetWrapper 构建在它之上,提供 TCP/UDP 帮助类、命令分发,以及文件传输 / 文件管理能力。
2.1.2.3,版本号统一维护在根目录 Directory.Build.props 的 <Version> 节点。net8.0;net10.0;Demo、App、测试与内部应用项目统一使用 net11.0 / net11.0-windows。logo.svg、logo.png、logo.ico 是唯一图标源,子工程只通过 MSBuild Link 引用,不维护图标副本。README.md 和 UpdateLog.md。| 项目 | 说明 |
|---|---|
CodeWF.NetWeaver |
核心数据包序列化 / 反序列化库。 |
CodeWF.NetWrapper |
基于 CodeWF.NetWeaver 的 TCP/UDP Socket 帮助库。 |
SocketTest.Client |
Wrapper 功能演示客户端。 |
SocketTest.Server |
Wrapper 功能演示服务端。 |
仅安装数据包序列化核心:
dotnet add package CodeWF.NetWeaver
如果需要 TCP/UDP 命令分发、文件传输或文件管理能力,再安装封装层:
dotnet add package CodeWF.NetWrapper
也可以在 Package Manager Console 中安装:
NuGet\Install-Package CodeWF.NetWeaver
global.jsonDirectory.Packages.props 统一做中央包管理CodeWF.NetWeaver 与 CodeWF.NetWrapperAvalonia 12.0.3、Semi.Avalonia 12.0.1、ReactiveUI.Avalonia 12.0.1Prism.DryIoc.Avalonia 固定为最后一个免费可用的 8.1.97.11073Avalonia.Controls.DataGrid 链路切换到开源 ProDataGrid 与自研开源 CodeWF.AvaloniaControls.ProDataGrid.Themes,不再使用非开源 Semi ProDataGrid 主题包还原、构建并测试整个解决方案:
dotnet restore CodeWF.NetWeaver.slnx
dotnet build CodeWF.NetWeaver.slnx -c Debug
dotnet test CodeWF.NetWeaver.slnx -c Debug --no-build
打包 NuGet 类库:
pack.bat
发布可运行示例:
publish_all.bat
运行示例时先启动服务端,再启动客户端:
dotnet run --project src/SocketTest.Server/SocketTest.Server.csproj -f net11.0-windows
dotnet run --project src/SocketTest.Client/SocketTest.Client.csproj -f net11.0-windows
每个数据包由固定头部和对象正文两部分组成:
Header
- BufferLen: int
- SystemId: long
- ObjectId: ushort
- ObjectVersion: byte
- UnixTimeMilliseconds: long
Body
- 序列化后的对象负载
可以通过 NetHead 为 DTO 标记协议头信息:
using CodeWF.NetWeaver.Base;
[NetHead(10, 1)]
public class ResponseProcessList : INetObject
{
public int TaskId { get; set; }
public int TotalSize { get; set; }
public List<ProcessItem>? Processes { get; set; }
}
public record ProcessItem
{
public int Pid { get; set; }
public string? Name { get; set; }
}
序列化:
var netObject = new ResponseProcessList
{
TaskId = 3,
TotalSize = 2,
Processes =
[
new ProcessItem { Pid = 1, Name = "CodeWF.NetWeaver" },
new ProcessItem { Pid = 2, Name = "CodeWF.NetWrapper" }
]
};
var buffer = netObject.Serialize(systemId: 32);
Console.WriteLine($"Packet bytes: {buffer.Length}");
反序列化:
var deserialized = buffer.Deserialize<ResponseProcessList>();
Console.WriteLine($"Process count: {deserialized.Processes?.Count ?? 0}");
CodeWF.NetWrapper 负责 TCP/UDP 通信,并将原始数据包转换为强类型命令:
using CodeWF.EventBus;
using CodeWF.NetWrapper.Commands;
using CodeWF.NetWrapper.Helpers;
var server = new TcpSocketServer();
await server.StartAsync("Server", "0.0.0.0", 8888);
EventBus.Default.Subscribe<SocketCommand>(async (sender, command) =>
{
// 非文件管理命令可以在这里处理。
await Task.CompletedTask;
});
TcpSocketClient 和 TcpSocketServer 现在使用更清晰的文件管理接口。
每个请求 / 响应式通信对象都带有 TaskId。同一个传输流程中的请求、响应、分块数据、分块确认、拒绝消息与完成消息都会沿用同一个 TaskId,用于把 Response 与对应的 Request 一一关联起来。
await client.BrowseFileSystemAsync("/");
await client.CreateDirectoryAsync("uploads");
await client.DeletePathAsync("old-folder", true);
await client.DeletePathAsync("uploads/old.bin", false);
await client.UploadFileAsync(@"D:\local\demo.zip", "uploads/demo.zip");
await client.DownloadFileAsync("uploads/demo.zip", @"D:\downloads");
var server = new TcpSocketServer
{
// 所有浏览、创建、删除、上传、下载操作都会限制在该根目录下。
FileSaveDirectory = @"D:\ServerFiles"
};
server.FileTransferProgress += (sender, args) =>
{
Console.WriteLine($"{args.FileName}: {args.Progress:F2}%");
};
设置 FileSaveDirectory 后:
"uploads/demo.zip" 会解析到这个根目录内。"..\\outside.txt" 之类的路径跳出根目录时,服务端会拒绝请求。FileTransferProgress 事件。当前文件管理协议对象名称如下:
| 类别 | 类型 |
|---|---|
| 浏览请求 | BrowseFileSystemRequest |
| 浏览响应 | BrowseFileSystemResponse |
| 磁盘列表响应 | DriveListResponse |
| 创建目录请求 | CreateDirectoryRequest |
| 创建目录响应 | CreateDirectoryResponse |
| 删除路径请求 | DeletePathRequest |
| 删除路径响应 | DeletePathResponse |
当前文件传输协议对象名称如下:
| 类别 | 类型 |
|---|---|
| 上传请求 | FileUploadRequest |
| 上传响应 | FileUploadResponse |
| 下载请求 | FileDownloadRequest |
| 下载响应 | FileDownloadResponse |
| 分块数据 | FileChunkData |
| 分块确认 | FileChunkAck |
| 传输拒绝 | FileTransferReject |
| 传输完成 | FileTransferComplete |
仓库中已经补充了面向 CodeWF.NetWrapper 文件链路的测试:
FileSaveDirectory 的路径访问。运行方式:
dotnet test src\CodeWF.NetWrapper.Tests\CodeWF.NetWrapper.Tests.csproj
设计说明文档见:
检查时间:2026-05-20。检查范围包括 NuGet 元数据、恢复后的 project.assets.json、NuGet.org 信息以及上游源码/许可证链接。优先接受 MIT / Apache-2.0 / BSD。
本次整改:
Semi.Avalonia.ProDataGrid,改用 MIT 的 ProDataGrid 和自研开源 CodeWF.AvaloniaControls.ProDataGrid.Themes 包。AvaloniaUI.DiagnosticsSupport,因为该包未公开明确的开源许可证和源码仓库。CodeWF.Tools 改为按需引用 CodeWF.Tools.Core / CodeWF.Tools.Files,避免不需要图片能力时引入 Magick 链路。System.Configuration.ConfigurationManager、System.Drawing.Common、System.Security.Cryptography.ProtectedData、System.Security.Permissions、System.Windows.Extensions 固定到 10.0.8,移除旧 4.7.0 传递依赖链。Avalonia 12.0.3、CodeWF.EventBus 3.4.5.5、CodeWF.LogViewer.Avalonia 12.0.3.1、CodeWF.AvaloniaControls.ProDataGrid.Themes 12.0.3.2、CodeWF.Tools.Core / CodeWF.Tools.Files 1.3.13.2、coverlet.collector 10.0.1。| 包 | 协议 | 源码/项目地址 | 结论 |
|---|---|---|---|
Avalonia / Avalonia.Desktop / Avalonia.Fonts.Inter / Avalonia.Markup.Xaml.Loader |
MIT | https://github.com/AvaloniaUI/Avalonia | 通过,12.0.3 |
CodeWF.EventBus / CodeWF.Log.Core / CodeWF.LogViewer.Avalonia / CodeWF.AvaloniaControls.ProDataGrid.Themes / CodeWF.Tools.Core / CodeWF.Tools.Files |
MIT | CodeWF 自研仓库 | 自研开源包;当前使用 CodeWF.EventBus 3.4.5.5、CodeWF.Log.Core 12.0.3.1、CodeWF.LogViewer.Avalonia 12.0.3.1、CodeWF.AvaloniaControls.ProDataGrid.Themes 12.0.3.2、CodeWF.Tools.* 1.3.13.2 |
Lorem.Universal.Net |
MIT | https://github.com/trichards57/Lorem.Universal.NET | 示例依赖,通过 |
Microsoft.NET.Test.Sdk |
MIT | https://github.com/microsoft/vstest | 测试依赖,通过 |
Prism.DryIoc.Avalonia |
MIT | https://github.com/AvaloniaCommunity/Prism.Avalonia | 通过,固定到 8.x 开源线 |
ProDataGrid |
MIT | https://github.com/wieslawsoltes/ProDataGrid | 通过 |
ReactiveUI.Avalonia |
MIT | https://github.com/reactiveui/reactiveui | 通过 |
Semi.Avalonia |
MIT | https://github.com/irihitech/Semi.Avalonia | 通过,仅使用开源主体包 |
System.Configuration.ConfigurationManager / System.Drawing.Common / System.Security.Cryptography.ProtectedData / System.Security.Permissions / System.Windows.Extensions |
MIT | https://github.com/dotnet/dotnet | 通过,固定到 10.0.8 |
coverlet.collector |
MIT | https://github.com/coverlet-coverage/coverlet | 测试依赖,通过,10.0.1 |
xunit / xunit.runner.visualstudio |
Apache-2.0 | https://github.com/xunit/xunit | 测试依赖,通过 |
传递依赖检查结论:Avalonia / SkiaSharp / ANGLE、ProDataGrid、CodeWF.AvaloniaControls.ProDataGrid.Themes、CodeWF.Tools.Files(CsvHelper、MiniExcel、SharpCompress、YamlDotNet)、Prism.Avalonia、ReactiveUI 链路均有公开源码。有效恢复资产不再包含 Semi.Avalonia.ProDataGrid、AvaloniaUI.DiagnosticsSupport、Magick.NET-Q16-AnyCPU、System.Drawing.Common 4.7.0、System.Configuration.ConfigurationManager 4.7.0 或 System.Security.Cryptography.ProtectedData 4.7.0。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 1 NuGet packages that depend on CodeWF.NetWrapper:
| Package | Downloads |
|---|---|
|
CodeWF.EventBus.Socket
基于 Socket 实现的分布式事件总线,不依赖第三方 MQ。 |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.1.2.3 | 112 | 6/8/2026 |
| 2.1.2.1 | 103 | 6/5/2026 |
| 2.1.1 | 118 | 5/3/2026 |
| 2.1.0 | 119 | 4/17/2026 |
| 2.0.24 | 129 | 2/13/2026 |
| 2.0.23 | 120 | 1/23/2026 |
| 2.0.20 | 146 | 1/5/2026 |
| 2.0.14 | 210 | 12/25/2025 |
| 2.0.8 | 198 | 12/14/2025 |
| 2.0.7 | 171 | 12/14/2025 |
| 2.0.6 | 205 | 12/13/2025 |
| 2.0.5 | 466 | 12/10/2025 |
| 2.0.4 | 464 | 12/10/2025 |
| 2.0.3 | 459 | 12/10/2025 |
| 1.0.1 | 467 | 12/10/2025 |