|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- 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 Newtonsoft.Json;
- 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.Animation;
- 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();
-
- TextHelper.GetInstance.WriteTextInfo("MOC", "StartShop", "DeviceConfig");
- CreateDevice();
- //Initialize();
-
- }
-
- Storyboard sb = new Storyboard();
- DoubleAnimation yd1 = new DoubleAnimation();//实例化浮点动画
- DoubleAnimation yd2 = new DoubleAnimation();
-
- private void CreateDevice()
- {
- DirectoryInfo directoryInfo = new DirectoryInfo(LocaPath.GetInstance().GetDeviceConfigPath);
- if(!File.Exists($"{directoryInfo}Moc.json"))
- {
- File.WriteAllText($"{directoryInfo}Moc.json", JsonConvert.SerializeObject(GLobal.deviceConfig));
- }
- string JsonString = File.ReadAllText($"{directoryInfo}MOC.json");
- var result = JsonConvert.DeserializeObject<ObservableCollection<DeviceConfigModelJson>>(JsonString);
- if (result != null)
- {
- ShopDeviceConfigViewModel.deviceConfig.Clear();
- foreach (var item in result)
- {
- GLobal.deviceConfig.Add(item);
- }
- }
-
- if(GLobal.deviceConfig.Count <1)
- {
- GLobal.deviceConfig.Add(new DeviceConfigModelJson());
- if(GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.Count <1)
- {
- GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.Add(new DeviceModel());
- if(GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAtOrDefault(0).communicationDevcies.Count <1)
- {
- GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAtOrDefault(0).communicationDevcies.Add(new CommunicationModel());
- }
- }
- }
- if (GLobal.deviceConfig.ElementAt(0).deviceModels.ElementAt(0).communicationDevcies.ElementAt(0).variables.Count < 1)
- {
- for (int i = 0; i < 20; i++)
- {
- GLobal.deviceConfig.ElementAt(0).deviceModels.ElementAt(0).communicationDevcies.ElementAt(0).variables.Add(new Variable()
- {
- Id = GLobal.deviceConfig.ElementAt(0).deviceModels.ElementAt(0).communicationDevcies.ElementAt(0).variables.Count,
- Address = string.Empty,
- ReadLeng = 0
- });
- }
- File.WriteAllText($"{LocaPath.GetInstance().GetDeviceConfigPath}MOC.json", JsonConvert.SerializeObject(GLobal.deviceConfig));
- }
- }
-
- 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)
- {
-
- FadeInOut(0, 1, 750, 0);
- 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);
- sb.Begin();
- }
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.ShowEx($"BPASmartClient 中引发错误,MainWindow.xaml.cs 类MenuItem_Click(),描述:[{ex.Message}]");
- }
- }
-
-
- private void FadeInOut(double opactityFrom ,double opactityTo,double yForm,double yTo)
- {
- contentRegion.RenderTransform = new TranslateTransform();
- yd1.From = opactityFrom;//动画的起始值
- yd1.To = opactityTo;//动画的结束值
- yd1.Duration = TimeSpan.FromSeconds(0.8);
- Storyboard.SetTarget(yd1, contentRegion);//给故事板绑定动画
- Storyboard.SetTargetProperty(yd1, new PropertyPath("Opacity"));//动画的依赖属性
- yd2.From = yForm;//动画的起始值
- yd2.To = yTo;//动画的结束值
- yd2.Duration = TimeSpan.FromSeconds(0.5);
- Storyboard.SetTarget(yd2, contentRegion);//给故事板绑定动画
- Storyboard.SetTargetProperty(yd2, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)"));//动画的依赖属性
- sb.Children.Add(yd1);//故事板添加动画
- sb.Children.Add(yd2);
- }
- }
- }
|