阶段性批量提交
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using SHH.CameraDashboard.Services;
|
||||
using SHH.ProcessLaunchers;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
|
||||
namespace SHH.CameraDashboard
|
||||
@@ -8,10 +10,30 @@ namespace SHH.CameraDashboard
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
#region 定义全局单例
|
||||
|
||||
/// <summary>
|
||||
/// 进程管理器
|
||||
/// </summary>
|
||||
public static ProcessManager ProcManager { get; private set; }
|
||||
= new ProcessManager(new ProcessDashboardLogger());
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
protected override async void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
|
||||
// 启动视频流接收 (Port 6002)
|
||||
StreamReceiverService.Instance.Start(6002);
|
||||
|
||||
// 启动指令服务 (Port 6001)
|
||||
CommandServer.Instance.Start(6001);
|
||||
|
||||
|
||||
// 现在我们来配置启动
|
||||
|
||||
// 1. 【核心代码】程序启动时,异步读取配置文件
|
||||
var savedNodes = await LocalStorageService.LoadAsync<ObservableCollection<ServiceNodeModel>>(AppPaths.ServiceNodesConfig);
|
||||
if (savedNodes != null)
|
||||
@@ -20,6 +42,43 @@ namespace SHH.CameraDashboard
|
||||
AppGlobal.ServiceNodes.Add(node);
|
||||
}
|
||||
|
||||
// =========================================================
|
||||
// 3. 构建启动参数 & 注册进程
|
||||
// =========================================================
|
||||
|
||||
// A. 获取当前 Dashboard 的 PID (用于父进程守护)
|
||||
int myPid = System.Environment.ProcessId;
|
||||
|
||||
// B. 构建参数字符串
|
||||
// --pid: 让 Service 知道谁是父进程
|
||||
// --uris: 告诉 Service 反向连接的目标 (注意顺序:视频端口, 指令端口)
|
||||
// --mode: 1 (主动连接模式)
|
||||
// --ports: Service 自身的 WebAPI 端口 (5005)
|
||||
string serviceArgs = $"" +
|
||||
$"--pid {myPid} " +
|
||||
$"--appid \"CameraApp_01\" " +
|
||||
$"--uris \"127.0.0.1,6002&6001;\" " +
|
||||
$"--mode 1 " +
|
||||
$"--ports \"5000,100\"";
|
||||
|
||||
// C. 注册进程配置 (复用 ProcManager)
|
||||
ProcManager.Register(new ProcessConfig
|
||||
{
|
||||
Id = "CameraService", // 内部标识
|
||||
DisplayName = "视频接入服务", // UI显示名称
|
||||
// 请确保路径正确,建议用相对路径 AppDomain.CurrentDomain.BaseDirectory + "SHH.CameraService.exe"
|
||||
ExePath = @"D:\Codes\Ayay\SHH.CameraService\bin\Debug\net8.0\SHH.CameraService.exe",
|
||||
Arguments = serviceArgs, // ★★★ 核心:注入参数 ★★★
|
||||
StartupOrder = 1, // 优先级
|
||||
RestartDelayMs = 2000, // 崩溃后2秒重启
|
||||
Visible = false // 不显示黑框
|
||||
});
|
||||
|
||||
// =========================================================
|
||||
// 4. 发射!启动所有注册的进程
|
||||
// =========================================================
|
||||
_ = ProcManager.StartAllAsync();
|
||||
|
||||
// 3. 启动主窗口
|
||||
// 注意:如果 LoadAsync 耗时较长,这里可能会导致启动画面停留,
|
||||
// 实际项目中可以搞一个 Splash Screen (启动屏) 来做这件事。
|
||||
@@ -35,7 +94,13 @@ namespace SHH.CameraDashboard
|
||||
// 1. 这里可以处理统一的资源清理逻辑 (如停止摄像头推流、关闭数据库连接)
|
||||
// 2. 保存用户配置
|
||||
// 3. 彻底退出
|
||||
StreamReceiverService.Instance.Dispose();
|
||||
CommandServer.Instance.Dispose();
|
||||
// 停止所有子进程
|
||||
ProcManager.StopAll();
|
||||
|
||||
Current.Shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user