using MaterialDesignThemes.Wpf; using Prism.Commands; using Prism.Events; using Prism.Mvvm; using Prism.Regions; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media; using DM_Weight.msg; using DM_Weight.Port; using DM_Weight.util; using DM_Weight.Finger; using DM_Weight.Views; using Unity; using System.Threading; using System.Timers; namespace DM_Weight.ViewModels { internal class MainWindowViewModel : BindableBase { private string _title = "Prism App"; //标题 private ISnackbarMessageQueue _snackbarMessageQueue = new SnackbarMessageQueue(TimeSpan.FromSeconds(3)); private SolidColorBrush _colorBrush; //private PortUtil _portUtil; private ScreenUtil _screenUtil; public SolidColorBrush Background { get => _colorBrush; set => SetProperty(ref _colorBrush, value); } public ISnackbarMessageQueue SnackbarMessageQueue { get => _snackbarMessageQueue; set => SetProperty(ref _snackbarMessageQueue, value); } public string Title { get { return _title; } set { SetProperty(ref _title, value); } } IEventAggregator eventAggregator; //public MainWindowViewModel(IEventAggregator eventAggregator, PortUtil portUtil, ScreenUtil screenUtil) //{ // _portUtil = portUtil; // this.eventAggregator = eventAggregator; // this.eventAggregator.GetEvent().Subscribe(doMyPrismEvent2); // _screenUtil = screenUtil; //} private FingerprintUtil _fingerprintUtil; IRegionManager _regionManager; IUnityContainer _container; PortUtil _portUtil; public MainWindowViewModel(IRegionManager regionManager, IUnityContainer container, IEventAggregator eventAggregator, FingerprintUtil fingerprintUtil, ScreenUtil screenUtil, PortUtil portUtil) { _portUtil = portUtil; this.eventAggregator = eventAggregator; this.eventAggregator.GetEvent().Subscribe(doMyPrismEvent2); _screenUtil = screenUtil; _fingerprintUtil = fingerprintUtil; _regionManager = regionManager; _container = container; System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => { _container.RegisterType("LoginWindow"); _regionManager.RequestNavigate("MainRegion", "LoginWindow"); })); #region 温度查询定时 int interval = 60000; if (interval > 0) { System.Timers.Timer doorTimer = new System.Timers.Timer(); doorTimer.Elapsed += new System.Timers.ElapsedEventHandler(doorStatus); doorTimer.Interval = interval; doorTimer.Start(); } #endregion } /// /// 监测后门是否打开 /// private async void doorStatus(object sender, ElapsedEventArgs e) { if (!_portUtil.Operate) { //监测后门是否打开 _portUtil.GetSingleBoardBackDoorState(); } } void doMyPrismEvent2(AlertMsg msg) { switch (msg.Type) { case MsgType.INFO: this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00e676")); break; case MsgType.ERROR: this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); break; default: this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00e676")); break; } SnackbarMessageQueue.Enqueue(msg.Message); } } }