|
- using BPASmartClient.CustomResource.Pages.Enums;
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.CustomResource.Pages.View;
- using BPASmartClient.Helper;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Configuration;
- using System.Data;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows;
- using BPASmart.Model;
-
- namespace BPASmart.VariableManager
- {
- /// <summary>
- /// Interaction logic for App.xaml
- /// </summary>
- public partial class App : Application
- {
- public static Window MainWindow;
- protected override void OnStartup(StartupEventArgs e)
- {
- base.OnStartup(e);
- DataRead();
- AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
- MenuInit();
- MainView mv = new MainView();
- mv.WindowState = WindowState.Normal;
- MainWindow = mv;
- mv.Show();
-
- }
-
- private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
- {
- DataSave();
- }
-
- protected override void OnExit(ExitEventArgs e)
- {
- base.OnExit(e);
- DataSave();
- }
-
- private void MenuInit()
- {
- #region 设备管理
- ObservableCollection<SubMenumodel> DeviceMonitor = new ObservableCollection<SubMenumodel>();
- DeviceMonitor.Add(new SubMenumodel()
- {
- SubMenuName = "设备管理",
- AssemblyName = "BPASmart.VariableManager",
- ToggleWindowPath = "Views.CommunicationSetView",
- SubMenuVisibility = Visibility.Visible,
- });
-
- MenuManage.GetInstance.menuModels.Add(new MenuModel()
- {
- MainMenuIcon = "",
- MainMenuName = "设备管理",
- Alias = "Device Management",
- subMenumodels = DeviceMonitor,
- });
- #endregion
-
- #region 变量管理,根据创建的通讯设备自动生成子菜单
- ObservableCollection<SubMenumodel> RecipeManage = new ObservableCollection<SubMenumodel>();
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- RecipeManage.Add(AddSubMenuModel(o.ToString()));
- }), "AddCommunicationDevice");
-
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null && o is CommunicationModel menumodel)
- {
- var res = RecipeManage.FirstOrDefault(p => p.SubMenuName == menumodel.DeviceName);
- if (res != null) RecipeManage.Remove(res);
- }
-
- }), "RemoveCommunicationDevice");
-
-
- Json<CommunicationPar>.Data.CommunicationDevices?.ToList()?.ForEach(item =>
- {
- RecipeManage.Add(AddSubMenuModel(item.DeviceName));
- });
-
- MenuManage.GetInstance.menuModels.Add(new MenuModel()
- {
- MainMenuIcon = "",
- MainMenuName = "变量管理",
- Alias = "Recipe Management",
- subMenumodels = RecipeManage,
- });
- #endregion
-
- }
-
- private SubMenumodel AddSubMenuModel(string s)
- {
- return new SubMenumodel()
- {
- SubMenuName = s,
- AssemblyName = "BPASmart.VariableManager",
- ToggleWindowPath = "Views.VariableConfig",
- SubMenuVisibility = Visibility.Visible,
- };
- }
-
- private void DataSave()
- {
- //for (int i = 0; i < Json<CommunicationPar>.Data.CommunicationDevices.Count; i++)
- //{
- // for (int m = 0; m < Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(i).VarTableModels.Count; m++)
- // {
- // var deviceType = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(i).CommDevice;
- // var deviceValue = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(i).VarTableModels.ElementAt(m).Address;
- // string RealAddress = AddressConvert.GetInstance.PlcConverter(deviceType, deviceValue);
- // Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(i).VarTableModels.ElementAt(m).RealAddress = RealAddress;
- // }
- //}
-
- Json<CommunicationPar>.Save();
- }
-
-
- private void DataRead()
- {
- Json<CommunicationPar>.Read();
- }
- }
-
- }
|