private Collector(IOperatingSystem os, ICollectorLog collectorLog) { _os = os; _collectorLog = collectorLog; _currentProcess = os.GetCurrentProcessName(); _currentProcessStartTime = DateTime.UtcNow; _lastSave = DateTime.UtcNow; _millisecondsIdle = 0; }
public void RunOnce(IOperatingSystem os, ICollectorLog collectorLog) { DateTime now = DateTime.UtcNow; ulong milliseconds = os.GetMillisecondsSinceLastInput(); if (milliseconds > 15000) { _millisecondsIdle = milliseconds; } else { if (_millisecondsIdle != 0) { collectorLog.Log("Idle", GetTimeInSeconds(now)); _currentProcessStartTime = now; _millisecondsIdle = 0; return; } } string processName = os.GetCurrentProcessName(); if (processName != _currentProcess) { collectorLog.Log(_currentProcess, GetTimeInSeconds(now)); _currentProcess = processName; _currentProcessStartTime = now; } // Every 10 minutes save if (now.Subtract(_lastSave).TotalSeconds > _timeBetweenSending) { string log = _millisecondsIdle > 15000 ? "Idle" : _currentProcess; collectorLog.Log(log, GetTimeInSeconds(now)); _currentProcessStartTime = now; _lastSave = now; collectorLog.Send(now); } }