MainWindow.xaml.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. using Panuon.WPF.UI;
  2. using SWRIS.Core;
  3. using SWRIS.Dtos;
  4. using SWRIS.Enums;
  5. using SWRIS.Events;
  6. using SWRIS.Extensions;
  7. using SWRIS.Models;
  8. using SWRIS.Models.ViewModel;
  9. using SWRIS.Pages;
  10. using SWRIS.Repository;
  11. using System;
  12. using System.ComponentModel;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Speech.Synthesis;
  16. using System.Threading;
  17. using System.Threading.Tasks;
  18. using System.Windows;
  19. using System.Windows.Controls;
  20. using System.Windows.Markup;
  21. namespace SWRIS
  22. {
  23. /// <summary>
  24. /// MainWindow.xaml 的交互逻辑
  25. /// </summary>
  26. public partial class MainWindow : WindowX, IComponentConnector
  27. {
  28. private readonly SpeechSynthesizer speech;
  29. public MainViewModel MainView { get; set; }
  30. private readonly IRecordRepository _recordRepository;
  31. private readonly IAlarmRepository _alarmRepository;
  32. public MainWindow()
  33. {
  34. InitializeComponent();
  35. _recordRepository = new RecordRepository();
  36. _alarmRepository = new AlarmRepository();
  37. speech = new SpeechSynthesizer()
  38. {
  39. Rate = 1,
  40. Volume = 100
  41. };
  42. MainView = new MainViewModel()
  43. {
  44. AppName = App.Config.AppName,
  45. Version = App.Config.Version,
  46. Copyright = App.Config.Copyright,
  47. SwitchInstances = App.Config.SwitchInstances
  48. };
  49. Application.Current.MainWindow = this;
  50. App.TcpServer.ClientConnected += TcpServer_ClientConnected;
  51. App.TcpServer.ClientDisconnected += TcpServer_ClientDisconnected;
  52. App.TcpServer.AlarmDataReceived += TcpServer_AlarmDataReceived;
  53. App.TcpServer.DetectionDataReceived += TcpServer_DetectionDataReceived;
  54. App.TcpServer.RealTimeDataReceived += TcpServer_RealTimeDataReceived;
  55. App.TcpServer.FaultDataReceived += TcpServer_FaultDataReceived;
  56. App.TcpServer.DetectionRawDataReceived += TcpServer_DetectionRawDataReceived;
  57. App.TcpServer.DetectionRawDataResultReceived += TcpServer_DetectionRawDataResultReceived;
  58. App.TcpServer.DetectionStatusResultReceived += TcpServer_DetectionStatusResultReceived;
  59. App.TcpServer.DebugMessageReceived += TcpServer_DebugMessageReceived;
  60. App.TcpServer.HeartbeatReceived += TcpServer_HeartbeatReceived;
  61. App.TcpServer.UpgradedRequestResultReceived += TcpServer_UpgradedRequestResultReceived;
  62. App.Calibration.ConnectionStateChanged += Calibration_ConnectionStateChanged;
  63. App.Calibration.LimitStateChanged += Calibration_LimitStateChanged;
  64. App.TcpServer.Start();
  65. DataContext = MainView;
  66. }
  67. /// <summary>
  68. /// 接收心跳数据
  69. /// </summary>
  70. private void TcpServer_HeartbeatReceived(object sender, HeartbeatReceviedEventArgs e)
  71. {
  72. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  73. if (equipmentData != null)
  74. {
  75. equipmentData.IsHeartbeatReceived = true;
  76. }
  77. }
  78. /// <summary>
  79. /// 接收调试信息
  80. /// </summary>
  81. private void TcpServer_DebugMessageReceived(object sender, DebugMessageReceivedEventArgs e)
  82. {
  83. if (e.IpAddress.IsNullOrEmpty() && e.SerialNo.IsNullOrEmpty())
  84. {
  85. DebugMessageShow(e.Message);
  86. }
  87. else
  88. {
  89. DebugMessageShow(e.Message, e.IpAddress, e.SerialNo);
  90. }
  91. }
  92. public void DebugMessageShow(string message, string ipAddress, string serialNo)
  93. {
  94. if (App.Config.ShowDebugMessage)
  95. {
  96. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == ipAddress || (serialNo != null && c.SerialNo == serialNo));
  97. if (equipmentData != null)
  98. {
  99. equipmentData.DebugMessage.DateTime = DateTime.Now;
  100. equipmentData.DebugMessage.Message = message;
  101. }
  102. }
  103. }
  104. public void DebugMessageShow(string message)
  105. {
  106. if (App.Config.ShowDebugMessage)
  107. {
  108. MainView.DebugMessage.DateTime = DateTime.Now;
  109. MainView.DebugMessage.Message = message;
  110. }
  111. }
  112. /// <summary>
  113. /// 标定限位状态更改
  114. /// </summary>
  115. private void Calibration_LimitStateChanged(object sender, LimitData limitData)
  116. {
  117. foreach (var equipment in App.DataCenter.Equipments)
  118. {
  119. foreach (var limit in equipment.Limits)
  120. {
  121. if (limit.Name == limitData.Name && limit.IsEnable)
  122. {
  123. if (limitData.State == LimitState.AtLimit)
  124. {
  125. limit.State = LimitState.AtLimit;
  126. // 当前运行状态添加预标定状态
  127. equipment.RunningStatus |= RunningStatus.PreCalibration;
  128. if (App.TcpServer.SendRealTimeAbsolutePositionData((float)limitData.Position, equipment.SerialNo, equipment.ClientSocket))
  129. {
  130. DebugMessageShow($"{limitData.Name}标定成功", equipment.IpAddress, equipment.SerialNo);
  131. }
  132. }
  133. else if (limitData.State == LimitState.NotInLimit)
  134. {
  135. limit.State = LimitState.NotInLimit;
  136. }
  137. }
  138. }
  139. }
  140. }
  141. /// <summary>
  142. /// 标定模块连接状态更改
  143. /// </summary>
  144. private void Calibration_ConnectionStateChanged(object sender, bool isConnect)
  145. {
  146. foreach (var equipment in App.DataCenter.Equipments)
  147. {
  148. foreach (var limit in equipment.Limits)
  149. {
  150. if (isConnect)
  151. {
  152. if (limit.State == LimitState.Offline)
  153. {
  154. limit.State = LimitState.NotInLimit;
  155. }
  156. }
  157. else
  158. {
  159. if (limit.State != LimitState.Offline)
  160. {
  161. limit.State = LimitState.Offline;
  162. }
  163. }
  164. }
  165. }
  166. }
  167. /// <summary>
  168. /// 接收检测状态开关结果
  169. /// </summary>
  170. private void TcpServer_DetectionStatusResultReceived(object sender, DetectionStatusResultReceivedEventArgs e)
  171. {
  172. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  173. if (equipmentData != null)
  174. {
  175. if (equipmentData.RunningStatus.HasFlag(RunningStatus.PreStop))
  176. {
  177. equipmentData.RunningStatus = RunningStatus.Stopped;
  178. Application.Current.Dispatcher.Invoke(() =>
  179. {
  180. NoticeBox.Show("自动检测停止", "通知", MessageBoxIcon.Warning, true, 3000);
  181. });
  182. }
  183. else if (equipmentData.RunningStatus.HasFlag(RunningStatus.PreRunning))
  184. {
  185. equipmentData.RunningStatus = RunningStatus.RunningNormal;
  186. Application.Current.Dispatcher.Invoke(() =>
  187. {
  188. NoticeBox.Show("自动检测恢复", "通知", MessageBoxIcon.Success, true, 3000);
  189. });
  190. }
  191. else if (equipmentData.RunningStatus.HasFlag(RunningStatus.PreCalibration))
  192. {
  193. equipmentData.RunningStatus = RunningStatus.RunningNormal;
  194. }
  195. }
  196. }
  197. /// <summary>
  198. /// 接收故障数据
  199. /// </summary>
  200. private void TcpServer_FaultDataReceived(object sender, FaultDataReceivedEventArgs e)
  201. {
  202. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  203. equipmentData?.Faults.Add(e.FaultData);
  204. }
  205. /// <summary>
  206. /// 接收实时数据
  207. /// </summary>
  208. private void TcpServer_RealTimeDataReceived(object sender, RealTimeDataReceivedEventArgs e)
  209. {
  210. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  211. if (equipmentData != null)
  212. {
  213. equipmentData.Speed = Math.Round(e.RealTimeData.Speed * 60, 2);
  214. equipmentData.Position = e.RealTimeData.Position;
  215. equipmentData.RunningStatus = e.RealTimeData.Status;
  216. equipmentData.AbsolutePosition = e.RealTimeData.AbsolutePosition;
  217. equipmentData.LiftHeight = (equipmentData.RopeLength - equipmentData.AbsolutePosition) / equipmentData.LiftHightRatio;
  218. equipmentData.Direction = equipmentData.Speed > 0 ? DirectionState.Forward :
  219. (equipmentData.Speed == 0f ? DirectionState.Stoped : DirectionState.Reverse);
  220. Console.WriteLine(equipmentData.AbsolutePosition);
  221. equipmentData.AddSpeedData(equipmentData.Speed);
  222. }
  223. }
  224. /// <summary>
  225. /// 客户端连接成功
  226. /// </summary>
  227. private void TcpServer_ClientConnected(object sender, ClientConnectedEventArgs e)
  228. {
  229. var equipment = App.Config.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  230. if (equipment == null)
  231. {
  232. LogHelper.Error($"未找到设备,IP地址:{e.IpAddress}");
  233. return;
  234. }
  235. var server = (TcpServerFrame)sender;
  236. server.SendTurnLiveStreamData(true, equipment.SerialNo, e.ClientSocket);
  237. Thread.Sleep(20);
  238. server.SendSetClockData(DateTime.Now.DateTimeToTimestamp(), equipment.SerialNo, e.ClientSocket);
  239. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  240. if (equipmentData != null)
  241. {
  242. equipmentData.IsConnect = true;
  243. equipmentData.ClientSocket = e.ClientSocket;
  244. if (equipmentData.RunningStatus != RunningStatus.RunningNormal)
  245. {
  246. equipmentData.RunningStatus |= RunningStatus.RunningNormal;
  247. }
  248. }
  249. }
  250. /// <summary>
  251. /// 客户端连接断开
  252. /// </summary>
  253. private void TcpServer_ClientDisconnected(object sender, ClientDisconnectedEventArgs e)
  254. {
  255. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  256. if (equipmentData != null)
  257. {
  258. equipmentData.IsConnect = false;
  259. equipmentData.ClientSocket = null;
  260. equipmentData.Speed = 0;
  261. equipmentData.AbsolutePosition = 0;
  262. equipmentData.Position = 0;
  263. equipmentData.Direction = DirectionState.Stoped;
  264. }
  265. }
  266. /// <summary>
  267. /// 接收检测结果
  268. /// </summary>
  269. private void TcpServer_DetectionDataReceived(object sender, DetectionDataReceivedEventArgs e)
  270. {
  271. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  272. if (equipmentData != null)
  273. {
  274. e.DetectionData.DetectionNo = equipmentData.DetectionNo;
  275. equipmentData.DetectionData = e.DetectionData;
  276. }
  277. }
  278. /// <summary>
  279. /// 接检测原始数据结果
  280. /// </summary>
  281. private void TcpServer_DetectionRawDataResultReceived(object sender, DetectionRawDataResultReceivedEventArgs e)
  282. {
  283. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  284. if (equipmentData != null)
  285. {
  286. // 处理检测原始结果数据
  287. if (e.DetectionRawResultData.Code == 0)
  288. {
  289. if (equipmentData.DetectionData != null)
  290. {
  291. equipmentData.DetectionData.RawResultData = e.DetectionRawResultData;
  292. }
  293. }
  294. else
  295. {
  296. LogHelper.Error($"获取检测原始数据失败,错误码:{e.DetectionRawResultData.Code}");
  297. }
  298. }
  299. }
  300. /// <summary>
  301. /// 接受检测结果原始数据
  302. /// </summary>
  303. private async void TcpServer_DetectionRawDataReceived(object sender, DetectionRawDataReceivedEventArgs e)
  304. {
  305. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  306. if (equipmentData != null)
  307. {
  308. if (equipmentData.DisableAlarm)
  309. {
  310. DebugMessageShow($"获取检测结果原始数据结束", equipmentData.IpAddress, equipmentData.SerialNo);
  311. return;
  312. }
  313. await Task.Run(() =>
  314. {
  315. if (equipmentData.DetectionData != null && equipmentData.DetectionData.RawResultData != null)
  316. {
  317. DebugMessageShow($"数据接收:{e.DetectionRawData.PacketNumber}/{e.DetectionRawData.TotalPackets}", equipmentData.IpAddress, equipmentData.SerialNo);
  318. if (e.DetectionRawData.PacketNumber == 1)
  319. {
  320. equipmentData.DetectionData.RawDataReceiving = true;
  321. equipmentData.DetectionData.RawData = new MemoryStream();
  322. equipmentData.DetectionData.RawData.Write(e.DetectionRawData.Data, 0, e.DetectionRawData.Data.Length);
  323. }
  324. else if (e.DetectionRawData.PacketNumber <= e.DetectionRawData.TotalPackets)
  325. {
  326. // 添加原始数据到检测数据中
  327. equipmentData.DetectionData.RawData.Write(e.DetectionRawData.Data, 0, e.DetectionRawData.Data.Length);
  328. // 如果是最后一包数据,处理检测数据
  329. if (e.DetectionRawData.PacketNumber == e.DetectionRawData.TotalPackets)
  330. {
  331. // 生成数据文件路径
  332. (string absolutePath, string relativePath) = DatFileHandler.GetDatFilePath(equipmentData.SerialNo);
  333. // 处理检测数据逻辑
  334. var record = new RecordDto
  335. {
  336. RopeName = equipmentData.RopeName,
  337. RopeNumber = equipmentData.RopeNumber,
  338. StartPoint = equipmentData.DetectionData.StartPoint,
  339. EndPoint = equipmentData.DetectionData.EndPoint,
  340. DetectedSpeed = equipmentData.DetectionData.DetectedSpeed,
  341. DetectionLength = equipmentData.DetectionData.DetectionLength,
  342. StartTime = equipmentData.DetectionData.StartTime.TimestampToDateTime(),
  343. EndTime = equipmentData.DetectionData.EndTime.TimestampToDateTime(),
  344. SensorCount = equipmentData.DetectionData.RawResultData.SensorCount,
  345. SamplingStep = equipmentData.DetectionData.RawResultData.SamplingStep,
  346. DataFilePath = relativePath,
  347. InUseSensors = string.Join(",", equipmentData.InUseSensor)
  348. };
  349. foreach (var damage in equipmentData.DetectionData.Damages)
  350. {
  351. var alarmCount = _alarmRepository.AddAlarm(new AlarmDataModel
  352. {
  353. DamageLevel = damage.DamageLevel,
  354. DamagePosition = damage.DamagePoint,
  355. DamageValue = damage.DamageValue,
  356. RopeNumber = equipmentData.RopeNumber
  357. }, AlarmSourceType.Detection, App.Config.DamageExtent);
  358. if (alarmCount >= App.Config.AlarmValidCount)
  359. {
  360. record.Damages.Add(new DamageDto
  361. {
  362. DamageLevel = damage.DamageLevel,
  363. DamagePoint = damage.DamagePoint,
  364. DamageValue = damage.DamageValue,
  365. });
  366. record.DamageCount++;
  367. //纠正健康度 以客户端上传的损伤数据 重新计算
  368. if ((int)record.RiskLevel < (int)damage.DamageLevel)
  369. {
  370. record.RiskLevel = (RiskLevel)damage.DamageLevel;
  371. }
  372. }
  373. }
  374. equipmentData.RiskLevel = record.RiskLevel;
  375. if (record.DamageCount > 0)
  376. {
  377. int? recordId = _recordRepository.CreateRecord(record);
  378. if (recordId.HasValue)
  379. {
  380. record.Id = recordId.Value;
  381. AddRecordToPageRecords(record);
  382. if (!DatFileHandler.CreateDatFile(absolutePath, equipmentData.DetectionData.RawData))
  383. {
  384. LogHelper.Error($"创建检测数据文件失败,路径:{absolutePath}");
  385. }
  386. DebugMessageShow($"检测数据记录成功", equipmentData.IpAddress, equipmentData.SerialNo);
  387. if ((int)record.RiskLevel >= (int)App.Config.SoundRiskLevel)
  388. {
  389. Application.Current.Dispatcher.Invoke(() =>
  390. {
  391. speech.SpeakAsync($"{equipmentData.RopeName},检测到{record.DamageCount}处损伤");
  392. });
  393. }
  394. }
  395. else
  396. {
  397. LogHelper.Error("检测数据记录失败");
  398. }
  399. }
  400. else
  401. {
  402. DebugMessageShow($"检测完成,未发现损伤,本次检测不做记录。", equipmentData.IpAddress, equipmentData.SerialNo);
  403. }
  404. equipmentData.DetectionData.RawDataReceiving = false;
  405. }
  406. }
  407. }
  408. });
  409. }
  410. }
  411. /// <summary>
  412. /// 接收报警数据
  413. /// </summary>
  414. private void TcpServer_AlarmDataReceived(object sender, AlarmDataReceivedEventArgs e)
  415. {
  416. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  417. if (equipmentData != null && equipmentData.IsSpeedStable && !equipmentData.DisableAlarm)
  418. {
  419. Dispatcher.InvokeAsync(() =>
  420. {
  421. e.AlarmData.RopeNumber = equipmentData.RopeNumber;
  422. var alarmCount = _alarmRepository.AddAlarm(e.AlarmData, AlarmSourceType.RealTime, App.Config.DamageExtent);
  423. if (alarmCount >= App.Config.AlarmValidCount)
  424. {
  425. equipmentData.AddAlarm(e.AlarmData);
  426. }
  427. });
  428. }
  429. }
  430. private void TcpServer_UpgradedRequestResultReceived(object sender, UpgradedResultReceivedEventArgs e)
  431. {
  432. Dispatcher.InvokeAsync(async () =>
  433. {
  434. if (e.Code == 0)
  435. {
  436. await Task.Delay(2000);
  437. string url = $"http://192.168.1.200"; // 替换为您的网页地址
  438. Extensions.Tools.OpenUrl(url);
  439. }
  440. });
  441. }
  442. public void AddRecordToPageRecords(RecordDto record)
  443. {
  444. Application.Current.Dispatcher.Invoke(() =>
  445. {
  446. if (main_frame.Content is Page currentPage && currentPage != null)
  447. {
  448. var simpleRecord = record.ToSimpleRecordDto();
  449. switch (currentPage.Title)
  450. {
  451. case "OneRopePage":
  452. if (currentPage.DataContext is OneRopeViewModel oneRopeView)
  453. {
  454. oneRopeView.AddRecord(simpleRecord);
  455. }
  456. break;
  457. case "TwoRopesPage":
  458. if (currentPage.DataContext is TwoRopesViewModel twoRopesView)
  459. {
  460. twoRopesView.AddRecord(simpleRecord);
  461. }
  462. break;
  463. case "ThreeRopesPage":
  464. if (currentPage.DataContext is ThreeRopesViewModel threeRopesView)
  465. {
  466. threeRopesView.AddRecord(simpleRecord);
  467. }
  468. break;
  469. case "FourRopesPage":
  470. if (currentPage.DataContext is FourRopesViewModel fourRopesView)
  471. {
  472. fourRopesView.AddRecord(simpleRecord);
  473. }
  474. break;
  475. }
  476. }
  477. });
  478. }
  479. private void WindowX_Loaded(object sender, RoutedEventArgs e)
  480. {
  481. NavigateToPage("Home");
  482. }
  483. public void NavigatePage(Uri uri)
  484. {
  485. main_frame.NavigationService.Navigate(uri);
  486. }
  487. private void NavigateToPage(object pageName)
  488. {
  489. switch (pageName)
  490. {
  491. case "Home":
  492. MainView.CurrentPage = "Home";
  493. int equipmentCount = App.Config.Equipments.Count;
  494. switch (equipmentCount)
  495. {
  496. case 1:
  497. main_frame.NavigationService.Navigate(new Uri($"Pages/RealTime/OneRopePage.xaml", uriKind: UriKind.Relative));
  498. break;
  499. case 2:
  500. main_frame.NavigationService.Navigate(new Uri($"Pages/RealTime/TwoRopesPage.xaml", uriKind: UriKind.Relative));
  501. break;
  502. case 3:
  503. main_frame.NavigationService.Navigate(new Uri($"Pages/RealTime/ThreeRopesPage.xaml", uriKind: UriKind.Relative));
  504. break;
  505. case 4:
  506. main_frame.NavigationService.Navigate(new Uri($"Pages/RealTime/FourRopesPage.xaml", uriKind: UriKind.Relative));
  507. break;
  508. }
  509. break;
  510. case "Record":
  511. MainView.CurrentPage = "Record";
  512. main_frame.NavigationService.Navigate(new Uri($"Pages/RecordPage.xaml", uriKind: UriKind.Relative));
  513. break;
  514. }
  515. }
  516. private void Menu_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  517. {
  518. if (sender is TextBlock menuItem)
  519. {
  520. CleanNavigation(main_frame);
  521. NavigateToPage(menuItem?.Tag);
  522. }
  523. }
  524. private void CleanNavigation(Frame frame)
  525. {
  526. while (frame.CanGoBack)
  527. frame.RemoveBackEntry();
  528. }
  529. private void StackPanel_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  530. {
  531. if (e.ClickCount == 2)
  532. {
  533. Left = 0;
  534. Top = 0;
  535. }
  536. }
  537. private void Setting_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  538. {
  539. SettingDialog settingDialog = new SettingDialog();
  540. if (settingDialog.ShowDialog(true) == true)
  541. {
  542. if (settingDialog.IsAutoStart)
  543. {
  544. App.RestartApplication();
  545. }
  546. }
  547. }
  548. private void Window_Closing(object sender, CancelEventArgs e)
  549. {
  550. App.TcpServer?.Dispose();
  551. speech?.Dispose();
  552. }
  553. private void Minimize_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  554. {
  555. WindowState = WindowState.Minimized;
  556. }
  557. private void Close_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  558. {
  559. var result = MessageBoxX.Show(this, "退出后将无法进行实时检测,是否确认退出程序?", "警告",
  560. MessageBoxButton.YesNo,
  561. MessageBoxIcon.Warning, DefaultButton.YesOK);
  562. if (result == MessageBoxResult.Yes)
  563. {
  564. Close();
  565. }
  566. }
  567. private void SwitchToInstance_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  568. {
  569. if (sender is Border instanceBorder && instanceBorder.Tag != null)
  570. {
  571. App.SwitchToExistingInstance(instanceBorder.Tag.ToString());
  572. }
  573. }
  574. }
  575. }