Compare commits
2
Commits
1b5d57bd19
...
5e9e9fa818
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e9e9fa818 | ||
|
|
8ca0679fca |
No files matched your search
@@ -24,9 +24,9 @@ dotnet build Sharp.sln
|
||||
### Build specific project
|
||||
```bash
|
||||
cd src/Sharp
|
||||
dotnet build Client/Client.csproj # WPF demo application
|
||||
dotnet build Common/Common.csproj # Core utilities
|
||||
dotnet build Config/Config.csproj # Configuration management
|
||||
dotnet build Sharp.Demo/Sharp.Demo.csproj # WPF demo application (最佳实践示例)
|
||||
dotnet build Common/Common.csproj # Core utilities
|
||||
dotnet build Config/Config.csproj # Configuration management
|
||||
```
|
||||
|
||||
### Run tests
|
||||
@@ -36,10 +36,10 @@ dotnet test Sharp.sln # All tests
|
||||
dotnet test ../../test/Common.Test # Specific test project
|
||||
```
|
||||
|
||||
### Run the WPF Client application
|
||||
### Run the Sharp.Demo application
|
||||
```bash
|
||||
cd src/Sharp
|
||||
dotnet run --project Client/Client.csproj
|
||||
dotnet run --project Sharp.Demo/Sharp.Demo.csproj
|
||||
```
|
||||
|
||||
### Clean build artifacts
|
||||
@@ -56,7 +56,9 @@ dotnet clean Sharp.sln
|
||||
src/Sharp/ # All source projects
|
||||
├── Common/ # Core foundation (Result<T>, Global container, utilities, SystemConfig)
|
||||
├── Config/ # Multi-format configuration with hot-reload
|
||||
├── Wpf/ # WPF UI toolkit (MVVM, dialogs, converters)
|
||||
├── Wpf/ # WPF UI toolkit (MVVM, dialogs, converters) - NO UI library dependency
|
||||
├── Wpf.HandyControl/ # HandyControl UI library integration (optional)
|
||||
├── Wpf.DevTools/ # WPF Developer Tools (DevTools, LogViewer, Performance Monitor)
|
||||
├── Data/ # EF Core wrapper with repository pattern
|
||||
├── Log/ # Serilog-based structured logging
|
||||
├── Cache/ # Memory cache (planned)
|
||||
@@ -68,8 +70,7 @@ src/Sharp/ # All source projects
|
||||
├── Plc.Siemens/ # Siemens S7 PLC implementation (S7.NET+)
|
||||
├── Process/ # Process execution
|
||||
├── Python/ # Python script execution
|
||||
├── Client/ # WPF demo application
|
||||
└── Server/ # WPF server example
|
||||
└── Sharp.Demo/ # 综合演示应用(最佳实践示例,替代了 Client 和 Server)
|
||||
|
||||
test/ # MSTest test projects
|
||||
├── Common.Test/
|
||||
|
||||
+17
-14
@@ -45,9 +45,9 @@ dotnet build Sharp.sln
|
||||
### Build specific project
|
||||
```bash
|
||||
cd src/Sharp
|
||||
dotnet build Client/Client.csproj # WPF demo application
|
||||
dotnet build Common/Common.csproj # Core utilities
|
||||
dotnet build Config/Config.csproj # Configuration management
|
||||
dotnet build Sharp.Demo/Sharp.Demo.csproj # WPF demo application (最佳实践示例)
|
||||
dotnet build Common/Common.csproj # Core utilities
|
||||
dotnet build Config/Config.csproj # Configuration management
|
||||
```
|
||||
|
||||
### Run tests
|
||||
@@ -57,10 +57,10 @@ dotnet test Sharp.sln # All tests
|
||||
dotnet test ../../test/Common.Test # Specific test project
|
||||
```
|
||||
|
||||
### Run the WPF Client application
|
||||
### Run the Sharp.Demo application
|
||||
```bash
|
||||
cd src/Sharp
|
||||
dotnet run --project Client/Client.csproj
|
||||
dotnet run --project Sharp.Demo/Sharp.Demo.csproj
|
||||
```
|
||||
|
||||
### Clean build artifacts
|
||||
@@ -79,6 +79,7 @@ src/Sharp/ # All source projects
|
||||
├── Config/ # Multi-format configuration with hot-reload
|
||||
├── Wpf/ # WPF UI toolkit (MVVM, dialogs, converters) - NO UI library dependency
|
||||
├── Wpf.HandyControl/ # HandyControl UI library integration (optional)
|
||||
├── Wpf.DevTools/ # WPF Developer Tools (DevTools, LogViewer, Performance Monitor)
|
||||
├── Data/ # EF Core wrapper with repository pattern
|
||||
├── Log/ # Serilog-based structured logging
|
||||
├── Cache/ # Memory cache (planned)
|
||||
@@ -90,8 +91,7 @@ src/Sharp/ # All source projects
|
||||
├── Plc.Siemens/ # Siemens S7 PLC implementation (S7.NET+)
|
||||
├── Process/ # Process execution
|
||||
├── Python/ # Python script execution
|
||||
├── Client/ # WPF demo application
|
||||
└── Server/ # WPF server example
|
||||
└── Sharp.Demo/ # 综合演示应用(最佳实践示例,替代了 Client 和 Server)
|
||||
|
||||
test/ # MSTest test projects
|
||||
├── Common.Test/
|
||||
@@ -123,7 +123,7 @@ test/ # MSTest test projects
|
||||
- **Primary**: Microsoft.Extensions.DependencyInjection for standard DI
|
||||
- **Fallback**: Global service locator (Common.Global) for legacy/convenience
|
||||
- Services registered in `DependencyInjection` folders within each module
|
||||
- Client app startup (App.xaml.cs) orchestrates all service registration
|
||||
- Sharp.Demo app startup (App.xaml.cs) orchestrates all service registration
|
||||
|
||||
#### 3. Configuration Management
|
||||
- Multi-source configuration builder supporting JSON/XML/INI/TOML
|
||||
@@ -170,7 +170,8 @@ test/ # MSTest test projects
|
||||
**WPF Layer**:
|
||||
- Wpf → (no UI library dependency - pure MVVM)
|
||||
- Wpf.HandyControl → Wpf, HandyControl 3.5.0 (optional UI library integration)
|
||||
- Client → Wpf, Config, NetClient, NetServer, Log, Plc.Siemens, Ports, HandyControl
|
||||
- Wpf.DevTools → Wpf (Developer Tools: DevTools, LogViewer, Performance Monitor)
|
||||
- Sharp.Demo → Wpf, Wpf.HandyControl, Wpf.DevTools, Config, NetClient, NetServer, Log, Data, Plc.Siemens, Ports, Process, Python
|
||||
|
||||
**Industrial IoT**:
|
||||
- Ports → (serial port communication)
|
||||
@@ -250,19 +251,21 @@ var config = ConfigBuilder.CreateDefault().Configuration;
|
||||
4. Register with DI: `services.AddSingleton(cfg)` and `services.AddSingleton(cfg.Configuration)`
|
||||
5. Use hot-reload callbacks: `cfg.OnReload(() => { /* refresh */ })`
|
||||
|
||||
### WPF Client startup flow (Modern Quick Start)
|
||||
### WPF Sharp.Demo startup flow (Modern Quick Start)
|
||||
```csharp
|
||||
protected override void OnStartup(StartupEventArgs e) {
|
||||
var services = new ServiceCollection();
|
||||
var config = ConfigBuilder.CreateDefault().Configuration;
|
||||
var config = ConfigBuilderExtensions.CreateDefault().Configuration;
|
||||
|
||||
services.AddSharpEssentials(config);
|
||||
services.AddSharpWpf();
|
||||
services.AddViewModel<MainViewModel>();
|
||||
services.AddTransient<MainWindow>();
|
||||
services.AddSharpHandyControl();
|
||||
services.AddSharpDevTools();
|
||||
services.AddViewModel<LauncherViewModel>();
|
||||
services.AddTransient<LauncherWindow>();
|
||||
|
||||
var provider = services.BuildServiceProvider();
|
||||
provider.GetRequiredService<MainWindow>().Show();
|
||||
provider.GetRequiredService<LauncherWindow>().Show();
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
# HTTP 服务器测试指南
|
||||
|
||||
## 问题修复总结
|
||||
|
||||
### 修复的问题
|
||||
|
||||
1. **端口不匹配**
|
||||
- 之前:服务器监听 8080,但客户端请求 5000
|
||||
- 现在:统一使用配置文件中的 8080 端口
|
||||
|
||||
2. **缺少控制器**
|
||||
- 之前:没有任何 HTTP 控制器,导致所有请求返回 404
|
||||
- 现在:添加了 `HealthController` 和 `DemoController`
|
||||
|
||||
3. **HandyControl 兼容性**
|
||||
- 之前:HandyControl 3.5.0 与 .NET 8 不兼容
|
||||
- 现在:升级到 HandyControl 3.5.1
|
||||
|
||||
## 测试步骤
|
||||
|
||||
### 1. 启动 Sharp.Demo 应用
|
||||
|
||||
```bash
|
||||
cd D:\yuanll\sharp-basic\src\Sharp\Sharp.Demo
|
||||
dotnet run
|
||||
```
|
||||
|
||||
### 2. 打开 HTTP 服务器窗口
|
||||
|
||||
在启动器中点击 "HTTP 服务器" 按钮
|
||||
|
||||
### 3. 启动服务器
|
||||
|
||||
点击 "启动服务器" 按钮,应该看到:
|
||||
- 状态变为 "运行中" (绿色)
|
||||
- 日志显示 "✅ 服务器已启动: http://localhost:8080"
|
||||
|
||||
### 4. 测试可用的 API 端点
|
||||
|
||||
#### 使用浏览器测试
|
||||
|
||||
打开浏览器访问以下地址:
|
||||
|
||||
- **健康检查**: http://localhost:8080/api/health
|
||||
- **详细健康检查**: http://localhost:8080/api/health/detailed
|
||||
- **Hello World**: http://localhost:8080/api/demo/hello
|
||||
- **服务器时间**: http://localhost:8080/api/demo/time
|
||||
|
||||
#### 使用 HTTP 客户端窗口测试
|
||||
|
||||
1. 打开 "HTTP 客户端" 窗口
|
||||
2. 默认 URL 已经设置为 `http://localhost:8080/api/health`
|
||||
3. 点击 "发送请求" 或 "测试本地服务器"
|
||||
4. 应该看到成功的响应:
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"status": "healthy",
|
||||
"timestamp": "2025-12-24T19:20:00",
|
||||
"version": "1.0.0",
|
||||
"server": "Sharp.Demo"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 使用 curl 测试
|
||||
|
||||
```bash
|
||||
# 健康检查
|
||||
curl http://localhost:8080/api/health
|
||||
|
||||
# POST 请求测试
|
||||
curl -X POST http://localhost:8080/api/demo/echo -H "Content-Type: application/json" -d "{\"test\": \"hello\"}"
|
||||
```
|
||||
|
||||
## 已注册的路由
|
||||
|
||||
| 方法 | 路径 | 描述 |
|
||||
|------|------|------|
|
||||
| GET | /api/health | 基本健康检查 |
|
||||
| GET | /api/health/detailed | 详细健康检查 |
|
||||
| GET | /api/demo/hello | Hello World 测试 |
|
||||
| GET | /api/demo/time | 获取服务器时间 |
|
||||
| POST | /api/demo/echo | Echo 测试(返回请求体) |
|
||||
|
||||
## 配置说明
|
||||
|
||||
服务器配置在 `appsettings.json` 中:
|
||||
|
||||
```json
|
||||
{
|
||||
"Server": {
|
||||
"Port": 8080,
|
||||
"Host": "localhost",
|
||||
"MaxConcurrentRequests": 100
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
可以修改端口和主机地址,重启服务器后生效。
|
||||
|
||||
## 故障排查
|
||||
|
||||
### 端口被占用
|
||||
|
||||
如果看到 "端口被占用" 错误:
|
||||
1. 修改 `appsettings.json` 中的端口号
|
||||
2. 重新启动应用
|
||||
|
||||
### 防火墙阻止
|
||||
|
||||
如果其他计算机无法访问:
|
||||
1. 检查 Windows 防火墙设置
|
||||
2. 确保允许 8080 端口的入站连接
|
||||
|
||||
### 客户端连接失败
|
||||
|
||||
确认:
|
||||
1. 服务器确实已启动(状态为"运行中")
|
||||
2. URL 端口号正确(8080)
|
||||
3. 使用的是 `localhost` 或 `127.0.0.1`
|
||||
@@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.13.35931.197
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "Client\Client.csproj", "{5979868C-C09D-4B3F-8909-C661F94EFFBE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common\Common.csproj", "{EF054B5F-5D65-4917-B2D7-A85FA2719128}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Config", "Config\Config.csproj", "{37FBE4C9-1658-4953-8D12-71068EE28804}"
|
||||
@@ -29,8 +27,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Log.Test", "..\..\test\Log.
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetServer.Test", "..\..\test\NetServer.Test\NetServer.Test.csproj", "{020997C0-FB5F-4222-8620-818840EF4447}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{C2505AD1-D775-4881-A56F-42BDB7CDE58D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Data", "Data\Data.csproj", "{D4FAD87A-D436-4F66-8A7F-B57DD130E966}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Data.Test", "..\..\test\Data.Test\Data.Test.csproj", "{8EEC8BF4-CF9A-473D-B7A0-005E151C645D}"
|
||||
@@ -63,18 +59,6 @@ Global
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{5979868C-C09D-4B3F-8909-C661F94EFFBE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5979868C-C09D-4B3F-8909-C661F94EFFBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5979868C-C09D-4B3F-8909-C661F94EFFBE}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{5979868C-C09D-4B3F-8909-C661F94EFFBE}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{5979868C-C09D-4B3F-8909-C661F94EFFBE}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{5979868C-C09D-4B3F-8909-C661F94EFFBE}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{5979868C-C09D-4B3F-8909-C661F94EFFBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5979868C-C09D-4B3F-8909-C661F94EFFBE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5979868C-C09D-4B3F-8909-C661F94EFFBE}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{5979868C-C09D-4B3F-8909-C661F94EFFBE}.Release|x64.Build.0 = Release|Any CPU
|
||||
{5979868C-C09D-4B3F-8909-C661F94EFFBE}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{5979868C-C09D-4B3F-8909-C661F94EFFBE}.Release|x86.Build.0 = Release|Any CPU
|
||||
{EF054B5F-5D65-4917-B2D7-A85FA2719128}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EF054B5F-5D65-4917-B2D7-A85FA2719128}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EF054B5F-5D65-4917-B2D7-A85FA2719128}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
@@ -219,18 +203,6 @@ Global
|
||||
{020997C0-FB5F-4222-8620-818840EF4447}.Release|x64.Build.0 = Release|Any CPU
|
||||
{020997C0-FB5F-4222-8620-818840EF4447}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{020997C0-FB5F-4222-8620-818840EF4447}.Release|x86.Build.0 = Release|Any CPU
|
||||
{C2505AD1-D775-4881-A56F-42BDB7CDE58D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C2505AD1-D775-4881-A56F-42BDB7CDE58D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C2505AD1-D775-4881-A56F-42BDB7CDE58D}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{C2505AD1-D775-4881-A56F-42BDB7CDE58D}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{C2505AD1-D775-4881-A56F-42BDB7CDE58D}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{C2505AD1-D775-4881-A56F-42BDB7CDE58D}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{C2505AD1-D775-4881-A56F-42BDB7CDE58D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C2505AD1-D775-4881-A56F-42BDB7CDE58D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C2505AD1-D775-4881-A56F-42BDB7CDE58D}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{C2505AD1-D775-4881-A56F-42BDB7CDE58D}.Release|x64.Build.0 = Release|Any CPU
|
||||
{C2505AD1-D775-4881-A56F-42BDB7CDE58D}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{C2505AD1-D775-4881-A56F-42BDB7CDE58D}.Release|x86.Build.0 = Release|Any CPU
|
||||
{D4FAD87A-D436-4F66-8A7F-B57DD130E966}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D4FAD87A-D436-4F66-8A7F-B57DD130E966}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D4FAD87A-D436-4F66-8A7F-B57DD130E966}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
|
||||
Reference in new issue
Block a user