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 GetStatus_SetAndGet() { var socket = new Socket(1, "Test"); var stateStore = new KeyloggerStateStore(); stateStore.SetStatus(socket, PowerStatus.On); Assert.Equal(PowerStatus.On, stateStore.GetStatus(socket)); }