终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MainWindow.xaml.cs 12 KiB

2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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 Newtonsoft.Json;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Reflection;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using System.Windows;
  19. using System.Windows.Controls;
  20. using System.Windows.Data;
  21. using System.Windows.Documents;
  22. using System.Windows.Input;
  23. using System.Windows.Media;
  24. using System.Windows.Media.Animation;
  25. using System.Windows.Media.Imaging;
  26. using System.Windows.Navigation;
  27. using System.Windows.Shapes;
  28. namespace BPASmartClient.MilkWithTea
  29. {
  30. /// <summary>
  31. /// Interaction logic for MainWindow.xaml
  32. /// </summary>
  33. public partial class MainWindow : Window
  34. {
  35. public MainConsole mainConsole;
  36. public MainWindow()
  37. {
  38. InitializeComponent();
  39. TextHelper.GetInstance.WriteTextInfo("MOC", "StartShop", "DeviceConfig");
  40. CreateDevice();
  41. //Initialize();
  42. }
  43. Storyboard sb = new Storyboard();
  44. DoubleAnimation yd1 = new DoubleAnimation();//实例化浮点动画
  45. DoubleAnimation yd2 = new DoubleAnimation();
  46. private void CreateDevice()
  47. {
  48. DirectoryInfo directoryInfo = new DirectoryInfo(LocaPath.GetInstance().GetDeviceConfigPath);
  49. if(!File.Exists($"{directoryInfo}Moc.json"))
  50. {
  51. File.WriteAllText($"{directoryInfo}Moc.json", JsonConvert.SerializeObject(GLobal.deviceConfig));
  52. }
  53. string JsonString = File.ReadAllText($"{directoryInfo}MOC.json");
  54. var result = JsonConvert.DeserializeObject<ObservableCollection<DeviceConfigModelJson>>(JsonString);
  55. if (result != null)
  56. {
  57. ShopDeviceConfigViewModel.deviceConfig.Clear();
  58. foreach (var item in result)
  59. {
  60. GLobal.deviceConfig.Add(item);
  61. }
  62. }
  63. if(GLobal.deviceConfig.Count <1)
  64. {
  65. GLobal.deviceConfig.Add(new DeviceConfigModelJson());
  66. if(GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.Count <1)
  67. {
  68. GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.Add(new DeviceModel());
  69. if(GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAtOrDefault(0).communicationDevcies.Count <1)
  70. {
  71. GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAtOrDefault(0).communicationDevcies.Add(new CommunicationModel());
  72. }
  73. }
  74. }
  75. if (GLobal.deviceConfig.ElementAt(0).deviceModels.ElementAt(0).communicationDevcies.ElementAt(0).variables.Count < 1)
  76. {
  77. for (int i = 0; i < 20; i++)
  78. {
  79. GLobal.deviceConfig.ElementAt(0).deviceModels.ElementAt(0).communicationDevcies.ElementAt(0).variables.Add(new Variable()
  80. {
  81. Id = GLobal.deviceConfig.ElementAt(0).deviceModels.ElementAt(0).communicationDevcies.ElementAt(0).variables.Count,
  82. Address = string.Empty,
  83. ReadLeng = 0
  84. });
  85. }
  86. File.WriteAllText($"{LocaPath.GetInstance().GetDeviceConfigPath}MOC.json", JsonConvert.SerializeObject(GLobal.deviceConfig));
  87. }
  88. }
  89. private void Initialize()
  90. {
  91. ThreadManage.GetInstance().Start(new Action(() =>
  92. {
  93. GetDevices();
  94. mainConsole = new MainConsole();
  95. mainConsole.Start();
  96. }), "启动主控制台", false);
  97. ActionManage.GetInstance.Register(new Action(() =>
  98. {
  99. ThreadManage.GetInstance().Start(new Action(() =>
  100. {
  101. try
  102. {
  103. DataVClient.GetInstance().Initialize();
  104. DataVClient.GetInstance().Start();
  105. }
  106. catch (Exception ex)
  107. {
  108. MessageLog.GetInstance.ShowEx(ex.ToString());
  109. }
  110. }), "启动主IoT", false);
  111. }), "配置初始化完成Iot启动");
  112. ActionManage.GetInstance.Register(new Action<object>((o) =>
  113. {
  114. App.Current.Dispatcher.Invoke(new Action(() =>
  115. {
  116. if (o is IOTCommandModel iot)
  117. {
  118. switch (iot.CommandName)
  119. {
  120. case 0://控制类
  121. if (iot.CommandValue != null && iot.CommandValue.Count > 0)
  122. {
  123. switch (iot.CommandValue.Keys.ToList()[0])
  124. {
  125. case "程序启动":
  126. //mainConsole.Start();
  127. break;
  128. //mainConsole.Stop();
  129. case "程序停止":
  130. break;
  131. case "程序复位":
  132. //mainConsole.Stop();
  133. //mainConsole.Start();
  134. break;
  135. default:
  136. break;
  137. }
  138. NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "大屏控制", iot.CommandValue.Keys.ToList()[0]);
  139. }
  140. break;
  141. case 1://设置类
  142. break;
  143. case 2://通知类
  144. if (iot.CommandValue != null && iot.CommandValue.ContainsKey("text"))
  145. {
  146. NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "大屏通知", iot.CommandValue["text"]);
  147. }
  148. break;
  149. default:
  150. break;
  151. }
  152. }
  153. }));
  154. }), "IotBroadcast");
  155. NavButton_Click(new Button() { Tag = "MainControlView" },null);
  156. }
  157. /// <summary>
  158. /// 获取设备集合
  159. /// </summary>
  160. private void GetDevices()
  161. {
  162. //List<string> IDevices = new List<string>();
  163. //List<string> IPeripherals = new List<string>();
  164. DirectoryInfo directoryInfo = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
  165. var files = directoryInfo.GetFiles().Where(p => p.FullName.Contains("BPASmartClient.") && p.FullName.Contains("dll")).ToList();
  166. List<string> fileList = new List<string>();
  167. var assemblies = AppDomain.CurrentDomain.GetAssemblies();
  168. var dlls = assemblies?.Where(p => p.FullName.Contains("BPASmartClient.")).ToList();
  169. List<string> dllList = new List<string>();
  170. if (files != null)
  171. {
  172. foreach (var item in files)
  173. {
  174. var res = System.IO.Path.GetFileNameWithoutExtension(item.FullName);
  175. if (res != null && res.Length > 0 && res.Contains(".") && !res.Contains("dll")) fileList.Add(res);
  176. }
  177. }
  178. if (dlls != null)
  179. {
  180. dlls.ForEach((item) =>
  181. {
  182. item.GetTypes().ToList().ForEach((type) =>
  183. {
  184. if (type.GetInterfaces().Contains(typeof(IDevice)))
  185. {
  186. if (!type.FullName.Contains("BaseDevice")) ShopDeviceConfigViewModel.IDevices.Add(type.FullName);
  187. }
  188. else if (type.GetInterfaces().Contains(typeof(IPeripheral)))
  189. {
  190. if (!type.FullName.Contains("BasePeripheral")) ShopDeviceConfigViewModel.IPeripherals.Add(type.FullName);
  191. }
  192. });
  193. dllList.Add(System.IO.Path.GetFileNameWithoutExtension(item.EscapedCodeBase));
  194. });
  195. }
  196. dllList.ForEach((item) => { if (fileList.Contains(item)) fileList.Remove(item); });
  197. fileList.ForEach((item) =>
  198. {
  199. Assembly.Load(item).GetTypes().ToList().ForEach((type) =>
  200. {
  201. if (type.GetInterfaces().Contains(typeof(IDevice)))
  202. {
  203. if (!type.FullName.Contains("BaseDevice")) ShopDeviceConfigViewModel.IDevices.Add(type.FullName);
  204. }
  205. else if (type.GetInterfaces().Contains(typeof(IPeripheral)))
  206. {
  207. if (!type.FullName.Contains("BasePeripheral")) ShopDeviceConfigViewModel.IPeripherals.Add(type.FullName);
  208. }
  209. });
  210. });
  211. }
  212. private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
  213. {
  214. this.DragMove();
  215. }
  216. private void CloseButton_Click(object sender, RoutedEventArgs e)
  217. {
  218. this.Close();
  219. }
  220. private void NavButton_Click(object sender, RoutedEventArgs e)
  221. {
  222. FadeInOut(0, 1, 750, 0);
  223. try
  224. {
  225. if (sender is Button bt )
  226. {
  227. Type type = Type.GetType($"BPASmartClient.MilkWithTea.View.{bt.Tag?.ToString()}");
  228. ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes);
  229. contentRegion.Content = (FrameworkElement)cti.Invoke(null);
  230. sb.Begin();
  231. }
  232. }
  233. catch (Exception ex)
  234. {
  235. MessageLog.GetInstance.ShowEx($"BPASmartClient 中引发错误,MainWindow.xaml.cs 类MenuItem_Click(),描述:[{ex.Message}]");
  236. }
  237. }
  238. private void FadeInOut(double opactityFrom ,double opactityTo,double yForm,double yTo)
  239. {
  240. contentRegion.RenderTransform = new TranslateTransform();
  241. yd1.From = opactityFrom;//动画的起始值
  242. yd1.To = opactityTo;//动画的结束值
  243. yd1.Duration = TimeSpan.FromSeconds(0.8);
  244. Storyboard.SetTarget(yd1, contentRegion);//给故事板绑定动画
  245. Storyboard.SetTargetProperty(yd1, new PropertyPath("Opacity"));//动画的依赖属性
  246. yd2.From = yForm;//动画的起始值
  247. yd2.To = yTo;//动画的结束值
  248. yd2.Duration = TimeSpan.FromSeconds(0.5);
  249. Storyboard.SetTarget(yd2, contentRegion);//给故事板绑定动画
  250. Storyboard.SetTargetProperty(yd2, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)"));//动画的依赖属性
  251. sb.Children.Add(yd1);//故事板添加动画
  252. sb.Children.Add(yd2);
  253. }
  254. }
  255. }