Esempio n. 1
0
        private DateTime GetNextWakeupSchedule(DateTime earliestWakeupTime)
        {
            IPowerScheduler ps  = GlobalServiceProvider.Instance.Get <IPowerScheduler>();
            EPGWakeupConfig cfg = ps.Settings.GetSetting("EPGWakeupConfig").Get <EPGWakeupConfig>();
            // Start by thinking we should run today
            DateTime nextRun = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, cfg.Hour, cfg.Minutes, 0);

            // check if we should run today or some other day in the future
            if (cfg.LastRun.Day == DateTime.Now.Day || nextRun < earliestWakeupTime)
            {
                // determine first next day to run EPG grabber
                for (int i = 1; i < 8; i++)
                {
                    if (ShouldRun(cfg.Days, nextRun.AddDays(i).DayOfWeek))
                    {
                        nextRun = nextRun.AddDays(i);
                        break;
                    }
                }
                if (DateTime.Now.Day == nextRun.Day)
                {
                    Log.Error("PowerScheduler: no valid next wakeup date for EPG grabbing found!");
                    nextRun = DateTime.MaxValue;
                }
            }
            return(nextRun);
        }
        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;
            }
        }
Esempio n. 3
0
 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;
     }
 }
Esempio n. 4
0
        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>
        /// Unregister the default set of standby/wakeup handlers
        /// </summary>
        public void RemoveDefaultSet()
        {
            IPowerScheduler powerScheduler = GlobalServiceProvider.Instance.Get <IPowerScheduler>();

            foreach (IStandbyHandler handler in _standbyHandlers)
            {
                powerScheduler.Unregister(handler);
            }
            foreach (IWakeupHandler handler in _wakeupHandlers)
            {
                powerScheduler.Unregister(handler);
            }
        }
Esempio n. 6
0
 public ScheduledRecordingsHandler()
 {
     if (GlobalServiceProvider.Instance.IsRegistered <IPowerScheduler>())
     {
         IPowerScheduler ips = GlobalServiceProvider.Instance.Get <IPowerScheduler>();
         if (ips != null)
         {
             ips.OnPowerSchedulerEvent += ScheduledRecordingsHandler_OnPowerSchedulerEvent;
             if (ips.Settings != null)
             {
                 _idleTimeout = ips.Settings.IdleTimeout;
             }
         }
     }
 }
Esempio n. 7
0
        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>
        /// Thread to perform reboot
        /// </summary>
        private void RebootThread()
        {
            TvBusinessLayer layer  = new TvBusinessLayer();
            EPGWakeupConfig config = new EPGWakeupConfig((layer.GetSetting("PowerSchedulerRebootConfig", String.Empty).Value));

            Log.Debug("RebootHandler: Reboot schedule {0:00}:{1:00} is due", config.Hour, config.Minutes);

            // Start external command
            RunExternalCommand("reboot");

            // Trigger reboot
            Log.Info("RebootHandler: Reboot system");
            IPowerScheduler ps = GlobalServiceProvider.Instance.Get <IPowerScheduler>();

            ps.SuspendSystem("RebootHandler", (int)RestartOptions.Reboot, false);
        }
Esempio n. 9
0
        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;
            }
        }
        /// <summary>
        /// Thread to perform reboot
        /// </summary>
        private void RebootThread()
        {
            using (Settings reader = new MPSettings())
            {
                EPGWakeupConfig config = new EPGWakeupConfig(reader.GetValueAsString("psclientplugin", "RebootConfig", String.Empty));

                Log.Debug("RebootHandler: Reboot schedule {0:00}:{1:00} is due", config.Hour, config.Minutes);

                // Start external command
                RunExternalCommand("reboot");

                // Trigger reboot
                Log.Info("RebootHandler: Reboot system");
                IPowerScheduler ps = GlobalServiceProvider.Instance.Get <IPowerScheduler>();
                ps.SuspendSystem("RebootHandler", (int)RestartOptions.Reboot, false);
            }
        }
        public DateTime GetNextWakeupTime(DateTime earliestWakeupTime)
        {
            IPowerScheduler ps  = GlobalServiceProvider.Instance.Get <IPowerScheduler>();
            EPGWakeupConfig cfg = ps.Settings.GetSetting("RebootConfig").Get <EPGWakeupConfig>();
            DateTime        now = DateTime.Now;

            // The earliest wakeup time cannot be in the past
            if (earliestWakeupTime < now)
            {
                earliestWakeupTime = now;
            }

            // Start with the earliest possible day
            DateTime nextRun = new DateTime(earliestWakeupTime.Year, earliestWakeupTime.Month, earliestWakeupTime.Day, cfg.Hour, cfg.Minutes, 0);

            // If the wakeup time is before the earliest wakeup time or if there already was a reboot on this day then take the next day
            if (nextRun < earliestWakeupTime || cfg.LastRun.Date >= nextRun.Date)
            {
                nextRun = nextRun.AddDays(1);
            }

            // Try the next 7 days
            for (int i = 0; i < 7; i++)
            {
                // Check if this day is configured for reboot
                if (ShouldRun(cfg.Days, nextRun.DayOfWeek))
                {
                    return(nextRun);
                }

                nextRun = nextRun.AddDays(1);
            }

            // Found no day configured for reboot
            return(DateTime.MaxValue);
        }
        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;
                }
            }
        }
Esempio n. 13
0
        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;
            }
        }
Esempio n. 14
0
        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;
            }
        }
        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;
            }
        }