private void ProcessActiveHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.Started: case PowerSchedulerEventType.Elapsed: IPowerScheduler ps = GlobalServiceProvider.Instance.Get <IPowerScheduler>(); if (ps == null) { return; } PowerSetting setting = ps.Settings.GetSetting("Processes"); TvBusinessLayer layer = new TvBusinessLayer(); string processString = layer.GetSetting("PowerSchedulerProcesses").Value; List <string> processes = new List <string>(); foreach (string process in processString.Split(',')) { processes.Add(process.Trim()); } if (!IsEqual(processes, setting.Get <List <string> >())) { setting.Set <List <string> >(processes); _processes = processes; foreach (string process in processes) { Log.Debug("PowerScheduler: preventing standby for process: {0}", process); } } break; } }
private void NetworkMonitorHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { IPowerScheduler ps = GlobalServiceProvider.Instance.Get <IPowerScheduler>(); if (ps == null) { return; } TvBusinessLayer layer = new TvBusinessLayer(); PowerSetting setting; bool enabled; switch (args.EventType) { case PowerSchedulerEventType.Elapsed: // Check if standby should be prevented setting = ps.Settings.GetSetting("NetworkMonitorEnabled"); enabled = Convert.ToBoolean(layer.GetSetting("PowerSchedulerNetworkMonitorEnabled", "false").Value); if (setting.Get <bool>() != enabled) // Setting changed { setting.Set <bool>(enabled); if (enabled) // Start { Log.Debug("NetworkMonitorHandler: Network monitor started"); StartNetworkMonitor(); } else // Stop { Log.Debug("NetworkMonitorHandler: Network monitor stopped"); StopNetworkMonitor(); } } // Get minimum transferrate considered as network activity if (enabled) { setting = ps.Settings.GetSetting("NetworkMonitorIdleLimit"); _idleLimit = Int32.Parse(layer.GetSetting("PowerSchedulerNetworkMonitorIdleLimit", "2").Value); if (setting.Get <Int32>() != _idleLimit) { setting.Set <Int32>(_idleLimit); Log.Debug("NetworkMonitorHandler: Idle limit in KB/s: {0}", _idleLimit); } // Check if away mode should be used setting = ps.Settings.GetSetting("NetworkMonitorAwayMode"); _useAwayMode = Convert.ToBoolean(layer.GetSetting("PowerSchedulerNetworkMonitorAwayMode", "false").Value); if (setting.Get <bool>() != _useAwayMode) { setting.Set <bool>(_useAwayMode); Log.Debug("NetworkMonitorHandler: Use away mode: {0}", _useAwayMode); } } break; } }
private void ProcessActiveHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.Started: case PowerSchedulerEventType.Elapsed: _enabled = LoadSharesToMonitor(); break; } }
private void ProcessActiveHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.Started: case PowerSchedulerEventType.Elapsed: IPowerScheduler ps = GlobalServiceProvider.Instance.Get <IPowerScheduler>(); if (ps == null) { return; } PowerSetting setting = ps.Settings.GetSetting("Processes"); TvBusinessLayer layer = new TvBusinessLayer(); // Get processes to be monitored string processes = layer.GetSetting("PowerSchedulerProcesses").Value; // Split processes into processList elements List <string> processList = new List <string>(); foreach (string process in processes.Split(',')) { processList.Add(process.Trim()); } // If something has changed... if (!IsEqual(processList, setting.Get <List <string> >())) { setting.Set <List <string> >(processList); _processList = processList; Log.Debug("ProcessActiveHandler: Preventing standby for processes: {0}", processes); } // Check for MP client running? setting = ps.Settings.GetSetting("CheckForMPClientRunning"); _checkForMPClientRunning = Convert.ToBoolean(layer.GetSetting("PowerSchedulerCheckForMPClientRunning", "false").Value); if (setting.Get <bool>() != _checkForMPClientRunning) { setting.Set <bool>(_checkForMPClientRunning); Log.Debug("ProcessActiveHandler: Prevent standby when MP client is not running : {0}", _checkForMPClientRunning); } // Check if away mode should be used setting = ps.Settings.GetSetting("ProcessesAwayMode"); _useAwayMode = Convert.ToBoolean(layer.GetSetting("PowerSchedulerProcessesAwayMode", "false").Value); if (setting.Get <bool>() != _useAwayMode) { setting.Set <bool>(_useAwayMode); Log.Debug("ProcessActiveHandler: Use away mode: {0}", _useAwayMode); } break; } }
/// <summary> /// Handles PowerScheduler event messages. /// Used to keep track of changes to the idle timeout /// </summary> /// <param name="args">PowerSchedulerEventArgs for a specific message</param> private void GenericStandbyHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.SettingsChanged: PowerSettings settings = args.GetData<PowerSettings>(); if (settings != null) _timeout = settings.IdleTimeout; break; } }
/// <summary> /// Handles PowerScheduler event messages. /// Used to keep track of changes to the idle timeout /// </summary> /// <param name="args">PowerSchedulerEventArgs for a specific message</param> private void PowerControllerStandbyHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.SettingsChanged: PowerSettings settings = args.GetData<PowerSettings>(); if (settings != null) _timeout = settings.IdleTimeout; break; } }
private void PingMonitorHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.Started: case PowerSchedulerEventType.Elapsed: TvBusinessLayer layer = new TvBusinessLayer(); _enabled = Convert.ToBoolean(layer.GetSetting("PowerSchedulerPingMonitorEnabled", "false").Value); _useAwayMode = Convert.ToBoolean(layer.GetSetting("PowerSchedulerPingMonitorAwayMode", "false").Value); break; } }
private void ActivePortsHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.Started: case PowerSchedulerEventType.Elapsed: TvBusinessLayer layer = new TvBusinessLayer(); _enabled = Convert.ToBoolean(layer.GetSetting("PowerSchedulerActivePortsHandlerEnabled", "true").Value); _useAwayMode = Convert.ToBoolean(layer.GetSetting("PowerSchedulerActivePortsHandlerAwayMode", "false").Value); break; } }
/// <summary> /// Handles settings changed events /// </summary> /// <param name="args">PowerScheduler event arguments</param> private void ScheduledRecordingsHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.SettingsChanged: PowerSettings settings = args.GetData <PowerSettings>(); if (settings != null) { _idleTimeout = settings.IdleTimeout; } break; } }
private void ProcessActiveHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.Started: case PowerSchedulerEventType.Elapsed: IPowerScheduler ps = GlobalServiceProvider.Instance.Get<IPowerScheduler>(); if (ps == null) return; PowerSetting setting = ps.Settings.GetSetting("Processes"); TvBusinessLayer layer = new TvBusinessLayer(); // Get processes to be monitored string processes = layer.GetSetting("PowerSchedulerProcesses").Value; // Split processes into processList elements List<string> processList = new List<string>(); foreach (string process in processes.Split(',')) processList.Add(process.Trim()); // If something has changed... if (!IsEqual(processList, setting.Get<List<string>>())) { setting.Set<List<string>>(processList); _processList = processList; Log.Debug("ProcessActiveHandler: Preventing standby for processes: {0}", processes); } // Check for MP client running? setting = ps.Settings.GetSetting("CheckForMPClientRunning"); _checkForMPClientRunning = Convert.ToBoolean(layer.GetSetting("PowerSchedulerCheckForMPClientRunning", "false").Value); if (setting.Get<bool>() != _checkForMPClientRunning) { setting.Set<bool>(_checkForMPClientRunning); Log.Debug("ProcessActiveHandler: Prevent standby when MP client is not running : {0}", _checkForMPClientRunning); } // Check if away mode should be used setting = ps.Settings.GetSetting("ProcessesAwayMode"); _useAwayMode = Convert.ToBoolean(layer.GetSetting("PowerSchedulerProcessesAwayMode", "false").Value); if (setting.Get<bool>() != _useAwayMode) { setting.Set<bool>(_useAwayMode); Log.Debug("ProcessActiveHandler: Use away mode: {0}", _useAwayMode); } break; } }
private void ProcessActiveHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.Started: case PowerSchedulerEventType.Elapsed: IPowerScheduler ps = GlobalServiceProvider.Instance.Get <IPowerScheduler>(); if (ps == null) { return; } PowerSetting setting = ps.Settings.GetSetting("Processes"); using (Settings reader = new MPSettings()) { // Get processes to be monitored string processes = reader.GetValueAsString("psclientplugin", "Processes", String.Empty); // Split processes into processList elements List <string> processList = new List <string>(); foreach (string process in processes.Split(',')) { processList.Add(process.Trim()); } // If something has changed... if (!IsEqual(processList, setting.Get <List <string> >())) { setting.Set <List <string> >(processList); _processList = processList; Log.Debug("ProcessActiveHandler: Preventing standby for processes: {0}", processes); } // Check if away mode should be used setting = ps.Settings.GetSetting("ProcessesAwayMode"); _useAwayMode = reader.GetValueAsBool("psclientplugin", "ProcessesAwayMode", false); if (setting.Get <bool>() != _useAwayMode) { setting.Set <bool>(_useAwayMode); Log.Debug("ProcessActiveHandler: Use away mode: {0}", _useAwayMode); } break; } } }
private void NetworkMonitorHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.Started: case PowerSchedulerEventType.Elapsed: IPowerScheduler ps = GlobalServiceProvider.Instance.Get <IPowerScheduler>(); if (ps == null) { return; } TvBusinessLayer layer = new TvBusinessLayer(); PowerSetting setting; bool enabled; // Check if standby should be prevented setting = ps.Settings.GetSetting("NetworkMonitorEnabled"); enabled = Convert.ToBoolean(layer.GetSetting("NetworkMonitorEnabled", "false").Value); if (setting.Get <bool>() != enabled) // Setting changed { setting.Set <bool>(enabled); if (enabled) // Start { Log.Debug("NetworkMonitorHandler: networkMonitor started"); Thread netmonThr = new Thread(new ThreadStart(StartNetworkMonitor)); netmonThr.Start(); } else // Stop { Log.Debug("NetworkMonitorHandler: networkMonitor stopped"); StopNetworkMonitor(); } } if (enabled) // Get minimum transferrate considered as network activity { idleLimit = Int32.Parse(layer.GetSetting("NetworkMonitorIdleLimit", "2").Value); Log.Debug("NetworkMonitorHandler: idle limit in KB/s: {0}", idleLimit); } break; } }
private void ProcessActiveHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.Started: case PowerSchedulerEventType.Elapsed: IPowerScheduler ps = GlobalServiceProvider.Instance.Get<IPowerScheduler>(); if (ps == null) return; PowerSetting setting = ps.Settings.GetSetting("Processes"); using (Settings reader = new MPSettings()) { // Get processes to be monitored string processes = reader.GetValueAsString("psclientplugin", "Processes", String.Empty); // Split processes into processList elements List<string> processList = new List<string>(); foreach (string process in processes.Split(',')) processList.Add(process.Trim()); // If something has changed... if (!IsEqual(processList, setting.Get<List<string>>())) { setting.Set<List<string>>(processList); _processList = processList; Log.Debug("ProcessActiveHandler: Preventing standby for processes: {0}", processes); } // Check if away mode should be used setting = ps.Settings.GetSetting("ProcessesAwayMode"); _useAwayMode = reader.GetValueAsBool("psclientplugin", "ProcessesAwayMode", false); if (setting.Get<bool>() != _useAwayMode) { setting.Set<bool>(_useAwayMode); Log.Debug("ProcessActiveHandler: Use away mode: {0}", _useAwayMode); } break; } } }
/// <summary> /// Sends the given PowerSchedulerEventArgs to receivers /// </summary> /// <param name="args">PowerSchedulerEventArgs to send</param> private void SendPowerSchedulerEvent(PowerSchedulerEventArgs args) { SendPowerSchedulerEvent(args, true); }
private void SendPowerSchedulerEvent(PowerSchedulerEventType eventType, bool sendAsync) { PowerSchedulerEventArgs args = new PowerSchedulerEventArgs(eventType); SendPowerSchedulerEvent(args, sendAsync); }
private void EpgGrabbingHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.Started: case PowerSchedulerEventType.Elapsed: IPowerScheduler ps = GlobalServiceProvider.Instance.Get <IPowerScheduler>(); TvBusinessLayer layer = new TvBusinessLayer(); PowerSetting setting; bool enabled; // Check if standby should be prevented when grabbing EPG setting = ps.Settings.GetSetting("EPGPreventStandby"); enabled = Convert.ToBoolean(layer.GetSetting("PowerSchedulerEPGPreventStandby", "false").Value); if (setting.Get <bool>() != enabled) { setting.Set <bool>(enabled); if (enabled) { if (ps.IsRegistered(this as IStandbyHandler)) { ps.Unregister(this as IStandbyHandler); } ps.Register(this as IStandbyHandler); } else { ps.Unregister(this as IStandbyHandler); } Log.Debug("EpgGrabbingHandler: Preventing standby when grabbing EPG: {0}", enabled); } // Check if away mode should be used setting = ps.Settings.GetSetting("EPGAwayMode"); _useAwayMode = Convert.ToBoolean(layer.GetSetting("PowerSchedulerEPGAwayMode", "false").Value); if (setting.Get <bool>() != _useAwayMode) { setting.Set <bool>(_useAwayMode); Log.Debug("EpgGrabbingHandler: Use away mode: {0}", _useAwayMode); } // Check if system should wakeup for EPG grabs setting = ps.Settings.GetSetting("EPGWakeup"); enabled = Convert.ToBoolean(layer.GetSetting("PowerSchedulerEPGWakeup", "false").Value); if (setting.Get <bool>() != enabled) { setting.Set <bool>(enabled); if (enabled) { if (ps.IsRegistered(this as IWakeupHandler)) { ps.Unregister(this as IWakeupHandler); } ps.Register(this as IWakeupHandler); } else { ps.Unregister(this as IWakeupHandler); } Log.Debug("EpgGrabbingHandler: Wakeup system for EPG grabbing: {0}", enabled ? "enabled" : "disabled"); } // Check if a wakeup time is set setting = ps.Settings.GetSetting("EPGWakeupConfig"); EPGWakeupConfig config = new EPGWakeupConfig((layer.GetSetting("PowerSchedulerEPGWakeupConfig", String.Empty).Value)); if (!config.Equals(setting.Get <EPGWakeupConfig>())) { setting.Set <EPGWakeupConfig>(config); Log.Debug("EpgGrabbingHandler: EPG grabbing at {0:00}:{1:00}", config.Hour, config.Minutes); if (config.Days != null) { String days = ""; foreach (EPGGrabDays day in config.Days) { if (days == "") { days = day.ToString(); } else { days = days + ", " + day.ToString(); } } Log.Debug("EpgGrabbingHandler: EPG grabbing on: {0}", days); } Log.Debug("EpgGrabbingHandler: EPG last run was at {0}", config.LastRun); } // check if schedule is due // check if we've already run today if (ShouldRunNow() && !_epgThreadRunning) { // kick off EPG thread _epgThreadRunning = true; Thread workerThread = new Thread(new ThreadStart(EPGThreadFunction)); workerThread.Name = "EPG Grabbing Handler"; workerThread.IsBackground = true; workerThread.Priority = ThreadPriority.Lowest; workerThread.Start(); } // Cleanup of expired grabber sources // A grabber is said to be expired, when its timeout has passed and there is no valid wakeup time // However, when the timeout has passed, the alow-standby flag is set true List <object> expired = new List <object>(); foreach (object o in _extGrabbers.Keys) { GrabberSource s = _extGrabbers[o]; if (s.Timeout < DateTime.Now) { Log.Debug("EpgGrabbingHandler: EPG source '{0}' timed out, setting allow-standby = true for this source.", s.Name); // timeout passed, standby is allowed s.SetStandbyAllowed(true, 0); // no valid wakeup-time -> expired if (s.NextWakeupTime == DateTime.MaxValue) { expired.Add(o); } } } foreach (object o in expired) { _extGrabbers.Remove(o); } expired = null; break; } }
private void ProcessActiveHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.Started: case PowerSchedulerEventType.Elapsed: IPowerScheduler ps = GlobalServiceProvider.Instance.Get <IPowerScheduler>(); if (ps == null) { return; } PowerSetting setting; TvBusinessLayer layer = new TvBusinessLayer(); // Load share monitoring configuration for standby prevention setting = ps.Settings.GetSetting("ActiveSharesEnabled"); _enabled = Convert.ToBoolean(layer.GetSetting("PowerSchedulerActiveSharesEnabled", "false").Value); if (setting.Get <bool>() != _enabled) { setting.Set <bool>(_enabled); Log.Debug("ActiveSharesHandler: Monitoring active shares {0}", _enabled ? "enabled" : "disabled"); } if (_enabled) { setting = ps.Settings.GetSetting("ActiveShares"); string _connections = Convert.ToString(layer.GetSetting("PowerSchedulerActiveShares", "").Value); if (setting.Get <string>() != _connections) { setting.Set <string>(_connections); _sharesToMonitor.Clear(); string[] shares = _connections.Split(';'); foreach (string share in shares) { string[] shareItem = share.Split(','); if ((shareItem.Length.Equals(3)) && ((shareItem[0].Trim().Length > 0) || (shareItem[1].Trim().Length > 0) || (shareItem[2].Trim().Length > 0))) { _sharesToMonitor.Add(new ShareMonitor(shareItem[0], shareItem[1], shareItem[2])); } } if (_sharesToMonitor.Count == 0) { _sharesToMonitor.Add(new ShareMonitor("", "", "")); } } } // Check if away mode should be used setting = ps.Settings.GetSetting("ActiveSharesAwayMode"); _useAwayMode = Convert.ToBoolean(layer.GetSetting("PowerSchedulerActiveSharesAwayMode", "false").Value); if (setting.Get <bool>() != _useAwayMode) { setting.Set <bool>(_useAwayMode); Log.Debug("ActiveSharesHandler: Use away mode: {0}", _useAwayMode); } break; } }
/// <summary> /// Handles settings changed events /// </summary> /// <param name="args">PowerScheduler event arguments</param> private void ScheduledRecordingsHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.SettingsChanged: PowerSettings settings = args.GetData<PowerSettings>(); if (settings != null) { _idleTimeout = settings.IdleTimeout; } break; } }
private void ProcessActiveHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.Started: case PowerSchedulerEventType.Elapsed: IPowerScheduler ps = GlobalServiceProvider.Instance.Get<IPowerScheduler>(); if (ps == null) return; PowerSetting setting; using (Settings reader = new MPSettings()) { // Load share monitoring configuration for standby prevention setting = ps.Settings.GetSetting("ActiveSharesEnabled"); _enabled = reader.GetValueAsBool("psclientplugin", "ActiveSharesEnabled", false); if (setting.Get<bool>() != _enabled) { setting.Set<bool>(_enabled); Log.Debug("ActiveSharesHandler: Monitoring active shares {0}", _enabled ? "enabled" : "disabled"); } if (_enabled) { setting = ps.Settings.GetSetting("ActiveShares"); string _connections = reader.GetValueAsString("psclientplugin", "ActiveShares", ""); if (setting.Get<string>() != _connections) { setting.Set<string>(_connections); _sharesToMonitor.Clear(); string[] shares = _connections.Split(';'); foreach (string share in shares) { string[] shareItem = share.Split(','); if ((shareItem.Length.Equals(3)) && ((shareItem[0].Trim().Length > 0) || (shareItem[1].Trim().Length > 0) || (shareItem[2].Trim().Length > 0))) { _sharesToMonitor.Add(new ShareMonitor(shareItem[0], shareItem[1], shareItem[2])); } } if (_sharesToMonitor.Count == 0) _sharesToMonitor.Add(new ShareMonitor("", "", "")); } } // Check if away mode should be used setting = ps.Settings.GetSetting("ActiveSharesAwayMode"); _useAwayMode = reader.GetValueAsBool("psclientplugin", "ActiveSharesAwayMode", false); if (setting.Get<bool>() != _useAwayMode) { setting.Set<bool>(_useAwayMode); Log.Debug("ActiveSharesHandler: Use away mode: {0}", _useAwayMode); } } break; } }
private void NetworkMonitorHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { IPowerScheduler ps = GlobalServiceProvider.Instance.Get<IPowerScheduler>(); if (ps == null) return; PowerSetting setting; bool enabled; switch (args.EventType) { case PowerSchedulerEventType.Elapsed: using (Settings reader = new MPSettings()) { // Check if standby should be prevented setting = ps.Settings.GetSetting("NetworkMonitorEnabled"); enabled = reader.GetValueAsBool("psclientplugin", "NetworkMonitorEnabled", false); if (setting.Get<bool>() != enabled) // Setting changed { setting.Set<bool>(enabled); if (enabled) // Start { Log.Debug("NetworkMonitorHandler: Network monitor started"); StartNetworkMonitor(); } else // Stop { Log.Debug("NetworkMonitorHandler: Network monitor stopped"); StopNetworkMonitor(); } } // Get minimum transferrate considered as network activity if (enabled) { setting = ps.Settings.GetSetting("NetworkMonitorIdleLimit"); _idleLimit = reader.GetValueAsInt("psclientplugin", "NetworkMonitorIdleLimit", 0); if (setting.Get<Int32>() != _idleLimit) { setting.Set<Int32>(_idleLimit); Log.Debug("NetworkMonitorHandler: Idle limit in KB/s: {0}", _idleLimit); } // Check if away mode should be used setting = ps.Settings.GetSetting("NetworkMonitorAwayMode"); _useAwayMode = reader.GetValueAsBool("psclientplugin", "NetworkMonitorAwayMode", false); if (setting.Get<bool>() != _useAwayMode) { setting.Set<bool>(_useAwayMode); Log.Debug("NetworkMonitorHandler: Use away mode: {0}", _useAwayMode); } } } break; } }
/// <summary> /// Loads the standby configuration /// </summary> private void LoadSettings() { bool changed = false; bool boolSetting; int intSetting; string stringSetting; PowerSetting powerSetting; Log.Debug("PS: LoadSettings()"); TvBusinessLayer layer = new TvBusinessLayer(); // Load initial settings only once if (_settings == null) { // Check if update of old PS settings is necessary Setting setting = layer.GetSetting("PowerSchedulerExpertMode"); if (setting.Value == "") { setting.Remove(); // Initialise list of old and new settings to update List<String[]> settingNames = new List<String[]>(); settingNames.Add(new String[] { "PreventStandybyWhenSpecificSharesInUse", "PowerSchedulerActiveShares" }); settingNames.Add(new String[] { "PreventStandybyWhenSharesInUse", "PowerSchedulerActiveSharesEnabled" }); settingNames.Add(new String[] { "PowerSchedulerEpgCommand", "PowerSchedulerEPGCommand" }); settingNames.Add(new String[] { "PreventStandbyWhenGrabbingEPG", "PowerSchedulerEPGPreventStandby" }); settingNames.Add(new String[] { "WakeupSystemForEPGGrabbing", "PowerSchedulerEPGWakeup" }); settingNames.Add(new String[] { "EPGWakeupConfig", "PowerSchedulerEPGWakeupConfig" }); settingNames.Add(new String[] { "NetworkMonitorEnabled", "PowerSchedulerNetworkMonitorEnabled" }); settingNames.Add(new String[] { "NetworkMonitorIdleLimit", "PowerSchedulerNetworkMonitorIdleLimit" }); settingNames.Add(new String[] { "PowerSchedulerPreNoShutdownTime", "PowerSchedulerPreNoStandbyTime" }); settingNames.Add(new String[] { "PowerSchedulerShutdownActive", "PowerSchedulerShutdownEnabled" }); settingNames.Add(new String[] { "PowerSchedulerStandbyAllowedStart", "PowerSchedulerStandbyHoursFrom" }); settingNames.Add(new String[] { "PowerSchedulerStandbyAllowedEnd", "PowerSchedulerStandbyHoursTo" }); // Update settings names foreach (String[] settingName in settingNames) { setting = layer.GetSetting(settingName[0], "---"); if (setting.Value != "---") { setting.Tag = settingName[1]; setting.Persist(); } else { setting.Remove(); } } } _settings = new PowerSettings(); changed = true; // Set constant values (needed for backward compatibility) _settings.ForceShutdown = false; _settings.ExtensiveLogging = false; _settings.CheckInterval = 15; } // Check if PowerScheduler should actively put the system into standby boolSetting = Convert.ToBoolean(layer.GetSetting("PowerSchedulerShutdownEnabled", "false").Value); if (_settings.ShutdownEnabled != boolSetting) { _settings.ShutdownEnabled = boolSetting; Log.Debug("PS: PowerScheduler forces system to go to standby when idle: {0}", boolSetting); changed = true; } if (_settings.ShutdownEnabled) { // Check configured shutdown mode intSetting = Int32.Parse(layer.GetSetting("PowerSchedulerShutdownMode", "0").Value); if ((int)_settings.ShutdownMode != intSetting) { _settings.ShutdownMode = (ShutdownMode)intSetting; Log.Debug("PS: Shutdown mode: {0}", _settings.ShutdownMode.ToString()); changed = true; } } // Get idle timeout if (_settings.ShutdownEnabled) intSetting = Int32.Parse(layer.GetSetting("PowerSchedulerIdleTimeout", "30").Value); else intSetting = (int)PowerManager.GetActivePowerSetting(PowerManager.SystemPowerSettingType.STANDBYIDLE) / 60; if (_settings.IdleTimeout != intSetting) { _settings.IdleTimeout = intSetting; Log.Debug("PS: {0}: {1} minutes", (_settings.ShutdownEnabled ? "Standby after" : "System idle timeout"), intSetting); changed = true; } // Check configured pre-wakeup time intSetting = Int32.Parse(layer.GetSetting("PowerSchedulerPreWakeupTime", "60").Value); if (_settings.PreWakeupTime != intSetting) { _settings.PreWakeupTime = intSetting; Log.Debug("PS: Pre-wakeup time: {0} seconds", intSetting); changed = true; } // Check configured pre-no-standby time intSetting = Int32.Parse(layer.GetSetting("PowerSchedulerPreNoStandbyTime", "300").Value); if (_settings.PreNoShutdownTime != intSetting) { _settings.PreNoShutdownTime = intSetting; Log.Debug("PS: Pre-no-standby time: {0} seconds", intSetting); changed = true; } // Check allowed start time intSetting = Int32.Parse(layer.GetSetting("PowerSchedulerStandbyHoursFrom", "0").Value); if (_settings.AllowedSleepStartTime != intSetting) { _settings.AllowedSleepStartTime = intSetting; Log.Debug("PS: Standby allowed from {0} o' clock", _settings.AllowedSleepStartTime); changed = true; } // Check allowed stop time intSetting = Int32.Parse(layer.GetSetting("PowerSchedulerStandbyHoursTo", "24").Value); if (_settings.AllowedSleepStopTime != intSetting) { _settings.AllowedSleepStopTime = intSetting; Log.Debug("PS: Standby allowed until {0} o' clock", _settings.AllowedSleepStopTime); changed = true; } // Check allowed start time on weekend intSetting = Int32.Parse(layer.GetSetting("PowerSchedulerStandbyHoursOnWeekendFrom", "0").Value); if (_settings.AllowedSleepStartTimeOnWeekend != intSetting) { _settings.AllowedSleepStartTimeOnWeekend = intSetting; Log.Debug("PS: Standby allowed from {0} o' clock on weekend", _settings.AllowedSleepStartTimeOnWeekend); changed = true; } // Check allowed stop time on weekend intSetting = Int32.Parse(layer.GetSetting("PowerSchedulerStandbyHoursOnWeekendTo", "24").Value); if (_settings.AllowedSleepStopTimeOnWeekend != intSetting) { _settings.AllowedSleepStopTimeOnWeekend = intSetting; Log.Debug("PS: Standby allowed until {0} o' clock on weekend", _settings.AllowedSleepStopTimeOnWeekend); changed = true; } // Check if PowerScheduler should wakeup the system automatically intSetting = Int32.Parse(layer.GetSetting("PowerSchedulerProfile", "0").Value); if (intSetting == 2) boolSetting = false; // Notebook else boolSetting = true; // HTPC, Desktop, Server if (_settings.WakeupEnabled != boolSetting) { _settings.WakeupEnabled = boolSetting; Log.Debug("PS: Wakeup system for varios events: {0}", boolSetting); changed = true; } // Check if PowerScheduler should reinitialize the TVService after wakeup boolSetting = Convert.ToBoolean(layer.GetSetting("PowerSchedulerReinitializeController", "false").Value); if (_settings.ReinitializeController != boolSetting) { _settings.ReinitializeController = boolSetting; Log.Debug("PS: Reinitialize TVService on wakeup: {0}", boolSetting); changed = true; } // Get external command powerSetting = _settings.GetSetting("Command"); stringSetting = layer.GetSetting("PowerSchedulerCommand", String.Empty).Value; if (!stringSetting.Equals(powerSetting.Get<string>())) { powerSetting.Set<string>(stringSetting); Log.Debug("PS: Run command on power state change: {0}", stringSetting); changed = true; } // Send message in case any setting has changed if (changed) { PowerSchedulerEventArgs args = new PowerSchedulerEventArgs(PowerSchedulerEventType.SettingsChanged); args.SetData<PowerSettings>(_settings.Clone()); SendPowerSchedulerEvent(args); } }
private void EpgGrabbingHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.Started: case PowerSchedulerEventType.Elapsed: IPowerScheduler ps = GlobalServiceProvider.Instance.Get<IPowerScheduler>(); TvBusinessLayer layer = new TvBusinessLayer(); PowerSetting setting; bool enabled; // Check if standby should be prevented when grabbing EPG setting = ps.Settings.GetSetting("EPGPreventStandby"); enabled = Convert.ToBoolean(layer.GetSetting("PowerSchedulerEPGPreventStandby", "false").Value); if (setting.Get<bool>() != enabled) { setting.Set<bool>(enabled); if (enabled) { if (ps.IsRegistered(this as IStandbyHandler)) ps.Unregister(this as IStandbyHandler); ps.Register(this as IStandbyHandler); } else { ps.Unregister(this as IStandbyHandler); } Log.Debug("EpgGrabbingHandler: Preventing standby when grabbing EPG: {0}", enabled); } // Check if away mode should be used setting = ps.Settings.GetSetting("EPGAwayMode"); _useAwayMode = Convert.ToBoolean(layer.GetSetting("PowerSchedulerEPGAwayMode", "false").Value); if (setting.Get<bool>() != _useAwayMode) { setting.Set<bool>(_useAwayMode); Log.Debug("EpgGrabbingHandler: Use away mode: {0}", _useAwayMode); } // Check if system should wakeup for EPG grabs setting = ps.Settings.GetSetting("EPGWakeup"); enabled = Convert.ToBoolean(layer.GetSetting("PowerSchedulerEPGWakeup", "false").Value); if (setting.Get<bool>() != enabled) { setting.Set<bool>(enabled); if (enabled) { if (ps.IsRegistered(this as IWakeupHandler)) ps.Unregister(this as IWakeupHandler); ps.Register(this as IWakeupHandler); } else { ps.Unregister(this as IWakeupHandler); } Log.Debug("EpgGrabbingHandler: Wakeup system for EPG grabbing: {0}", enabled ? "enabled" : "disabled"); } // Check if a wakeup time is set setting = ps.Settings.GetSetting("EPGWakeupConfig"); EPGWakeupConfig config = new EPGWakeupConfig((layer.GetSetting("PowerSchedulerEPGWakeupConfig", String.Empty).Value)); if (!config.Equals(setting.Get<EPGWakeupConfig>())) { setting.Set<EPGWakeupConfig>(config); Log.Debug("EpgGrabbingHandler: EPG grabbing at {0:00}:{1:00}", config.Hour, config.Minutes); if (config.Days != null) { String days = ""; foreach (EPGGrabDays day in config.Days) { if (days == "") days = day.ToString(); else days = days + ", " + day.ToString(); } Log.Debug("EpgGrabbingHandler: EPG grabbing on: {0}", days); } Log.Debug("EpgGrabbingHandler: EPG last run was at {0}", config.LastRun); } // check if schedule is due // check if we've already run today if (ShouldRunNow() && !_epgThreadRunning) { // kick off EPG thread _epgThreadRunning = true; Thread workerThread = new Thread(new ThreadStart(EPGThreadFunction)); workerThread.Name = "EPG Grabbing Handler"; workerThread.IsBackground = true; workerThread.Priority = ThreadPriority.Lowest; workerThread.Start(); } // Cleanup of expired grabber sources // A grabber is said to be expired, when its timeout has passed and there is no valid wakeup time // However, when the timeout has passed, the alow-standby flag is set true List<object> expired = new List<object>(); foreach (object o in _extGrabbers.Keys) { GrabberSource s = _extGrabbers[o]; if (s.Timeout < DateTime.Now) { Log.Debug("EpgGrabbingHandler: EPG source '{0}' timed out, setting allow-standby = true for this source.", s.Name); // timeout passed, standby is allowed s.SetStandbyAllowed(true, 0); // no valid wakeup-time -> expired if (s.NextWakeupTime == DateTime.MaxValue) expired.Add(o); } } foreach (object o in expired) _extGrabbers.Remove(o); expired = null; break; } }
private void NetworkMonitorHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { IPowerScheduler ps = GlobalServiceProvider.Instance.Get <IPowerScheduler>(); if (ps == null) { return; } PowerSetting setting; bool enabled; switch (args.EventType) { case PowerSchedulerEventType.Elapsed: using (Settings reader = new MPSettings()) { // Check if standby should be prevented setting = ps.Settings.GetSetting("NetworkMonitorEnabled"); enabled = reader.GetValueAsBool("psclientplugin", "NetworkMonitorEnabled", false); if (setting.Get <bool>() != enabled) // Setting changed { setting.Set <bool>(enabled); if (enabled) // Start { Log.Debug("NetworkMonitorHandler: Network monitor started"); StartNetworkMonitor(); } else // Stop { Log.Debug("NetworkMonitorHandler: Network monitor stopped"); StopNetworkMonitor(); } } // Get minimum transferrate considered as network activity if (enabled) { setting = ps.Settings.GetSetting("NetworkMonitorIdleLimit"); _idleLimit = reader.GetValueAsInt("psclientplugin", "NetworkMonitorIdleLimit", 0); if (setting.Get <Int32>() != _idleLimit) { setting.Set <Int32>(_idleLimit); Log.Debug("NetworkMonitorHandler: Idle limit in KB/s: {0}", _idleLimit); } // Check if away mode should be used setting = ps.Settings.GetSetting("NetworkMonitorAwayMode"); _useAwayMode = reader.GetValueAsBool("psclientplugin", "NetworkMonitorAwayMode", false); if (setting.Get <bool>() != _useAwayMode) { setting.Set <bool>(_useAwayMode); Log.Debug("NetworkMonitorHandler: Use away mode: {0}", _useAwayMode); } } } break; } }
/// <summary> /// Sends the given PowerSchedulerEventArgs to receivers /// </summary> /// <param name="args">PowerSchedulerEventArgs to send</param> /// <param name="sendAsync">bool indicating whether or not to send it asynchronously</param> private void SendPowerSchedulerEvent(PowerSchedulerEventArgs args, bool sendAsync) { if (OnPowerSchedulerEvent == null) return; lock (OnPowerSchedulerEvent) { if (OnPowerSchedulerEvent == null) return; if (sendAsync) { OnPowerSchedulerEvent(args); } else { foreach (Delegate del in OnPowerSchedulerEvent.GetInvocationList()) { PowerSchedulerEventHandler handler = del as PowerSchedulerEventHandler; handler(args); } } } }
/// <summary> /// Loads the standby configuration /// </summary> private void LoadSettings() { bool changed = false; bool boolSetting; int intSetting; string stringSetting; PowerSetting powerSetting; Log.Debug("PS: LoadSettings()"); // Load initial settings only once if (_settings == null) { using (Settings reader = new MPSettings()) { // Check if update of old PS settings is necessary if (reader.GetValue("psclientplugin", "ExpertMode") == "") { // Initialise list of old and new settings names to update List<String[]> settingNames = new List<String[]>(); settingNames.Add(new String[] { "homeonly", "HomeOnly" }); settingNames.Add(new String[] { "idletimeout", "IdleTimeout" }); settingNames.Add(new String[] { "shutdownenabled", "ShutdownEnabled" }); settingNames.Add(new String[] { "shutdownmode", "ShutdownMode" }); // Update settings names foreach (String[] settingName in settingNames) { String settingValue = reader.GetValue("psclientplugin", settingName[0]); if (settingValue != "") { reader.RemoveEntry("psclientplugin", settingName[0]); reader.SetValue("psclientplugin", settingName[1], settingValue); } } } _settings = new PowerSettings(); changed = true; // Set constant values (needed for backward compatibility) _settings.ForceShutdown = false; _settings.ExtensiveLogging = false; _settings.PreNoShutdownTime = 300; _settings.CheckInterval = 15; // Check if we only should suspend in MP's home window boolSetting = reader.GetValueAsBool("psclientplugin", "HomeOnly", false); powerSetting = _settings.GetSetting("HomeOnly"); powerSetting.Set<bool>(boolSetting); Log.Debug("PS: Only allow standby when on home window: {0}", boolSetting); // Get external command stringSetting = reader.GetValueAsString("psclientplugin", "Command", String.Empty); powerSetting = _settings.GetSetting("Command"); powerSetting.Set<string>(stringSetting); Log.Debug("PS: Run command on power state change: {0}", stringSetting); // Check if we should unmute the master volume boolSetting = reader.GetValueAsBool("psclientplugin", "UnmuteMasterVolume", true); powerSetting = _settings.GetSetting("UnmuteMasterVolume"); powerSetting.Set<bool>(boolSetting); Log.Debug("PS: Unmute master volume: {0}", boolSetting); // Detect single-seat string tvPluginDll = Config.GetSubFolder(Config.Dir.Plugins, "windows") + @"\" + "TvPlugin.dll"; if (File.Exists(tvPluginDll)) { string hostName = reader.GetValueAsString("tvservice", "hostname", String.Empty); if (hostName != String.Empty && PowerManager.IsLocal(hostName)) { _singleSeat = true; Log.Info("PS: Detected single-seat setup - TV-Server on local system"); } else if (hostName == String.Empty) { _singleSeat = false; Log.Info("PS: Detected standalone client setup - no TV-Server configured"); } else { _singleSeat = false; Log.Info("PS: Detected remote client setup - TV-Server on \"{0}\"", hostName); RemotePowerControl.HostName = hostName; Log.Debug("PS: Set RemotePowerControl.HostName: {0}", hostName); } } else { _singleSeat = false; Log.Info("PS: Detected standalone client setup - no TV-Plugin installed"); } // Standalone client has local standby / wakeup settings if (!_singleSeat) { // Check if PowerScheduler should actively put the system into standby boolSetting = reader.GetValueAsBool("psclientplugin", "ShutdownEnabled", false); _settings.ShutdownEnabled = boolSetting; Log.Debug("PS: PowerScheduler forces system to go to standby when idle: {0}", boolSetting); if (_settings.ShutdownEnabled) { // Check configured shutdown mode intSetting = reader.GetValueAsInt("psclientplugin", "ShutdownMode", 0); _settings.ShutdownMode = (ShutdownMode)intSetting; Log.Debug("PS: Shutdown mode: {0}", _settings.ShutdownMode.ToString()); } // Get idle timeout if (_settings.ShutdownEnabled) { intSetting = reader.GetValueAsInt("psclientplugin", "IdleTimeout", 30); _settings.IdleTimeout = intSetting; Log.Debug("PS: Standby after: {0} minutes", intSetting); } // Check configured pre-wakeup time (can only be configured by editing MediaPortal.xml) intSetting = reader.GetValueAsInt("psclientplugin", "PreWakeupTime", 60); _settings.PreWakeupTime = intSetting; Log.Debug("PS: Pre-wakeup time: {0} seconds", intSetting); // Check configured pre-no-standby time (can only be configured by editing MediaPortal.xml) intSetting = reader.GetValueAsInt("psclientplugin", "PreNoStandbyTime", 300); _settings.PreNoShutdownTime = intSetting; Log.Debug("PS: Pre-no-standby time: {0} seconds", intSetting); // Check if PowerScheduler should wakeup the system automatically intSetting = reader.GetValueAsInt("psclientplugin", "Profile", 0); if (intSetting == 2) boolSetting = false; // Notebook else boolSetting = true; // HTPC, Desktop _settings.WakeupEnabled = boolSetting; Log.Debug("PS: Wakeup system for various events: {0}", boolSetting); } } } // (Re-)Load settings every check interval if (_singleSeat) { // Connect to local tvservice (RemotePowerControl) if (RemotePowerControl.Instance != null && RemotePowerControl.Isconnected) { // Check if PowerScheduler should actively put the system into standby boolSetting = RemotePowerControl.Instance.PowerSettings.ShutdownEnabled; if (_settings.ShutdownEnabled != boolSetting) { _settings.ShutdownEnabled = boolSetting; Log.Debug("PS: Server plugin setting - PowerScheduler forces system to go to standby when idle: {0}", boolSetting); changed = true; } if (_settings.ShutdownEnabled) { // Get configured shutdown mode from local tvservice intSetting = (int)RemotePowerControl.Instance.PowerSettings.ShutdownMode; if ((int)_settings.ShutdownMode != intSetting) { _settings.ShutdownMode = (ShutdownMode)intSetting; Log.Debug("PS: Server plugin setting - Shutdown mode: {0}", _settings.ShutdownMode.ToString()); changed = true; } } // Get idle timeout from local tvservice intSetting = RemotePowerControl.Instance.PowerSettings.IdleTimeout; if (_settings.IdleTimeout != intSetting) { _settings.IdleTimeout = intSetting; Log.Debug("PS: Server plugin setting - {0}: {1} minutes", (_settings.ShutdownEnabled ? "Standby after" : "System idle timeout"), intSetting); changed = true; } // Get configured pre-wakeup time from local tvservice intSetting = RemotePowerControl.Instance.PowerSettings.PreWakeupTime; if (_settings.PreWakeupTime != intSetting) { _settings.PreWakeupTime = intSetting; Log.Debug("PS: Pre-wakeup time: {0} seconds", intSetting); changed = true; } // Check if PowerScheduler should wakeup the system automatically boolSetting = RemotePowerControl.Instance.PowerSettings.WakeupEnabled; if (_settings.WakeupEnabled != boolSetting) { _settings.WakeupEnabled = boolSetting; Log.Debug("PS: Server plugin setting - Wakeup system for various events: {0}", boolSetting); changed = true; } } else { Log.Error("PS: Cannot connect to local tvservice to load settings"); } } else { // Get active idle timeout for standalone client if standby is handled by Windows if (!_settings.ShutdownEnabled) { intSetting = (int)PowerManager.GetActivePowerSetting(PowerManager.SystemPowerSettingType.STANDBYIDLE) / 60; if (_settings.IdleTimeout != intSetting) { _settings.IdleTimeout = intSetting; Log.Debug("PS: System idle timeout: {0} minutes", intSetting); changed = true; } } } // Send message in case any setting has changed if (changed) { PowerSchedulerEventArgs args = new PowerSchedulerEventArgs(PowerSchedulerEventType.SettingsChanged); args.SetData<PowerSettings>(_settings.Clone()); SendPowerSchedulerEvent(args); } }
/// <summary> /// Refreshes the standby configuration /// </summary> private void LoadSettings() { int setting; bool changed = false; if (_settings == null) _settings = new PowerSettings(); TvBusinessLayer layer = new TvBusinessLayer(); // Check if PowerScheduler should log verbose debug messages if (_settings.ExtensiveLogging != Convert.ToBoolean(layer.GetSetting("PowerSchedulerExtensiveLogging", "false").Value)) { _settings.ExtensiveLogging = !_settings.ExtensiveLogging; Log.Debug("PowerScheduler: extensive logging enabled: {0}", _settings.ExtensiveLogging); changed = true; } // Check if PowerScheduler should actively put the system into standby if (_settings.ShutdownEnabled != Convert.ToBoolean(layer.GetSetting("PowerSchedulerShutdownActive", "false").Value)) { _settings.ShutdownEnabled = !_settings.ShutdownEnabled; LogVerbose("PowerScheduler: entering standby is enabled: {0}", _settings.ShutdownEnabled); changed = true; } // Check if PowerScheduler should wakeup the system automatically if (_settings.WakeupEnabled != Convert.ToBoolean(layer.GetSetting("PowerSchedulerWakeupActive", "false").Value)) { _settings.WakeupEnabled = !_settings.WakeupEnabled; LogVerbose("PowerScheduler: automatic wakeup is enabled: {0}", _settings.WakeupEnabled); changed = true; } // Check if PowerScheduler should force the system into suspend/hibernate if (_settings.ForceShutdown != Convert.ToBoolean(layer.GetSetting("PowerSchedulerForceShutdown", "false").Value)) { _settings.ForceShutdown = !_settings.ForceShutdown; LogVerbose("PowerScheduler: force shutdown enabled: {0}", _settings.ForceShutdown); changed = true; } // Check if PowerScheduler should reinitialize the TVController after wakeup if (_settings.ReinitializeController != Convert.ToBoolean(layer.GetSetting("PowerSchedulerReinitializeController", "false").Value)) { _settings.ReinitializeController = !_settings.ReinitializeController; LogVerbose("PowerScheduler: Reinitialize controller on wakeup: {0}", _settings.ReinitializeController); changed = true; } PowerSetting pSetting = _settings.GetSetting("ExternalCommand"); string sSetting = layer.GetSetting("PowerSchedulerCommand", String.Empty).Value; if (!sSetting.Equals(pSetting.Get<string>())) { pSetting.Set<string>(sSetting); LogVerbose("PowerScheduler: Run external command before standby / after resume: {0}", sSetting); changed = true; } // Check configured PowerScheduler idle timeout setting = Int32.Parse(layer.GetSetting("PowerSchedulerIdleTimeout", "5").Value); if (_settings.IdleTimeout != setting) { _settings.IdleTimeout = setting; LogVerbose("PowerScheduler: idle timeout set to: {0} minutes", _settings.IdleTimeout); changed = true; } // Check configured pre-wakeup time setting = Int32.Parse(layer.GetSetting("PowerSchedulerPreWakeupTime", "60").Value); if (_settings.PreWakeupTime != setting) { _settings.PreWakeupTime = setting; LogVerbose("PowerScheduler: pre-wakeup time set to: {0} seconds", _settings.PreWakeupTime); changed = true; } // Check configured pre-no-shutdown time setting = Int32.Parse(layer.GetSetting("PowerSchedulerPreNoShutdownTime", "120").Value); if (_settings.PreNoShutdownTime != setting) { _settings.PreNoShutdownTime = setting; LogVerbose("PowerScheduler: pre-no-shutdown time set to: {0} seconds", _settings.PreNoShutdownTime); changed = true; } // Check if check interval needs to be updated setting = Int32.Parse(layer.GetSetting("PowerSchedulerCheckInterval", "60").Value); if (_settings.CheckInterval != setting) { _settings.CheckInterval = setting; LogVerbose("PowerScheduler: Check interval set to {0} seconds", _settings.CheckInterval); _reloadInterval = setting; changed = true; } // Check configured shutdown mode setting = Int32.Parse(layer.GetSetting("PowerSchedulerShutdownMode", "2").Value); if ((int)_settings.ShutdownMode != setting) { _settings.ShutdownMode = (ShutdownMode)setting; LogVerbose("PowerScheduler: Shutdown mode set to {0}", _settings.ShutdownMode); changed = true; } // Check allowed stop time setting = Int32.Parse(layer.GetSetting("PowerSchedulerStandbyAllowedEnd", "24").Value); if (_settings.AllowedSleepStopTime != setting) { _settings.AllowedSleepStopTime = setting; LogVerbose("PowerScheduler: Standby allowed until {0} o' clock", _settings.AllowedSleepStopTime); changed = true; } // Check configured allowed start time setting = Int32.Parse(layer.GetSetting("PowerSchedulerStandbyAllowedStart", "0").Value); if (_settings.AllowedSleepStartTime != setting) { _settings.AllowedSleepStartTime = setting; LogVerbose("PowerScheduler: Standby allowed starting at {0} o' clock", _settings.AllowedSleepStartTime); changed = true; } // Send message in case any setting has changed if (changed) { PowerSchedulerEventArgs args = new PowerSchedulerEventArgs(PowerSchedulerEventType.SettingsChanged); args.SetData<PowerSettings>(_settings.Clone()); SendPowerSchedulerEvent(args); } }
private void NetworkMonitorHandler_OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { IPowerScheduler ps = GlobalServiceProvider.Instance.Get<IPowerScheduler>(); if (ps == null) return; TvBusinessLayer layer = new TvBusinessLayer(); PowerSetting setting; bool enabled; switch (args.EventType) { case PowerSchedulerEventType.Elapsed: // Check if standby should be prevented setting = ps.Settings.GetSetting("NetworkMonitorEnabled"); enabled = Convert.ToBoolean(layer.GetSetting("PowerSchedulerNetworkMonitorEnabled", "false").Value); if (setting.Get<bool>() != enabled) // Setting changed { setting.Set<bool>(enabled); if (enabled) // Start { Log.Debug("NetworkMonitorHandler: Network monitor started"); StartNetworkMonitor(); } else // Stop { Log.Debug("NetworkMonitorHandler: Network monitor stopped"); StopNetworkMonitor(); } } // Get minimum transferrate considered as network activity if (enabled) { setting = ps.Settings.GetSetting("NetworkMonitorIdleLimit"); _idleLimit = Int32.Parse(layer.GetSetting("PowerSchedulerNetworkMonitorIdleLimit", "2").Value); if (setting.Get<Int32>() != _idleLimit) { setting.Set<Int32>(_idleLimit); Log.Debug("NetworkMonitorHandler: Idle limit in KB/s: {0}", _idleLimit); } // Check if away mode should be used setting = ps.Settings.GetSetting("NetworkMonitorAwayMode"); _useAwayMode = Convert.ToBoolean(layer.GetSetting("PowerSchedulerNetworkMonitorAwayMode", "false").Value); if (setting.Get<bool>() != _useAwayMode) { setting.Set<bool>(_useAwayMode); Log.Debug("NetworkMonitorHandler: Use away mode: {0}", _useAwayMode); } } break; } }
private void OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.Started: case PowerSchedulerEventType.Elapsed: IPowerScheduler ps = GlobalServiceProvider.Instance.Get<IPowerScheduler>(); if (ps == null) return; TvBusinessLayer layer = new TvBusinessLayer(); PowerSetting setting; bool enabled; EPGWakeupConfig config = new EPGWakeupConfig((layer.GetSetting("PowerSchedulerRebootConfig", String.Empty).Value)); if (args.EventType == PowerSchedulerEventType.Started) { // Get time of last reboot if (config.LastRun == DateTime.MinValue) config.LastRun = DateTime.Now; else config.LastRun = DateTime.Now.AddMilliseconds(-Environment.TickCount); // Save last reboot status Setting s = layer.GetSetting("PowerSchedulerRebootConfig", String.Empty); s.Value = config.SerializeAsString(); s.Persist(); Log.Debug("RebootHandler: Set time of last reboot: {0}", config.LastRun); } // Check if system should wakeup for reboot setting = ps.Settings.GetSetting("RebootWakeup"); enabled = Convert.ToBoolean(layer.GetSetting("PowerSchedulerRebootWakeup", "false").Value); if (setting.Get<bool>() != enabled) { setting.Set<bool>(enabled); if (enabled) { if (ps.IsRegistered(this as IWakeupHandler)) ps.Unregister(this as IWakeupHandler); ps.Register(this as IWakeupHandler); } else { ps.Unregister(this as IWakeupHandler); } Log.Debug("RebootHandler: Wakeup system for reboot: {0}", enabled ? "enabled" : "disabled"); } // Check if a reboot time is set setting = ps.Settings.GetSetting("RebootConfig"); if (!config.Equals(setting.Get<EPGWakeupConfig>())) { setting.Set<EPGWakeupConfig>(config); Log.Debug("RebootHandler: Reboot system at {0:00}:{1:00}", config.Hour, config.Minutes); if (config.Days != null) { String days = ""; foreach (EPGGrabDays day in config.Days) { if (days == "") days = day.ToString(); else days = days + ", " + day.ToString(); } Log.Debug("RebootHandler: Reboot system on: {0}", days); } } if (args.EventType == PowerSchedulerEventType.Elapsed) { // Check if reboot is due if (ShouldRunNow()) { // See if system is idle bool unattended, disAllowShutdown; String disAllowShutdownHandler, nextWakeupHandler; DateTime nextWakeupTime; // Reboot only if all other handlers allow standby ps.GetCurrentState(false, out unattended, out disAllowShutdown, out disAllowShutdownHandler, out nextWakeupTime, out nextWakeupHandler); if (!disAllowShutdown) { // Kick off reboot thread Log.Debug("RebootHandler: Reboot is due - reboot now"); Thread workerThread = new Thread(new ThreadStart(RebootThread)); workerThread.Name = "RebootHandler"; workerThread.IsBackground = true; workerThread.Priority = ThreadPriority.Lowest; workerThread.Start(); } else Log.Debug("RebootHandler: Reboot is due - reboot when standby is allowed"); } } break; } }
private void OnPowerSchedulerEvent(PowerSchedulerEventArgs args) { switch (args.EventType) { case PowerSchedulerEventType.Started: case PowerSchedulerEventType.Elapsed: IPowerScheduler ps = GlobalServiceProvider.Instance.Get <IPowerScheduler>(); if (ps == null) { return; } PowerSetting setting; bool enabled; using (Settings reader = new MPSettings()) { EPGWakeupConfig config = new EPGWakeupConfig(reader.GetValueAsString("psclientplugin", "RebootConfig", String.Empty)); if (args.EventType == PowerSchedulerEventType.Started) { // Get time of last reboot if (config.LastRun == DateTime.MinValue) { config.LastRun = DateTime.Now; } else { config.LastRun = DateTime.Now.AddMilliseconds(-Environment.TickCount); } // Save last reboot status reader.SetValue("psclientplugin", "RebootConfig", config.SerializeAsString()); Log.Debug("RebootHandler: Set time of last reboot: {0}", config.LastRun); } // Check if system should wakeup for reboot setting = ps.Settings.GetSetting("RebootWakeup"); enabled = reader.GetValueAsBool("psclientplugin", "RebootWakeup", false); if (setting.Get <bool>() != enabled) { setting.Set <bool>(enabled); if (enabled) { if (ps.IsRegistered(this as IWakeupHandler)) { ps.Unregister(this as IWakeupHandler); } ps.Register(this as IWakeupHandler); } else { ps.Unregister(this as IWakeupHandler); } Log.Debug("RebootHandler: Wakeup system for reboot: {0}", enabled ? "enabled" : "disabled"); } // Check if a reboot time is set setting = ps.Settings.GetSetting("RebootConfig"); if (!config.Equals(setting.Get <EPGWakeupConfig>())) { setting.Set <EPGWakeupConfig>(config); Log.Debug("RebootHandler: Reboot system at {0:00}:{1:00}", config.Hour, config.Minutes); if (config.Days != null) { String days = ""; foreach (EPGGrabDays day in config.Days) { if (days == "") { days = day.ToString(); } else { days = days + ", " + day.ToString(); } } Log.Debug("RebootHandler: Reboot system on: {0}", days); } } if (args.EventType == PowerSchedulerEventType.Elapsed) { // Check if reboot is due if (ShouldRunNow()) { // See if system is idle bool unattended, disAllowShutdown; String disAllowShutdownHandler, nextWakeupHandler; DateTime nextWakeupTime; // Reboot only if all other handlers allow standby ps.GetCurrentState(false, out unattended, out disAllowShutdown, out disAllowShutdownHandler, out nextWakeupTime, out nextWakeupHandler); if (!disAllowShutdown) { // Kick off reboot thread Log.Debug("RebootHandler: Reboot is due - reboot now"); Thread workerThread = new Thread(new ThreadStart(RebootThread)); workerThread.Name = "RebootHandler"; workerThread.IsBackground = true; workerThread.Priority = ThreadPriority.Lowest; workerThread.Start(); } else { Log.Debug("RebootHandler: Reboot is due - reboot when standby is allowed"); } } } break; } } }
private bool LoadSettings() { bool changed = false; PowerSetting setting; PowerSchedulerEventArgs args; if (_settings == null) { _settings = new PowerSettings(); _settings.ExtensiveLogging = true; _settings.ShutdownEnabled = true; _settings.WakeupEnabled = true; } using (Settings reader = new MPSettings()) { // Only detect singleseat/multiseat once if (!_refreshSettings) { setting = _settings.GetSetting("SingleSeat"); string stringSetting = reader.GetValueAsString("tvservice", "hostname", String.Empty); if (stringSetting == String.Empty) { Log.Info("Detected client-only setup - using local methods to suspend/hibernate system"); setting.Set<bool>(false); } else if (Network.IsSingleSeat()) { Log.Info("PowerScheduler: detected a singleseat setup - delegating suspend/hibernate requests to tvserver"); setting.Set<bool>(true); } else { Log.Info("PowerScheduler: detected a multiseat setup - using local methods to suspend/hibernate system"); setting.Set<bool>(false); stringSetting = reader.GetValueAsString("tvservice", "hostname", String.Empty); RemotePowerControl.HostName = stringSetting; Log.Info("PowerScheduler: set hostname to {0}", stringSetting); } changed = true; // From now on, only refresh the required settings on subsequent LoadSettings() calls _refreshSettings = true; } // Check if logging should be verbose bool boolSetting = reader.GetValueAsBool("psclientplugin", "extensivelogging", false); if (_settings.ExtensiveLogging != boolSetting) { _settings.ExtensiveLogging = boolSetting; Log.Debug("Extensive logging enabled: {0}", boolSetting); changed = true; } // Check if we only should suspend in MP's home window boolSetting = reader.GetValueAsBool("psclientplugin", "homeonly", true); setting = _settings.GetSetting("HomeOnly"); if (setting.Get<bool>() != boolSetting) { setting.Set<bool>(boolSetting); LogVerbose("Only allow standby when in home screen: {0}", boolSetting); changed = true; } // Check if we should force the system into standby boolSetting = reader.GetValueAsBool("psclientplugin", "forceshutdown", false); if (_settings.ForceShutdown != boolSetting) { _settings.ForceShutdown = boolSetting; LogVerbose("Force system into standby: {0}", boolSetting); changed = true; } // Check configured PowerScheduler shutdown enabled boolSetting = reader.GetValueAsBool("psclientplugin", "shutdownenabled", false); if (_settings.ShutdownEnabled != boolSetting) { _settings.ShutdownEnabled = boolSetting; LogVerbose("shutdown enabled locally set to: {0}", boolSetting); changed = true; } // Check configured PowerScheduler idle timeout int intSetting = reader.GetValueAsInt("psclientplugin", "idletimeout", 5); if (_settings.IdleTimeout != intSetting) { _settings.IdleTimeout = intSetting; LogVerbose("idle timeout locally set to: {0} minutes", intSetting); changed = true; } // Check configured pre-wakeup time intSetting = reader.GetValueAsInt("psclientplugin", "prewakeup", 60); if (_settings.PreWakeupTime != intSetting) { _settings.PreWakeupTime = intSetting; LogVerbose("pre-wakeup time set to: {0} seconds", intSetting); changed = true; } // Check configured pre-wakeup time intSetting = reader.GetValueAsInt("psclientplugin", "prenoshutdown", 120); if (_settings.PreNoShutdownTime != intSetting) { _settings.PreNoShutdownTime = intSetting; LogVerbose("pre-shutdown time set to: {0} seconds", intSetting); changed = true; } // Check with what interval the system status should be checked intSetting = reader.GetValueAsInt("psclientplugin", "checkinterval", 25); if (_settings.CheckInterval != intSetting) { _settings.CheckInterval = intSetting; LogVerbose("Check interval is set to {0} seconds", intSetting); _timer.Interval = intSetting * 1000; changed = true; } // Check configured shutdown mode intSetting = reader.GetValueAsInt("psclientplugin", "shutdownmode", 2); if ((int)_settings.ShutdownMode != intSetting) { _settings.ShutdownMode = (ShutdownMode)intSetting; LogVerbose("Shutdown mode set to {0}", _settings.ShutdownMode); changed = true; } // Send message in case any setting has changed if (changed) { args = new PowerSchedulerEventArgs(PowerSchedulerEventType.SettingsChanged); args.SetData<PowerSettings>(_settings.Clone()); SendPowerSchedulerEvent(args); } } return true; }