| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- using ivf_tl_Operate.View;
- using ivf_tl_Operate.ViewModel;
- using ivf_tl_Operate.Windows;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace ivf_tl_Operate
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- //DisableWPFTabletSupport();
- Loaded += MainWindow_Loaded;
- // M4-01-1:自适应竖屏框架。原仅 #if DEBUG 才用 Viewbox 等比缩放,
- // 导致 Release 无缩放、换分辨率必错位。此处去掉条件编译,让 Viewbox
- // 在所有配置(含 Release)生效:MainGrid → Viewbox(Stretch=Uniform,等比保竖屏比例) → 窗口内容。
- // 窗口尺寸由 WindowState=Maximized 铺满实际屏幕,不再硬编码 1824×2736(已删 .xaml 写死 Width/Height)。
- // [D6] 最终是否需 Stretch=Fill 或切真弹性布局、设计基准分辨率取值依赖 Surface 真机,登记待验证。
- Grid originalCanvas = MainGrid;
- this.Content = null;
- Viewbox viewbox = new Viewbox
- {
- Child = originalCanvas,
- Stretch = Stretch.Uniform
- };
- this.Content = viewbox;
- }
- private void MainWindow_Loaded(object sender, RoutedEventArgs e)
- {
- var a = new LoginWindow(this).ShowDialog();
- if (a != true)
- {
- this.Close();
- return;
- }
- AppData.Instance.MainWindow = this;
- MainPageViewModel mainPageViewModel = new MainPageViewModel(AppData.Instance.TlSn);
- MainPageView mainPageView = new MainPageView();
- mainPageView.DataContext = mainPageViewModel;
- AppData.Instance.MainPageView = mainPageView;
- LoadPage(mainPageView);
- // M1-01 步骤3:operate 登录成功后,在后台线程托管 control 的 StartMain.StartRun()。
- // StartRun 内部阻塞(AppData.StartAsync().Wait()),必须放后台线程避免卡 UI。
- // 复刻原 control Window1_Loaded1 的 Task.Run 形态,但去掉 Environment.Exit(0)——
- // 合并后 control 后台启动失败不应杀掉前台 operate 进程,改为捕获异常 + 记录日志降级。
- System.Threading.Tasks.Task.Run(() =>
- {
- try
- {
- // M1-02 步骤2:单登录账号透传。
- // 合并后只保留 operate 的 LoginWindow,control 的 Window1 登录窗已从启动路径剔除。
- // 把 operate 登录成功后保存的账号/密码(AppData.Instance.CurrentUserInfo)
- // 透传给 control 的 AppData.Login,使 control 后台用同一账号工作,不再弹独立登录窗。
- // 复刻原 control Window1_Loaded1(Window1.xaml.cs:51-87)里 StartRun 之前的前置:
- // ① ivf_tl_Control.AppData.Instance.Login(account, password)
- // ② PathHelper.pan / LogService.Pan = cacheDisk(缓存盘,仍从 control 侧 config 读,配置统一属 M5)
- // 去掉原 Window1 里的 Environment.Exit(0):合并后 control 登录/启动失败不杀前台进程,仅记日志降级。
- string account = AppData.Instance.CurrentUserInfo.account;
- string password = AppData.Instance.CurrentUserInfo.password;
- if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password))
- {
- ivf_tl_Services.Log4netHelper.WriteLog("control 后台启动跳过:operate 登录账号/密码为空");
- return;
- }
- // ① control 端登录(与 operate 同一账号)。失败仅记日志、不退进程(V-012 真机验证)。
- if (!ivf_tl_Control.AppData.Instance.Login(account, password))
- {
- ivf_tl_Services.Log4netHelper.WriteLog("control 后台登录失败:单登录账号透传未通过 control 端 AppData.Login");
- return;
- }
- // ② 缓存盘:沿用 control 原 config 项 cacheDisk(StartRun 内随后会用服务器 tmpDir 覆盖 PathHelper.pan)。
- string cacheDisk = System.Configuration.ConfigurationManager.AppSettings["cacheDisk"];
- if (!string.IsNullOrEmpty(cacheDisk))
- {
- ivf_tl_UtilHelper.PathHelper.pan = cacheDisk;
- ivf_tl_Control.AppData.Instance.LogService.Pan = cacheDisk;
- }
- var startMain = new ivf_tl_Control.StartMain(); // 已并入的 control 类库
- // M1-03 步骤3:HAL 单例在 control StartRun 之前初始化一次(设备发现),
- // 确保后台采集与前台调试拿到的是同一组句柄(同 COM 口/同相机唯一持有)。
- // ⚠ 待验证 V-027:HAL.ScanDevices 设备发现稳定(相机index/COM漂移、CCDSN配对)。
- try
- {
- IvfTl.Hardware.Impl.HardwareAccessLayer.Instance.Log =
- msg => ivf_tl_Services.Log4netHelper.WriteLog(msg);
- var devices = IvfTl.Hardware.Impl.HardwareAccessLayer.Instance.ScanDevices();
- ivf_tl_Services.Log4netHelper.WriteLog($"HAL 设备发现完成:发现 {devices.Count} 个舱");
- }
- catch (Exception hex)
- {
- // HAL 发现失败不阻断 control 启动(control 自身仍会枚举),仅记日志降级。
- ivf_tl_Services.Log4netHelper.WriteLog("HAL 设备发现异常(降级)", hex);
- }
- string err = startMain.StartRun(); // 阻塞跑 InitTL→InitHouse→StartAsync
- if (!string.IsNullOrEmpty(err))
- ivf_tl_Services.Log4netHelper.WriteLog($"control 后台启动失败:{err}");
- else
- ivf_tl_Services.Log4netHelper.WriteLog("control 后台启动成功");
- }
- catch (Exception ex)
- {
- // 不退进程:仅记录日志,前台 operate 继续可用(自愈策略属后续)。
- ivf_tl_Services.Log4netHelper.WriteLog("control 后台启动异常", ex);
- }
- });
- }
- public void LoadPage(UserControl t)
- {
- _container.Content = t;
- }
- /// <summary>
- /// 显示与隐藏遮罩层
- /// </summary>
- /// <param name="v"></param>
- public void Mark(bool v)
- {
- Application.Current.Dispatcher.Invoke(() =>
- {
- if (v == true)
- {
- this._mask.Visibility = Visibility.Visible;
- }
- else
- {
- this._mask.Visibility = Visibility.Hidden;
- }
- });
- }
- public void DisableWPFTabletSupport()
- {
- TabletDeviceCollection devices = System.Windows.Input.Tablet.TabletDevices;
- if (devices.Count > 0)
- {
- Type inputManagerType = typeof(System.Windows.Input.InputManager);
- object stylusLogic = inputManagerType.InvokeMember("StylusLogic", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, InputManager.Current, null);
- if (stylusLogic != null)
- {
- Type stylusLogicType = stylusLogic.GetType();
- while (devices.Count > 0)
- {
- stylusLogicType.InvokeMember("OnTabletRemoved",
- BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic,
- null, stylusLogic, new object[] { (uint)0 });
- }
- }
- }
- }
- }
- }
|