# Device SDK for C#

## 安装
将 `DeviceSDK.cs` 添加到你的项目中。

## 初始化 

```csharp
var client = new DeviceClient(
baseUrl: "http://your-server:8080", // 服务器地址
encryptKey: "your-32-byte-encrypt-key-here123456" // 32字节加密密钥
);
```

## API 使用说明

### 1. 设备注册

```csharp
// 基本注册（无授权码）
var response = await client.RegisterDeviceAsync(new DeviceRegisterRequest {
Uid = "device-001",
DeviceModel = "test-model"
});```



```csharp
// 带授权码的注册
var response = await client.RegisterDeviceAsync(new DeviceRegisterRequest {
Uid = "device-001",
DeviceModel = "test-model",
License = "your-license-code-here"
});
```

### 2. 设备验证

```csharp
var validateResponse = await client.ValidateDeviceAsync("device-001");
Console.WriteLine($"设备状态: {validateResponse.Status}");
Console.WriteLine($"授权类型: {validateResponse.LicenseType}");
Console.WriteLine($"过期时间: {validateResponse.ExpireTime}");
```

### 3. 更新启动次数

```csharp
var startCountResponse = await client.UpdateStartCountAsync("device-001");
Console.WriteLine($"当前启动次数: {startCountResponse.Data.StartCount}");
```

### 4. 绑定授权码

```csharp
var bindLicenseResponse = await client.BindLicenseAsync("device-001", "your-license-code-here");
Console.WriteLine($"绑定结果: {bindLicenseResponse.Data.Success}");
```

## 错误处理
SDK 使用 `DeviceSDKException` 统一处理错误：

```csharp
try {
    // 调用 API 的代码
} catch (DeviceSDKException e) {
    Console.WriteLine($"错误码: {e.ErrorCode}, 错误信息: {e.Message}");
}
```

## 响应数据结构

```csharp
// 设备验证响应
public class DeviceValidateResponse
{
public string Status { get; set; } // 设备状态
public string LicenseType { get; set; } // 授权类型
public DateTime ExpireTime { get; set; } // 过期时间
public int StartCount { get; set; } // 启动次数
public int MaxUses { get; set; } // 最大使用次数
}
// 启动次数响应
public class StartCountResponse
{
public int Code { get; set; }
public string Message { get; set; }
public StartCountData Data { get; set; }
}
```
