Example #1
0
        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 GetSockets()
        {
            var socket     = new Socket(1, "Test");
            var settings   = new KeyloggerSocketSettings(TimeSpan.FromSeconds(50));
            var stateStore = new KeyloggerStateStore();

            stateStore.SetSettings(socket, settings);

            var sockets = stateStore.GetSockets();

            Assert.Single(sockets);
            Assert.Equal(socket, sockets.First());
        }