private void _timer_Elapsed(object sender, ElapsedEventArgs e) { var inputIdle = _user32.GetInputIdle(); var sockets = _stateStore.GetSockets(); foreach (var socket in sockets) { var settings = _stateStore.GetSettings(socket); var status = _stateStore.GetStatus(socket); bool turnSocketOn = inputIdle.TotalSeconds < 1 && status != PowerStatus.On; bool turnSocketOff = inputIdle >= settings.OffDelay && status != PowerStatus.Off; if (turnSocketOn) { _stateStore.SetStatus(socket, PowerStatus.On); StatusChanged?.Invoke(this, new StatusChangedEventArgs("", "", socket, PowerStatus.On)); } else if (turnSocketOff) { _stateStore.SetStatus(socket, PowerStatus.Off); StatusChanged?.Invoke(this, new StatusChangedEventArgs("", "", socket, PowerStatus.Off)); } fireStatusForecastEvent(socket, settings.OffDelay, inputIdle); } }
public void GetSettings_DefaultValue() { var socket = new Socket(1, "Test"); var defaultSettings = KeyloggerSocketSettings.GetDefault(); var stateStore = new KeyloggerStateStore(); Assert.Equal(defaultSettings, stateStore.GetSettings(socket)); }
public void GetSettings_SetAndGet() { var socket = new Socket(1, "Test"); var settings = new KeyloggerSocketSettings(TimeSpan.FromSeconds(50)); var stateStore = new KeyloggerStateStore(); stateStore.SetSettings(socket, settings); Assert.Equal(settings, stateStore.GetSettings(socket)); }