|
- using BPASmartClient.Business;
- using BPASmartClient.CustomResource.UserControls;
- using BPASmartClient.CustomResource.UserControls.MessageShow;
- using BPASmartClient.Device;
- using BPASmartClient.Helper;
- using BPASmartClient.IoT;
- using BPASmartClient.Message;
- using BPASmartClient.Peripheral;
- using BPASmartClient.ViewModel;
- using System;
- using System.Collections.Generic;
- using System.IO;
- 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 BPASmartClient.MilkWithTea
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainConsole mainConsole;
- public MainWindow()
- {
- InitializeComponent();
-
- Initialize();
-
- }
-
-
- private void Initialize()
- {
-
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- GetDevices();
- mainConsole = new MainConsole();
- mainConsole.Start();
- }), "启动主控制台", false);
-
- ActionManage.GetInstance.Register(new Action(() =>
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- try
- {
- DataVClient.GetInstance().Initialize();
- DataVClient.GetInstance().Start();
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.ShowEx(ex.ToString());
- }
- }), "启动主IoT", false);
- }), "配置初始化完成Iot启动");
-
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- App.Current.Dispatcher.Invoke(new Action(() =>
- {
- if (o is IOTCommandModel iot)
- {
- switch (iot.CommandName)
- {
- case 0://控制类
- if (iot.CommandValue != null && iot.CommandValue.Count > 0)
- {
- switch (iot.CommandValue.Keys.ToList()[0])
- {
- case "程序启动":
- //mainConsole.Start();
- break;
- //mainConsole.Stop();
- case "程序停止":
- break;
- case "程序复位":
- //mainConsole.Stop();
- //mainConsole.Start();
- break;
- default:
- break;
- }
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "大屏控制", iot.CommandValue.Keys.ToList()[0]);
- }
- break;
- case 1://设置类
- break;
- case 2://通知类
- if (iot.CommandValue != null && iot.CommandValue.ContainsKey("text"))
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "大屏通知", iot.CommandValue["text"]);
- }
- break;
- default:
- break;
- }
- }
- }));
- }), "IotBroadcast");
- NavButton_Click(new Button() { Tag = "MainControlView" },null);
-
- }
-
- /// <summary>
- /// 获取设备集合
- /// </summary>
- private void GetDevices()
- {
- //List<string> IDevices = new List<string>();
- //List<string> IPeripherals = new List<string>();
-
- DirectoryInfo directoryInfo = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
- var files = directoryInfo.GetFiles().Where(p => p.FullName.Contains("BPASmartClient.") && p.FullName.Contains("dll")).ToList();
- List<string> fileList = new List<string>();
-
- var assemblies = AppDomain.CurrentDomain.GetAssemblies();
- var dlls = assemblies?.Where(p => p.FullName.Contains("BPASmartClient.")).ToList();
- List<string> dllList = new List<string>();
-
- if (files != null)
- {
- foreach (var item in files)
- {
- var res = System.IO.Path.GetFileNameWithoutExtension(item.FullName);
- if (res != null && res.Length > 0 && res.Contains(".") && !res.Contains("dll")) fileList.Add(res);
- }
- }
-
- if (dlls != null)
- {
- dlls.ForEach((item) =>
- {
- item.GetTypes().ToList().ForEach((type) =>
- {
- if (type.GetInterfaces().Contains(typeof(IDevice)))
- {
- if (!type.FullName.Contains("BaseDevice")) ShopDeviceConfigViewModel.IDevices.Add(type.FullName);
- }
- else if (type.GetInterfaces().Contains(typeof(IPeripheral)))
- {
- if (!type.FullName.Contains("BasePeripheral")) ShopDeviceConfigViewModel.IPeripherals.Add(type.FullName);
- }
- });
-
- dllList.Add(System.IO.Path.GetFileNameWithoutExtension(item.EscapedCodeBase));
- });
- }
-
- dllList.ForEach((item) => { if (fileList.Contains(item)) fileList.Remove(item); });
-
- fileList.ForEach((item) =>
- {
- Assembly.Load(item).GetTypes().ToList().ForEach((type) =>
- {
- if (type.GetInterfaces().Contains(typeof(IDevice)))
- {
- if (!type.FullName.Contains("BaseDevice")) ShopDeviceConfigViewModel.IDevices.Add(type.FullName);
- }
- else if (type.GetInterfaces().Contains(typeof(IPeripheral)))
- {
- if (!type.FullName.Contains("BasePeripheral")) ShopDeviceConfigViewModel.IPeripherals.Add(type.FullName);
- }
- });
- });
-
-
- }
-
-
-
- private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
- {
- this.DragMove();
- }
-
-
-
- private void CloseButton_Click(object sender, RoutedEventArgs e)
- {
- this.Close();
- }
-
-
- private void NavButton_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (sender is Button bt )
- {
- Type type = Type.GetType($"BPASmartClient.MilkWithTea.View.{bt.Tag?.ToString()}");
- ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes);
- contentRegion.Content = (FrameworkElement)cti.Invoke(null);
- }
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.ShowEx($"BPASmartClient 中引发错误,MainWindow.xaml.cs 类MenuItem_Click(),描述:[{ex.Message}]");
- }
- }
- }
- }
|