|
@@ -44,43 +44,14 @@ namespace IvfTl.ControlHost
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- // 4) 复刻 operate MainWindow 启动序(顺序不可变)。
|
|
|
|
|
- if (!AppData.Instance.Login(hostArgs.Account, hostArgs.Password))
|
|
|
|
|
- {
|
|
|
|
|
- Log4netHelper.WriteLog("ControlHost: control 登录失败");
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- if (!string.IsNullOrEmpty(hostArgs.CacheDisk))
|
|
|
|
|
- {
|
|
|
|
|
- ivf_tl_UtilHelper.PathHelper.pan = hostArgs.CacheDisk;
|
|
|
|
|
- AppData.Instance.LogService.Pan = hostArgs.CacheDisk;
|
|
|
|
|
- }
|
|
|
|
|
- try
|
|
|
|
|
- {
|
|
|
|
|
- IvfTl.Hardware.Impl.HardwareAccessLayer.Instance.Log =
|
|
|
|
|
- msg => Log4netHelper.WriteLog(msg);
|
|
|
|
|
- var devices = IvfTl.Hardware.Impl.HardwareAccessLayer.Instance.ScanDevices();
|
|
|
|
|
- Log4netHelper.WriteLog($"ControlHost: HAL 发现 {devices.Count} 个舱");
|
|
|
|
|
- }
|
|
|
|
|
- catch (Exception hex)
|
|
|
|
|
- {
|
|
|
|
|
- Log4netHelper.WriteLog("ControlHost: HAL 发现异常(降级):" + hex.Message);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- var startMain = new StartMain();
|
|
|
|
|
- string err = startMain.StartRun(); // 阻塞:InitTL→InitHouse→StartAsync
|
|
|
|
|
- if (!string.IsNullOrEmpty(err))
|
|
|
|
|
- Log4netHelper.WriteLog("ControlHost: control 启动失败:" + err);
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- _started = true;
|
|
|
|
|
- Log4netHelper.WriteLog("ControlHost: control 启动成功,常驻运行");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 4) 启动序放后台线程(复刻 operate MainWindow 的 Task.Run 形态):
|
|
|
|
|
+ // StartRun 内部会阻塞(InitTL 串口握手 + StartAsync().Wait()),不能占住主线程,
|
|
|
|
|
+ // 否则下面的 _exitEvent.Wait() 永不可达、阶段2 /shutdown 也无从优雅停。
|
|
|
|
|
+ // 主线程只负责驻留;HTTP 在独立 Task 上,采集起没起都能被 operate 探活。
|
|
|
|
|
+ System.Threading.Tasks.Task.Run(() => RunStartupSequence(hostArgs));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 5) 驻留:control 后台线程已起(LongRunning),主线程阻塞等退出信号。
|
|
|
|
|
|
|
+ // 5) 驻留:主线程阻塞等退出信号(阶段2 的 /shutdown 会 Set 此事件)。
|
|
|
_exitEvent = new ManualResetEventSlim(false);
|
|
_exitEvent = new ManualResetEventSlim(false);
|
|
|
_exitEvent.Wait();
|
|
_exitEvent.Wait();
|
|
|
return 0;
|
|
return 0;
|
|
@@ -97,6 +68,53 @@ namespace IvfTl.ControlHost
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// control 启动序(后台线程跑,复刻 operate MainWindow 顺序,顺序不可变):
|
|
|
|
|
+ /// Login → 设缓存盘 → HAL.ScanDevices → StartMain.StartRun。
|
|
|
|
|
+ /// 任一步失败仅记日志降级,不退进程(HTTP 仍存活,operate 可探活到"未就绪")。
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private static void RunStartupSequence(HostArgs hostArgs)
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!AppData.Instance.Login(hostArgs.Account, hostArgs.Password))
|
|
|
|
|
+ {
|
|
|
|
|
+ Log4netHelper.WriteLog("ControlHost: control 登录失败");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!string.IsNullOrEmpty(hostArgs.CacheDisk))
|
|
|
|
|
+ {
|
|
|
|
|
+ ivf_tl_UtilHelper.PathHelper.pan = hostArgs.CacheDisk;
|
|
|
|
|
+ AppData.Instance.LogService.Pan = hostArgs.CacheDisk;
|
|
|
|
|
+ }
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ IvfTl.Hardware.Impl.HardwareAccessLayer.Instance.Log =
|
|
|
|
|
+ msg => Log4netHelper.WriteLog(msg);
|
|
|
|
|
+ var devices = IvfTl.Hardware.Impl.HardwareAccessLayer.Instance.ScanDevices();
|
|
|
|
|
+ Log4netHelper.WriteLog($"ControlHost: HAL 发现 {devices.Count} 个舱");
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception hex)
|
|
|
|
|
+ {
|
|
|
|
|
+ Log4netHelper.WriteLog("ControlHost: HAL 发现异常(降级):" + hex.Message);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var startMain = new StartMain();
|
|
|
|
|
+ string err = startMain.StartRun(); // 阻塞:InitTL→InitHouse→StartAsync
|
|
|
|
|
+ if (!string.IsNullOrEmpty(err))
|
|
|
|
|
+ Log4netHelper.WriteLog("ControlHost: control 启动失败:" + err);
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ _started = true;
|
|
|
|
|
+ Log4netHelper.WriteLog("ControlHost: control 启动成功,常驻运行");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ Log4netHelper.WriteLog("ControlHost: 启动序异常(降级,HTTP 仍存活)", ex);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/// <summary>提供给 HTTP /status 的快照(阶段1:基础存活;阶段2 接 GetMonitorSnapshot 补全)。</summary>
|
|
/// <summary>提供给 HTTP /status 的快照(阶段1:基础存活;阶段2 接 GetMonitorSnapshot 补全)。</summary>
|
|
|
private static StatusDto BuildStatus()
|
|
private static StatusDto BuildStatus()
|
|
|
{
|
|
{
|