SuncodeSoftware.SuperSDK.Core
1.0.5
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SuncodeSoftware.SuperSDK.Core --version 1.0.5
NuGet\Install-Package SuncodeSoftware.SuperSDK.Core -Version 1.0.5
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SuncodeSoftware.SuperSDK.Core" Version="1.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SuncodeSoftware.SuperSDK.Core" Version="1.0.5" />
<PackageReference Include="SuncodeSoftware.SuperSDK.Core" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SuncodeSoftware.SuperSDK.Core --version 1.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SuncodeSoftware.SuperSDK.Core, 1.0.5"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SuncodeSoftware.SuperSDK.Core@1.0.5
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SuncodeSoftware.SuperSDK.Core&version=1.0.5
#tool nuget:?package=SuncodeSoftware.SuperSDK.Core&version=1.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SuperSDK.Core
SuperSDK.Core 是 Goes 应用程序的核心基础库,提供零 UI 依赖的通用工具类和消息系统。
✨ 核心特性
📡 消息总线系统
- ✅ 纯 C# 实现 - 无 ReactiveUI、Avalonia 等 UI 框架依赖
- ✅ 多级通道 - 支持全局、Fixture级、Slot级消息隔离
- ✅ 请求-响应模式 - 支持异步请求处理,带超时控制
- ✅ 性能优化 - 内置数字缓存、通道名优化
- ✅ 线程安全 - 完全线程安全的消息分发
🛠️ 工具类库
- DataPathHelper - 测试数据路径生成(支持 SlotSync、FixtureSync 等模式)
- FileTools - 文件路径验证、文件操作工具
- Utils - 性能测量、随机数生成、文件名解析等
📦 安装
dotnet add package SuperSDK.Core
或通过 NuGet 包管理器:
Install-Package SuperSDK.Core
🚀 快速开始
1. 消息总线 - 基础用法
using SuperSDK.Core.Messaging;
// 定义消息类型
public class TestResultMessage
{
public string TestName { get; set; }
public bool Passed { get; set; }
}
// 订阅消息(全局通道)
public class TestObserver
{
public TestObserver()
{
MessageBus.Subscribe<TestResultMessage>(this, OnTestResult);
}
private void OnTestResult(TestResultMessage msg)
{
Console.WriteLine($"Test: {msg.TestName}, Result: {msg.Passed}");
}
~TestObserver()
{
MessageBus.UnsubscribeAll(this); // 清理订阅
}
}
// 发送消息
MessageBus.Send(new TestResultMessage
{
TestName = "Voltage Test",
Passed = true
});
2. Fixture/Slot 级通道隔离
适用于多工位测试场景:
// Fixture 级通道(例如:Fixture 0)
MessageBus.Subscribe<TestResultMessage>(this, msg => {
Console.WriteLine($"[Fixture 0] {msg.TestName}");
}, fixtureId: 0);
MessageBus.Send(new TestResultMessage { TestName = "Test1", Passed = true }, fixtureId: 0);
// Slot 级通道(例如:Fixture 0, Slot 1)
MessageBus.Subscribe<TestResultMessage>(this, msg => {
Console.WriteLine($"[F0S1] {msg.TestName}");
}, fixtureId: 0, slotId: 1);
MessageBus.Send(new TestResultMessage { TestName = "Test2", Passed = false },
fixtureId: 0, slotId: 1);
3. 请求-响应模式
// 定义请求和响应类型
public class GetConfigRequest
{
public string ConfigName { get; set; }
}
public class ConfigResponse
{
public string Value { get; set; }
}
// 注册请求处理器
public class ConfigService
{
public ConfigService()
{
MessageBus.RegisterRequestHandler<GetConfigRequest, ConfigResponse>(
this,
async req => {
// 模拟数据库查询
await Task.Delay(100);
return new ConfigResponse { Value = "TestValue" };
}
);
}
}
// 发送请求并等待响应
var response = await MessageBus.SendRequest<GetConfigRequest, ConfigResponse>(
new GetConfigRequest { ConfigName = "DataPath" },
timeout: 5000 // 5秒超时
);
Console.WriteLine($"Config Value: {response.Value}");
4. 数据路径生成工具
using SuperSDK.Core.Tools;
// SlotSync 模式路径生成
DateTime now = DateTime.Now;
string dataRoot = "D:\\GoesData";
// 1. 创建 Fixture 批次文件夹
string fixturePath = DataPathHelper.GetFixtureBatchFolderPath(
fixtureId: 0,
startTime: now,
dataRootPath: dataRoot
);
// 返回: D:\GoesData\2025-12-15\F1_20251215_143052
// 2. 创建 Slot 数据文件夹
string slotPath = DataPathHelper.GetSlotDataFolderPath(
fixtureId: 0,
slotId: 0,
startTime: now,
workMode: "SlotSync",
dataRootPath: dataRoot,
sn: "SN12345",
fixtureBatchFolderPath: fixturePath
);
// 返回: D:\GoesData\2025-12-15\F1_20251215_143052\S1_SN12345_20251215_143055
// 3. 获取 CSV 文件路径
string csvPath = DataPathHelper.GetDetailedCsvFilePath(
fixtureId: 0,
slotId: 0,
startTime: now,
workMode: "SlotSync",
dataRootPath: dataRoot,
sn: "SN12345",
fixtureBatchFolderPath: fixturePath
);
// 返回: D:\GoesData\2025-12-15\F1_20251215_143052\S1_SN12345_20251215_143055\ItemResult.csv
// 确保文件夹存在
DataPathHelper.EnsureFolderExists(slotPath);
5. 性能测量工具
using SuperSDK.Core.Tools;
// 方式 1:自动打印耗时
var result = Utils.MeasureTime(() => {
// 执行耗时操作
Thread.Sleep(100);
return "完成";
}, "数据库查询");
// 输出: 数据库查询耗时: 100 ms
// 方式 2:获取耗时数据
var result2 = Utils.MeasureTime(() => {
Thread.Sleep(50);
return 42;
}, out TimeSpan elapsed);
Console.WriteLine($"操作耗时: {elapsed.TotalMilliseconds:F2} ms");
6. 文件工具类
using SuperSDK.Core.Tools;
// 验证路径
bool isValid = FileTools.IsValidPath("C:\\Data\\test.csv"); // true
bool isInvalid = FileTools.IsValidPath("C:\\Data\\test?.csv"); // false (? 是非法字符)
// 检查路径是否存在
if (FileTools.PathExists("D:\\Data"))
{
Console.WriteLine("路径存在");
}
// 确保目录存在
FileTools.EnsureDirectoryExists("D:\\Logs\\2025-12-15");
// 安全删除文件
bool deleted = FileTools.SafeDeleteFile("D:\\temp.txt");
// 获取文件大小
long fileSize = FileTools.GetFileSize("D:\\data.csv");
Console.WriteLine($"文件大小: {fileSize} 字节");
📖 API 文档
MessageBus 类
发送消息
| 方法 | 说明 |
|---|---|
Send<T>(T message) |
发送全局消息 |
Send<T>(T message, int fixtureId) |
发送 Fixture 级消息 |
Send<T>(T message, int fixtureId, int slotId) |
发送 Slot 级消息 |
Log(string name, string message, LogLevel level) |
发送日志消息 |
订阅消息
| 方法 | 说明 | 返回值 |
|---|---|---|
Subscribe<T>(object owner, Action<T> handler) |
订阅全局消息 | IDisposable |
Subscribe<T>(object owner, Action<T> handler, int fixtureId) |
订阅 Fixture 级消息 | IDisposable |
Subscribe<T>(object owner, Action<T> handler, int fixtureId, int slotId) |
订阅 Slot 级消息 | IDisposable |
取消订阅
| 方法 | 说明 |
|---|---|
UnsubscribeAll(object owner) |
取消该 owner 的所有订阅 |
Unsubscribe<T>(object owner) |
取消全局通道的特定类型订阅 |
Unsubscribe<T>(object owner, int fixtureId) |
取消 Fixture 级订阅 |
Unsubscribe<T>(object owner, int fixtureId, int slotId) |
取消 Slot 级订阅 |
请求-响应
| 方法 | 说明 |
|---|---|
RegisterRequestHandler<TReq, TResp>(owner, handler) |
注册请求处理器 |
SendRequest<TReq, TResp>(request, timeout) |
发送请求并等待响应 |
UnregisterRequestHandler<TReq>(owner) |
注销请求处理器 |
HasRequestHandler<TReq>() |
检查是否已注册处理器 |
DataPathHelper 类
| 方法 | 说明 |
|---|---|
GetDateFolderPath(date, rootPath) |
获取日期文件夹路径 |
GetFixtureBatchFolderPath(fixtureId, time, rootPath) |
获取 Fixture 批次文件夹 |
GetSlotFolderName(slotId, sn, time) |
获取 Slot 文件夹名称 |
GetSlotDataFolderPath(...) |
获取 Slot 数据文件夹完整路径 |
GetDetailedCsvFilePath(...) |
获取详细测试数据 CSV 路径 |
GetDailySummaryCsvFilePath(date, rootPath) |
获取每日汇总 CSV 路径 |
EnsureFolderExists(path) |
确保文件夹存在 |
Utils 类
| 方法 | 说明 |
|---|---|
MeasureTime<T>(Func<T>, out TimeSpan) |
测量函数执行时间 |
MeasureTime<T>(Func<T>, string) |
测量并打印耗时 |
GetRandomI(num1, num2) |
生成随机整数 |
GetRandomD(num1, num2) |
生成随机浮点数(1位小数) |
ParseFileName(path, out name, out version) |
解析版本化文件名 |
KillPythonProcesses() |
终止所有 Python 进程 |
FileTools 类
| 方法 | 说明 |
|---|---|
IsValidPath(path) |
验证路径是否有效 |
PathExists(path) |
检查路径是否存在 |
EnsureDirectoryExists(path) |
确保目录存在 |
SafeDeleteFile(path) |
安全删除文件 |
GetFileSize(path) |
获取文件大小 |
🏗️ 完整 SuperSDK 系列
SuperSDK 采用分层架构,按需引用:
| Package | 描述 | 依赖 |
|---|---|---|
| SuperSDK.Core ⭐ | 核心工具和消息系统(本包) | 无 |
| SuperSDK.Data | 数据访问层(EF Core + Sqlite) | Core + EF Core |
| SuperSDK.UI.Avalonia | Avalonia UI 组件 | Core + Avalonia |
| SuperSDK.Driver | 仪器驱动和 License | Core + NSec |
📝 注意事项
- ✅ 线程安全:所有 API 都是线程安全的
- ✅ 内存管理:记得在对象销毁时调用
MessageBus.UnsubscribeAll(this) - ✅ 性能优化:使用 Fixture/Slot 级通道避免全局消息泛滥
- ⚠️ 订阅管理:避免重复订阅同一消息类型
📄 License
MIT License - 详见 LICENSE 文件
🤝 贡献
欢迎提交 Issue 和 Pull Request!
Made with ❤️ by Goes Team
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- Avalonia (>= 11.3.7)
- ReactiveUI (>= 20.1.63)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on SuncodeSoftware.SuperSDK.Core:
| Package | Downloads |
|---|---|
|
SuncodeSoftware.SuperSDK.Data
数据访问层 - 基于 Entity Framework Core 和 SQLite/SQLCipher 的数据持久化 |
|
|
SuncodeSoftware.SuperSDK.UI
Avalonia UI 通用组件库 - 通知管理、对话框、ViewModelBase 等 |
|
|
SuncodeSoftware.SuperSDK.App
Application foundation framework for Avalonia-based Goes applications |
|
|
SuncodeSoftware.SuperSDK.Canvas
SuperSDK Canvas - 开箱即用的 Avalonia 画布组件,支持设备绘制、连线管理、缩放平移等功能 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.6 | 235 | 12/23/2025 |
| 1.2.5 | 218 | 12/23/2025 |
| 1.2.4 | 220 | 12/23/2025 |
| 1.2.2 | 218 | 12/23/2025 |
| 1.2.1 | 215 | 12/22/2025 |
| 1.2.0 | 221 | 12/22/2025 |
| 1.1.8 | 215 | 12/22/2025 |
| 1.1.7 | 213 | 12/22/2025 |
| 1.1.6 | 214 | 12/22/2025 |
| 1.1.5 | 218 | 12/22/2025 |
| 1.1.4 | 221 | 12/22/2025 |
| 1.1.3 | 223 | 12/22/2025 |
| 1.1.2 | 222 | 12/22/2025 |
| 1.1.1 | 223 | 12/22/2025 |
| 1.0.7 | 301 | 12/16/2025 |
| 1.0.6 | 299 | 12/16/2025 |
| 1.0.5 | 303 | 12/16/2025 |
| 1.0.4 | 306 | 12/16/2025 |
| 1.0.3 | 303 | 12/16/2025 |
| 1.0.2 | 306 | 12/16/2025 |
| 1.0.1 | 237 | 12/15/2025 |
| 1.0.0 | 224 | 12/15/2025 |
Added DLL integrity validation