private void AnalyzePowerRequests(object sender, IdleScanAnalysis analysis) { string output = QueryPowerRequests(); var detectedRequests = new HashSet <string>(); foreach (string key in selectors.Keys) { foreach (string keyWord in selectors[key]) { if (output.IndexOf(keyWord, StringComparison.InvariantCultureIgnoreCase) >= 0) { string token = "((" + key + "))"; if (!analysis.BusyTokens.Contains(token)) { analysis.BusyTokens.Add(token); } if (keepAlive) { analysis.Busy = true; } } } } }
private void ScanHosts(object sender, IdleScanAnalysis analysis) { foreach (string host in hostsAwake.Union(hostsWatch)) { try { PingReply reply = ping.Send(host); if (reply.Status == IPStatus.Success) { if (hostsAwake.Contains(host)) { if (!analysis.BusyTokens.Contains(host)) { analysis.BusyTokens.Add(host); } analysis.Busy = true; } else { analysis.InfoTokens.Add(host); } } } catch (PingException) { } } }
private void OnBusy(object sender, IdleScanAnalysis analysis) { string tokens = string.Join(", ", analysis.BusyTokens.Where(t => !(t.StartsWith("((") && t.EndsWith("))")))); string reason = $"Kein Standby-Modus wegen: {tokens}"; if (Request?.Reason != reason) { Request?.Clear(); Request = new PowerRequest(reason); } }
private void OnIdle(object sender, IdleScanAnalysis analysis) { if (analysis.IdleCount > idleMax) { if (Context.DebugLog) { EventLog.WriteEntry("Computer idle", EventLogEntryType.Information, 5); } Win32API.EnterStandby(); } }
private void ScanSessions(object sender, IdleScanAnalysis analysis) { foreach (ITerminalServicesSession session in Component <TerminalServer>().Sessions) { if (session.ConnectionState == ConnectionState.Active) { if (session.IsRemoteConnected()) { analysis.BusyTokens.Add($"<{session.ClientName}\\{session.UserName}>"); analysis.Busy = true; } } } }
private void SavePowerRequests(object sender, IdleScanAnalysis analysis) { try { var now = DateTime.Now; string name = now.ToString("HHmm") + ".log"; string today = Path.Combine(requestsDir.FullName, now.ToString("yyyy-MM-dd")); string path = Path.Combine(today, name); Directory.CreateDirectory(today); File.AppendAllText(path, QueryPowerRequests()); } catch (Exception e) { EventLog.WriteEntry(e.ToString(), EventLogEntryType.Error); } }
private void QueryIdleTimers(object sender, IdleScanAnalysis analysis) { foreach (User user in users.Values) { if (user.IdleTime >= 0 && user.IdleTime < Context.Interval) { // Ist der Benutzer NICHT bereits über RDP angemeldet? if (!Component <TerminalServer>()[user.SID].IsRemoteConnected()) { analysis.BusyTokens.Add("<" + user.Name + ">"); } analysis.Busy = true; } } }
private void CheckLastSeen(object sender, IdleScanAnalysis analysis) { lock (lastSeen) { foreach (string host in lastSeen.Keys) { TimeSpan time = DateTime.Now - lastSeen[host]; if (time.TotalMilliseconds < Context.Interval) { if (!analysis.BusyTokens.Contains(host)) { analysis.BusyTokens.Add(host); } analysis.Busy = true; } } } }
private void OnIdle(object sender, IdleScanAnalysis analysis) { Request?.Clear(); Request = null; }