public void Reset() { BeamgunState.AppendToAlert("Resetting alarm."); BeamgunState.Disabler.Enable(); _alarm.Reset(); _networkWatcher.Triggered = false; }
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); }
public void Reset() { BeamgunState.AppendToAlert("Resetting alarm."); BeamgunState.Disabler.Enable(); BeamgunState.KeyLog = $"Reset at {DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}\n"; _alarm.Reset(); }
public void IsNotDisabledAfterConstruction() { var state = new BeamgunState(); var disabler = new Disabler(state); Assert.AreEqual(false, disabler.IsDisabled); }
public void HasZeroDisabledTimeAfterEnable() { var state = new BeamgunState(); var disabler = new Disabler(state); disabler.Enable(); Assert.AreEqual(0, disabler.DisabledTime); }
public void WindowNotVisibleAfterDisabled() { var state = new BeamgunState(); var disabler = new Disabler(state); disabler.DisableUntil(DateTime.Now.AddMilliseconds(50)); Assert.AreEqual(Visibility.Hidden, state.MainWindowVisibility); }
public void TrayPathHasIconAfterDisabled() { var state = new BeamgunState(); var disabler = new Disabler(state); disabler.DisableUntil(DateTime.Now.AddMilliseconds(50)); Assert.IsNotNull(state.TrayIconPath); }
public void HasNonZeroDisabledTimeAfterDisabled() { var state = new BeamgunState(); var disabler = new Disabler(state); disabler.DisableUntil(DateTime.Now.AddMilliseconds(50)); Assert.AreNotEqual(0, disabler.DisabledTime); }
public void IsDisabledAfterDisabled() { var state = new BeamgunState(); var disabler = new Disabler(state); disabler.DisableUntil(DateTime.Now.AddMilliseconds(50)); Assert.AreEqual(true, disabler.IsDisabled); }
public void EnableSetsIconPath() { var state = new BeamgunState(); var disabler = new Disabler(state); disabler.Enable(); Assert.NotNull(state.TrayIconPath); }
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)); }
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); }
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); }
public void Reset() { BeamgunState.AppendToAlert("Resetting alarm."); BeamgunState.Disabler.Enable(); _alarm.Reset(); }
public Alarm(uint repeatInterval, BeamgunState beamgunState) { _beamgunState = beamgunState; _repeatInterval = (int)repeatInterval; _triggered = false; }
public void ClearAlerts() { BeamgunState.AlertLog = ""; BeamgunState.AppendToAlert("Log cleared."); }
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)); }; }