Esempio n. 1
0
 public void Reset()
 {
     BeamgunState.AppendToAlert("Resetting alarm.");
     BeamgunState.Disabler.Enable();
     _alarm.Reset();
     _networkWatcher.Triggered = false;
 }
Esempio n. 2
0
        private UsbStorageGuard InstallUsbStorageGuard(IBeamgunSettings beamgunSettings)
        {
            var usbGuard = new UsbStorageGuard(beamgunSettings);

            BeamgunState.UsbMassStorageDisabled = usbGuard.UsbStorageDisabled;
            BeamgunState.PropertyChanged       += (sender, args) =>
            {
                if (args.PropertyName != nameof(BeamgunState.UsbMassStorageDisabled))
                {
                    return;
                }
                if (!beamgunSettings.IsAdmin)
                {
                    BeamgunState.AppendToAlert("Cannot change USB Mass Storage settings without administrative privileges.");
                }
                try
                {
                    usbGuard.UsbStorageDisabled = BeamgunState.UsbMassStorageDisabled;
                }
                catch (PrivilegeNotHeldException e)
                {
                    BeamgunState.AppendToAlert($"Privileges exception: {e.Message}");
                }
            };
            return(usbGuard);
        }
Esempio n. 3
0
 public void Reset()
 {
     BeamgunState.AppendToAlert("Resetting alarm.");
     BeamgunState.Disabler.Enable();
     BeamgunState.KeyLog = $"Reset at {DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}\n";
     _alarm.Reset();
 }
Esempio n. 4
0
        public void IsNotDisabledAfterConstruction()
        {
            var state = new BeamgunState();

            var disabler = new Disabler(state);

            Assert.AreEqual(false, disabler.IsDisabled);
        }
Esempio n. 5
0
        public void HasZeroDisabledTimeAfterEnable()
        {
            var state    = new BeamgunState();
            var disabler = new Disabler(state);

            disabler.Enable();

            Assert.AreEqual(0, disabler.DisabledTime);
        }
Esempio n. 6
0
        public void WindowNotVisibleAfterDisabled()
        {
            var state    = new BeamgunState();
            var disabler = new Disabler(state);

            disabler.DisableUntil(DateTime.Now.AddMilliseconds(50));

            Assert.AreEqual(Visibility.Hidden, state.MainWindowVisibility);
        }
Esempio n. 7
0
        public void TrayPathHasIconAfterDisabled()
        {
            var state    = new BeamgunState();
            var disabler = new Disabler(state);

            disabler.DisableUntil(DateTime.Now.AddMilliseconds(50));

            Assert.IsNotNull(state.TrayIconPath);
        }
Esempio n. 8
0
        public void HasNonZeroDisabledTimeAfterDisabled()
        {
            var state    = new BeamgunState();
            var disabler = new Disabler(state);

            disabler.DisableUntil(DateTime.Now.AddMilliseconds(50));

            Assert.AreNotEqual(0, disabler.DisabledTime);
        }
Esempio n. 9
0
        public void IsDisabledAfterDisabled()
        {
            var state    = new BeamgunState();
            var disabler = new Disabler(state);

            disabler.DisableUntil(DateTime.Now.AddMilliseconds(50));

            Assert.AreEqual(true, disabler.IsDisabled);
        }
Esempio n. 10
0
        public void EnableSetsIconPath()
        {
            var state    = new BeamgunState();
            var disabler = new Disabler(state);

            disabler.Enable();

            Assert.NotNull(state.TrayIconPath);
        }
Esempio n. 11
0
        public BeamgunViewModel()
        {
            var dictionary      = new RegistryBackedDictionary();
            var beamgunSettings = new BeamgunSettings(dictionary);

            BeamgunState = new BeamgunState(beamgunSettings)
            {
                MainWindowVisibility = Visibility.Hidden
            };
            // TODO: This bi-directional relationship feels bad.
            dictionary.BadCastReport += BeamgunState.AppendToAlert;
            BeamgunState.Disabler     = new Disabler(BeamgunState);
            BeamgunState.Disabler.Enable();
            DisableCommand     = new DisableCommand(this, beamgunSettings);
            TrayIconCommand    = new TrayIconCommand(this);
            LoseFocusCommand   = new DeactivatedCommand(this);
            ResetCommand       = new ResetCommand(this);
            ExitCommand        = new ExitCommand(this);
            ClearAlertsCommand = new ClearAlertsCommand(this);
            _keystrokeHooker   = InstallKeystrokeHooker();
            _usbStorageGuard   = InstallUsbStorageGuard(beamgunSettings);
            _alarm             = InstallAlarm(beamgunSettings);
            _networkWatcher    = new NetworkWatcher(beamgunSettings,
                                                    new NetworkAdapterDisabler(),
                                                    x => BeamgunState.AppendToAlert(x),
                                                    x =>
            {
                _alarm.Trigger(x);
                BeamgunState.SetGraphicsLanAlert();
            },
                                                    () => BeamgunState.Disabler.IsDisabled);
            _keyboardWatcher = new KeyboardWatcher(beamgunSettings,
                                                   new WorkstationLocker(),
                                                   x => BeamgunState.AppendToAlert(x),
                                                   x =>
            {
                _alarm.Trigger(x);
                BeamgunState.SetGraphicsKeyboardAlert();
            },
                                                   () => BeamgunState.Disabler.IsDisabled);
            _mouseWatcher = new MouseWatcher(beamgunSettings,
                                             new WorkstationLocker(),
                                             x => BeamgunState.AppendToAlert(x),
                                             x =>
            {
                _alarm.Trigger(x);
                BeamgunState.SetGraphicsMouseAlert();
            },
                                             () => BeamgunState.Disabler.IsDisabled);
            var checker = new VersionChecker();

            _updateTimer = new VersionCheckerTimer(beamgunSettings,
                                                   checker,
                                                   x => BeamgunState.AppendToAlert(x));
        }
Esempio n. 12
0
        public void IsNotDisabledTimeAfterDisabledAndWait()
        {
            var state    = new BeamgunState();
            var disabler = new Disabler(state);
            var wait     = 10;

            disabler.DisableUntil(DateTime.Now.AddMilliseconds(wait));
            Thread.Sleep(wait + 1);

            Assert.AreEqual(false, disabler.IsDisabled);
        }
Esempio n. 13
0
        private KeystrokeHooker InstallKeystrokeHooker()
        {
            var converter       = new Models.KeyConverter();
            var keystrokeHooker = new KeystrokeHooker();

            keystrokeHooker.Callback += key =>
            {
                if (!_alarm.Triggered)
                {
                    return;
                }
                BeamgunState.AppendToKeyLog(converter.Convert(key));
            };
            return(keystrokeHooker);
        }
Esempio n. 14
0
 public void Reset()
 {
     BeamgunState.AppendToAlert("Resetting alarm.");
     BeamgunState.Disabler.Enable();
     _alarm.Reset();
 }
Esempio n. 15
0
 public Alarm(uint repeatInterval, BeamgunState beamgunState)
 {
     _beamgunState   = beamgunState;
     _repeatInterval = (int)repeatInterval;
     _triggered      = false;
 }
Esempio n. 16
0
 public void ClearAlerts()
 {
     BeamgunState.AlertLog = "";
     BeamgunState.AppendToAlert("Log cleared.");
 }
Esempio n. 17
0
        public BeamgunViewModel(Window mainWindow)
        {
            BeamgunState = new BeamgunState
            {
                MainWindowVisibility = Visibility.Hidden
            };
            BeamgunState.Disabler = new Disabler(BeamgunState);
            BeamgunState.Disabler.Enable();
            DisableCommand     = new DisableCommand(this);
            TrayIconCommand    = new TrayIconCommand(this);
            LoseFocusCommand   = new DeactivatedCommand(this);
            ResetCommand       = new ResetCommand(this);
            ExitCommand        = new ExitCommand(this);
            _workstationLocker = new WorkstationLocker();

            const uint repeatInterval = 10;
            var        converter      = new KeyConverter();

            _keystrokeHooker = new KeystrokeHooker();

            _alarm = new Alarm(repeatInterval, BeamgunState);
            _alarm.AlarmCallback += () =>
            {
                BeamgunState.MainWindowState      = WindowState.Normal;
                BeamgunState.MainWindowVisibility = Visibility.Visible;
                BeamgunState.SetGraphicsAlert();
                if (BeamgunState.StealFocus)
                {
                    StealFocus();
                }
            };

            var windowHandle = new WindowInteropHelper(mainWindow).Handle;

            _usbMonitor              = new UsbMonitor(windowHandle);
            _usbMonitor.DeviceAdded += () =>
            {
                BeamgunState.AppendToAlert("USB device inserted.");
                _alarm.Trigger("Alerting on USB device insertion.");
                if (!BeamgunState.LockWorkStation)
                {
                    return;
                }
                var result  = _workstationLocker.Lock();
                var message = result ? "Successfully locked the workstation." : "Could not lock the workstation.";
                BeamgunState.AppendToAlert(message);
            };
            _usbMonitor.DeviceRemoved += () =>
            {
                BeamgunState.AppendToAlert("USB device removed.");
            };

            _keystrokeHooker.Callback += key =>
            {
                if (!_alarm.Triggered)
                {
                    return;
                }
                BeamgunState.AppendToKeyLog(converter.Convert(key));
            };
        }