|
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Reflection;
- using System.Security.Cryptography.Xml;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Media;
- using BPASmartClient.CustomResource.Pages.Model;
- using BPA.Helper;
- using BPASmartClient.Model;
- using BPA.Helper;
-
-
- namespace BPASmartClient.CustomResource.Pages.ViewModel
- {
- public class MainViewModel : NotifyBase
- {
- public MainViewModel()
- {
- NavChangedCommand = new BPARelayCommand<object>(DoNavChanged);
- MessageLog.GetInstance.InfoNotify = new Action<string>((o) =>
- {
- Application.Current?.Dispatcher?.Invoke(() =>
- {
- //ff20aefe
- var temp = new MessageModel()
- {
- LogInfo = o,
- Forground = new SolidColorBrush(Color.FromArgb(255, 32, 174, 254))
- };
- if (DebugLogViewModel.MessageModels.Count > 0)
- DebugLogViewModel.MessageModels.Insert(0, temp);
- else
- DebugLogViewModel.MessageModels.Add(temp);
- });
- });
-
- MessageLog.GetInstance.ExInfoNotify = new Action<string>((o) =>
- {
- Application.Current?.Dispatcher?.Invoke(() =>
- {
- //FFF53F62
- var temp = new MessageModel()
- {
- LogInfo = o,
- Forground = new SolidColorBrush(Color.FromArgb(255, 245, 63, 98))
- };
- if (DebugLogViewModel.MessageModels.Count > 0)
- DebugLogViewModel.MessageModels.Insert(0, temp);
- else
- DebugLogViewModel.MessageModels.Add(temp);
- });
- });
-
- BPA.Helper.MessageLog.GetInstance.NotifyShow = new Action<string>((o) =>
- {
- try
- {
- Application.Current?.Dispatcher?.Invoke(() =>
- {
- //ff20aefe
- var temp = new MessageModel()
- {
- LogInfo = o,
- Forground = new SolidColorBrush(Color.FromArgb(255, 32, 174, 254))
- };
- if (DebugLogViewModel.MessageModels.Count > 0)
- DebugLogViewModel.MessageModels.Insert(0, temp);
- else
- DebugLogViewModel.MessageModels.Add(temp);
- });
- }
- catch (Exception)
- {
-
- //throw;
- }
- });
- BPA.Helper.MessageLog.GetInstance.NotifyShowEx = new Action<string>((o) =>
- {
- Application.Current?.Dispatcher?.Invoke(() =>
- {
- //FFF53F62
- var temp = new MessageModel()
- {
- LogInfo = o,
- Forground = new SolidColorBrush(Color.FromArgb(255, 245, 63, 98))
- };
- if (DebugLogViewModel.MessageModels.Count > 0)
- DebugLogViewModel.MessageModels.Insert(0, temp);
- else
- DebugLogViewModel.MessageModels.Add(temp);
- });
-
-
- });
- menuModels = MenuManage.GetInstance.menuModels;
- PermissionChange();
- ActionManage.GetInstance.Register(new Action(() =>
- {
- PermissionChange();
- }), "PermissionChange");
-
- ActionManage.GetInstance.Register(new Action<object>((c) =>
- {
- if (c != null)
- IsAlarm = Convert.ToBoolean(c);
- }), "HeartBeatCheck");
- }
-
- private void PermissionChange()
- {
- int MainIndex = Array.FindIndex(menuModels.ToArray(), P => P.MainMenuVisibility == Visibility.Visible);
- if (MainIndex >= 0 && MainIndex < menuModels.Count)
- {
- int SubIndex; SubIndex = Array.FindIndex(menuModels.ElementAt(MainIndex).subMenumodels.ToArray(), p => p.SubMenuVisibility == Visibility.Visible);
- if (SubIndex >= 0 && SubIndex < menuModels.ElementAt(MainIndex).subMenumodels.Count)
- {
- //DoNavChanged(menuModels.ElementAt(MainIndex).subMenumodels.ElementAt(SubIndex).ToggleWindowPath);
- DoNavChanged(menuModels.ElementAt(MainIndex).subMenumodels.ElementAt(SubIndex));
- }
- }
- }
-
- public ObservableCollection<MenuModel> menuModels { get; set; }
-
- private void DoNavChanged(object obj)
- {
- if (obj != null && obj is SubMenumodel menumodel)
- {
- DisplayName = menumodel.SubMenuName;
- var end = menumodel.AssemblyName.Substring(menumodel.AssemblyName.Length - 1);
- var start = menumodel.ToggleWindowPath.Substring(0, 1);
- bool isAddPoint = end != "." && start != ".";
- string point = isAddPoint ? "." : "";
- Type type = Assembly.Load(menumodel.AssemblyName)?.GetType($"{menumodel.AssemblyName}{point}{menumodel.ToggleWindowPath}");
- ConstructorInfo cti = type?.GetConstructor(System.Type.EmptyTypes);
- if (type?.BaseType.Name == "Window") ((Window)cti?.Invoke(null)).ShowDialog();
- else if (type?.BaseType.Name == "UserControl")
- {
- MainContent = null;
- MainContent = (FrameworkElement)cti?.Invoke(null);
- MainContent?.GetType()?.GetProperty("Name").SetValue(MainContent, menumodel.SubMenuName);
- }
- }
- }
- private bool _status;
- /// <summary>
- /// 设备初始化状态
- /// </summary>
- public bool Status
- {
- get { return _status; }
- set
- {
- if (value)
- {
- ActionManage.GetInstance.Send("StartPlcInite");
- }
- else
- {
- ActionManage.GetInstance.Send("EndPlcInite");
- }
- _status = value;
- OnPropertyChanged();
- }
- }
- private bool _isAlarm = true;
- /// <summary>
- /// 心跳检测报警
- /// </summary>
- public bool IsAlarm
- {
- get { return _isAlarm; }
- set { _isAlarm = value; OnPropertyChanged(); }
- }
- /// <summary>
- /// 开机自启
- /// </summary>
- public bool AutoStart { get { return SystemHelper.GetInstance.IsAutoStart(); } set { SystemHelper.GetInstance.AutoStart(value); OnPropertyChanged(); } }
- public BPARelayCommand<object> NavChangedCommand { get; set; }
-
- public FrameworkElement MainContent { get { return _mMainContent; } set { _mMainContent = value; OnPropertyChanged(); } }
- private FrameworkElement _mMainContent;
-
- public string DisplayName { get { return _mDisplayName; } set { _mDisplayName = value; OnPropertyChanged(); } }
- private string _mDisplayName;
-
-
-
- }
- }
|