终端一体化运控平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

215 righe
7.9 KiB

  1. using BPASmartClient.Business;
  2. using BPASmartClient.CustomResource.UserControls;
  3. using BPASmartClient.CustomResource.UserControls.MessageShow;
  4. using BPASmartClient.Device;
  5. using BPASmartClient.Helper;
  6. using BPASmartClient.IoT;
  7. using BPASmartClient.Message;
  8. using BPASmartClient.Peripheral;
  9. using BPASmartClient.ViewModel;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Reflection;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Data;
  20. using System.Windows.Documents;
  21. using System.Windows.Input;
  22. using System.Windows.Media;
  23. using System.Windows.Media.Imaging;
  24. using System.Windows.Navigation;
  25. using System.Windows.Shapes;
  26. namespace BPASmartClient.MilkWithTea
  27. {
  28. /// <summary>
  29. /// Interaction logic for MainWindow.xaml
  30. /// </summary>
  31. public partial class MainWindow : Window
  32. {
  33. public MainConsole mainConsole;
  34. public MainWindow()
  35. {
  36. InitializeComponent();
  37. Initialize();
  38. }
  39. private void Initialize()
  40. {
  41. ThreadManage.GetInstance().Start(new Action(() =>
  42. {
  43. GetDevices();
  44. mainConsole = new MainConsole();
  45. mainConsole.Start();
  46. }), "启动主控制台", false);
  47. ActionManage.GetInstance.Register(new Action(() =>
  48. {
  49. ThreadManage.GetInstance().Start(new Action(() =>
  50. {
  51. try
  52. {
  53. DataVClient.GetInstance().Initialize();
  54. DataVClient.GetInstance().Start();
  55. }
  56. catch (Exception ex)
  57. {
  58. MessageLog.GetInstance.ShowEx(ex.ToString());
  59. }
  60. }), "启动主IoT", false);
  61. }), "配置初始化完成Iot启动");
  62. ActionManage.GetInstance.Register(new Action<object>((o) =>
  63. {
  64. App.Current.Dispatcher.Invoke(new Action(() =>
  65. {
  66. if (o is IOTCommandModel iot)
  67. {
  68. switch (iot.CommandName)
  69. {
  70. case 0://控制类
  71. if (iot.CommandValue != null && iot.CommandValue.Count > 0)
  72. {
  73. switch (iot.CommandValue.Keys.ToList()[0])
  74. {
  75. case "程序启动":
  76. //mainConsole.Start();
  77. break;
  78. //mainConsole.Stop();
  79. case "程序停止":
  80. break;
  81. case "程序复位":
  82. //mainConsole.Stop();
  83. //mainConsole.Start();
  84. break;
  85. default:
  86. break;
  87. }
  88. NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "大屏控制", iot.CommandValue.Keys.ToList()[0]);
  89. }
  90. break;
  91. case 1://设置类
  92. break;
  93. case 2://通知类
  94. if (iot.CommandValue != null && iot.CommandValue.ContainsKey("text"))
  95. {
  96. NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "大屏通知", iot.CommandValue["text"]);
  97. }
  98. break;
  99. default:
  100. break;
  101. }
  102. }
  103. }));
  104. }), "IotBroadcast");
  105. NavButton_Click(new Button() { Tag = "MainControlView" },null);
  106. }
  107. /// <summary>
  108. /// 获取设备集合
  109. /// </summary>
  110. private void GetDevices()
  111. {
  112. //List<string> IDevices = new List<string>();
  113. //List<string> IPeripherals = new List<string>();
  114. DirectoryInfo directoryInfo = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
  115. var files = directoryInfo.GetFiles().Where(p => p.FullName.Contains("BPASmartClient.") && p.FullName.Contains("dll")).ToList();
  116. List<string> fileList = new List<string>();
  117. var assemblies = AppDomain.CurrentDomain.GetAssemblies();
  118. var dlls = assemblies?.Where(p => p.FullName.Contains("BPASmartClient.")).ToList();
  119. List<string> dllList = new List<string>();
  120. if (files != null)
  121. {
  122. foreach (var item in files)
  123. {
  124. var res = System.IO.Path.GetFileNameWithoutExtension(item.FullName);
  125. if (res != null && res.Length > 0 && res.Contains(".") && !res.Contains("dll")) fileList.Add(res);
  126. }
  127. }
  128. if (dlls != null)
  129. {
  130. dlls.ForEach((item) =>
  131. {
  132. item.GetTypes().ToList().ForEach((type) =>
  133. {
  134. if (type.GetInterfaces().Contains(typeof(IDevice)))
  135. {
  136. if (!type.FullName.Contains("BaseDevice")) ShopDeviceConfigViewModel.IDevices.Add(type.FullName);
  137. }
  138. else if (type.GetInterfaces().Contains(typeof(IPeripheral)))
  139. {
  140. if (!type.FullName.Contains("BasePeripheral")) ShopDeviceConfigViewModel.IPeripherals.Add(type.FullName);
  141. }
  142. });
  143. dllList.Add(System.IO.Path.GetFileNameWithoutExtension(item.EscapedCodeBase));
  144. });
  145. }
  146. dllList.ForEach((item) => { if (fileList.Contains(item)) fileList.Remove(item); });
  147. fileList.ForEach((item) =>
  148. {
  149. Assembly.Load(item).GetTypes().ToList().ForEach((type) =>
  150. {
  151. if (type.GetInterfaces().Contains(typeof(IDevice)))
  152. {
  153. if (!type.FullName.Contains("BaseDevice")) ShopDeviceConfigViewModel.IDevices.Add(type.FullName);
  154. }
  155. else if (type.GetInterfaces().Contains(typeof(IPeripheral)))
  156. {
  157. if (!type.FullName.Contains("BasePeripheral")) ShopDeviceConfigViewModel.IPeripherals.Add(type.FullName);
  158. }
  159. });
  160. });
  161. }
  162. private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
  163. {
  164. this.DragMove();
  165. }
  166. private void CloseButton_Click(object sender, RoutedEventArgs e)
  167. {
  168. this.Close();
  169. }
  170. private void NavButton_Click(object sender, RoutedEventArgs e)
  171. {
  172. try
  173. {
  174. if (sender is Button bt )
  175. {
  176. Type type = Type.GetType($"BPASmartClient.MilkWithTea.View.{bt.Tag?.ToString()}");
  177. ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes);
  178. contentRegion.Content = (FrameworkElement)cti.Invoke(null);
  179. }
  180. }
  181. catch (Exception ex)
  182. {
  183. MessageLog.GetInstance.ShowEx($"BPASmartClient 中引发错误,MainWindow.xaml.cs 类MenuItem_Click(),描述:[{ex.Message}]");
  184. }
  185. }
  186. }
  187. }