终端一体化运控平台
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.
 
 
 

129 lines
4.2 KiB

  1. using BPASmartClient.CustomResource.Pages.Enums;
  2. using BPASmartClient.CustomResource.Pages.Model;
  3. using BPASmartClient.CustomResource.Pages.View;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.Configuration;
  8. using System.Data;
  9. using System.Linq;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using BPASmart.Model;
  13. using BPA.Helper;
  14. using System.IO;
  15. namespace BPASmart.VariableManager
  16. {
  17. /// <summary>
  18. /// Interaction logic for App.xaml
  19. /// </summary>
  20. public partial class App : Application
  21. {
  22. public static Window MainWindow;
  23. protected override void OnStartup(StartupEventArgs e)
  24. {
  25. base.OnStartup(e);
  26. ServiceCenter.GetInstance.PipeInit();
  27. Json<LocalPar>.Read();
  28. FileConfigModel.ConstPath = Json<LocalPar>.Data.ProjectPath;
  29. DataRead();
  30. AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
  31. MenuInit();
  32. MainView mv = new MainView();
  33. mv.WindowState = WindowState.Normal;
  34. MainWindow = mv;
  35. mv.Show();
  36. ServiceCenter.GetInstance.ExitNotify = new Action(() => { App.Current.Dispatcher.Invoke(() => { mv.Close(); }); });
  37. }
  38. private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  39. {
  40. DataSave();
  41. }
  42. protected override void OnExit(ExitEventArgs e)
  43. {
  44. base.OnExit(e);
  45. DataSave();
  46. }
  47. private void MenuInit()
  48. {
  49. #region 设备管理
  50. ObservableCollection<SubMenumodel> DeviceMonitor = new ObservableCollection<SubMenumodel>();
  51. DeviceMonitor.Add(new SubMenumodel()
  52. {
  53. SubMenuName = "设备管理",
  54. AssemblyName = "BPASmart.VariableManager",
  55. ToggleWindowPath = "Views.CommunicationSetView",
  56. SubMenuVisibility = Visibility.Visible,
  57. });
  58. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  59. {
  60. MainMenuIcon = "&#xe603;",
  61. MainMenuName = "设备管理",
  62. Alias = "Device Management",
  63. subMenumodels = DeviceMonitor,
  64. });
  65. #endregion
  66. #region 变量管理,根据创建的通讯设备自动生成子菜单
  67. ObservableCollection<SubMenumodel> RecipeManage = new ObservableCollection<SubMenumodel>();
  68. ActionManage.GetInstance.Register(new Action<object>((o) =>
  69. {
  70. RecipeManage.Add(AddSubMenuModel(o.ToString()));
  71. }), "AddCommunicationDevice");
  72. ActionManage.GetInstance.Register(new Action<object>((o) =>
  73. {
  74. if (o != null && o is CommunicationModel menumodel)
  75. {
  76. var res = RecipeManage.FirstOrDefault(p => p.SubMenuName == menumodel.DeviceName);
  77. if (res != null) RecipeManage.Remove(res);
  78. }
  79. }), "RemoveCommunicationDevice");
  80. Json<CommunicationPar>.Data.CommunicationDevices?.ToList()?.ForEach(item =>
  81. {
  82. RecipeManage.Add(AddSubMenuModel(item.DeviceName));
  83. });
  84. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  85. {
  86. MainMenuIcon = "&#xe62d;",
  87. MainMenuName = "变量管理",
  88. Alias = "Recipe Management",
  89. subMenumodels = RecipeManage,
  90. });
  91. #endregion
  92. }
  93. private SubMenumodel AddSubMenuModel(string s)
  94. {
  95. return new SubMenumodel()
  96. {
  97. SubMenuName = s,
  98. AssemblyName = "BPASmart.VariableManager",
  99. ToggleWindowPath = "Views.VariableConfig",
  100. SubMenuVisibility = Visibility.Visible,
  101. };
  102. }
  103. private void DataSave()
  104. {
  105. Json<CommunicationPar>.Save(FileConfigModel.VarConfigPath);
  106. }
  107. private void DataRead()
  108. {
  109. Json<CommunicationPar>.Read(FileConfigModel.VarConfigPath);
  110. }
  111. }
  112. }