Beispiel #1
0
        private void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
        {
            if (e.Reason == SessionSwitchReason.SessionLock)
            {
                backgroundManager.StopUnlockTimer();
                int OrderNo = commonService.InfoViewModel.SystemActions.First().OrderNo + 1;

                var sysAction = new SystemAction {
                    OrderNo = OrderNo, CurrentAction = ActionType.Lock, ActionTime = DateTime.Now
                };
                commonService.InfoViewModel.SystemActions.Insert(0, sysAction);

                backgroundManager.SaveSystemAction(sysAction);
            }
            else if (e.Reason == SessionSwitchReason.SessionUnlock)
            {
                backgroundManager.StartUnlockTimer();
                int OrderNo = commonService.InfoViewModel.SystemActions.First().OrderNo + 1;

                var sysAction = new SystemAction {
                    OrderNo = OrderNo, CurrentAction = ActionType.Unlock, ActionTime = DateTime.Now
                };
                commonService.InfoViewModel.SystemActions.Insert(0, sysAction);

                backgroundManager.SaveSystemAction(sysAction);
            }
        }
Beispiel #2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            bool createNew;

            oneInstanceMutex = new Mutex(false, "BgInfo_OneInstanceMutex", out createNew);
            if (!createNew)
            {
                MessageBox.Show("Am running already!", "SimpleMan Blues", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                Shutdown();
                return;
            }

            commonService = CommonService.GetInstance();

            mainWindow = new Blues.MainWindow();
            commonService.CurrentMainWindow = mainWindow;
            infoWindow = new InfoWindow();
            commonService.CurrentInfoWindow = infoWindow;

            backgroundManager = BackgroundManager.GetInstance();
            backgroundManager.InitTray();
            backgroundManager.StartUnlockTimer();

            mainWindow.Show();

            var sysAction = new SystemAction {
                OrderNo = 1, CurrentAction = ActionType.StartUp, ActionTime = DateTime.Now
            };

            commonService.InfoViewModel.SystemActions.Add(sysAction);
            backgroundManager.SaveSystemAction(sysAction);

            Microsoft.Win32.SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
        }