Beispiel #1
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));
        }
Beispiel #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);
        }
Beispiel #3
0
 public void Reset()
 {
     BeamgunState.AppendToAlert("Resetting alarm.");
     BeamgunState.Disabler.Enable();
     _alarm.Reset();
     _networkWatcher.Triggered = false;
 }
Beispiel #4
0
 public void Reset()
 {
     BeamgunState.AppendToAlert("Resetting alarm.");
     BeamgunState.Disabler.Enable();
     BeamgunState.KeyLog = $"Reset at {DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}\n";
     _alarm.Reset();
 }
Beispiel #5
0
        public void Trigger(string message)
        {
            if (_triggered)
            {
                return;
            }
            _beamgunState.AppendToAlert(message);
            _triggered = true;
            var triggerThread = new Thread(() =>
            {
                while (_triggered)
                {
                    AlarmCallback?.Invoke();
                    Thread.Sleep(_repeatInterval);
                }
            });

            triggerThread.Start();
        }
Beispiel #6
0
 public void Reset()
 {
     BeamgunState.AppendToAlert("Resetting alarm.");
     BeamgunState.Disabler.Enable();
     _alarm.Reset();
 }
Beispiel #7
0
 public void ClearAlerts()
 {
     BeamgunState.AlertLog = "";
     BeamgunState.AppendToAlert("Log cleared.");
 }
Beispiel #8
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));
            };
        }