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);
        }
Esempio n. 2
0
 private void CheckDay(EPGWakeupConfig cfg, EPGGrabDays day, bool enabled)
 {
     if (enabled)
     {
         cfg.Days.Add(day);
     }
 }
Esempio n. 3
0
        private DateTime GetNextWakeupSchedule(DateTime earliestWakeupTime)
        {
            TvBusinessLayer layer = new TvBusinessLayer();

            EPGWakeupConfig cfg = new EPGWakeupConfig(layer.GetSetting("webepgSchedule", String.Empty).Value);

            // 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("WebEPG: no valid next wakeup date for EPG grabbing found!");
                    nextRun = DateTime.MaxValue;
                }
            }
            return(nextRun);
        }
        /// <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. 5
0
        private void EPGThreadFunction()
        {
            // ShouldRun still returns true until LastRun is updated,
            // shutdown is disallowed until then

            TvBusinessLayer layer  = new TvBusinessLayer();
            EPGWakeupConfig config = new EPGWakeupConfig((layer.GetSetting("EPGWakeupConfig", String.Empty).Value));

            Log.Info("PowerScheduler: EPG schedule {0}:{1} is due: {2}:{3}",
                     config.Hour, config.Minutes, DateTime.Now.Hour, DateTime.Now.Minute);

            // start external command
            RunExternalCommand("epg");

            // try a forced start of EPG grabber if not already started
            if (!_controller.EpgGrabberEnabled)
            {
                _controller.EpgGrabberEnabled = true;
            }

            // Fire the EPGScheduleDue event for EPG grabber plugins
            if (_epgScheduleDue != null)
            {
                lock (_epgScheduleDue)
                {
                    if (_epgScheduleDue != null)
                    {
                        _epgScheduleDue();
                    }
                }
            }

            // sleep 10 Seconds to give the grabbers time to kick off their threads,
            // so that they disallow shutdown
            // without this sleep the PS could be tempted to standby (wakeup/standby race condition)
            Thread.Sleep(10000);

            // Update last schedule run status
            config.LastRun = DateTime.Now;
            Setting s = layer.GetSetting("EPGWakeupConfig", String.Empty);

            s.Value = config.SerializeAsString();
            s.Persist();

            _epgThreadRunning = false;
        }
        /// <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);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Returns whether a schedule is due, and the EPG should run now.
        /// </summary>
        /// <returns></returns>
        private bool ShouldRunNow()
        {
            TvBusinessLayer layer  = new TvBusinessLayer();
            EPGWakeupConfig config = new EPGWakeupConfig((layer.GetSetting("PowerSchedulerEPGWakeupConfig", String.Empty).Value));

            // Check if this day is configured for EPG and there was no EPG grabbing yet
            DateTime now = DateTime.Now;

            if (ShouldRun(config.Days, now.DayOfWeek) && config.LastRun.Date < now.Date)
            {
                // Check if schedule is due
                if (now >= new DateTime(now.Year, now.Month, now.Day, config.Hour, config.Minutes, 0))
                {
                    return(true);
                }
            }
            return(false);
        }
        /// <summary>
        /// Check if a reboot is due
        /// </summary>
        /// <returns>Returns whether the system should reboot now</returns>
        private bool ShouldRunNow()
        {
            using (Settings reader = new MPSettings())
            {
                EPGWakeupConfig config = new EPGWakeupConfig(reader.GetValueAsString("psclientplugin", "RebootConfig", String.Empty));

                // Check if this day is configured for reboot and there was no reboot yet
                DateTime now = DateTime.Now;
                if (ShouldRun(config.Days, now.DayOfWeek) && config.LastRun.Date < now.Date)
                {
                    // Check if schedule is due
                    if (now >= new DateTime(now.Year, now.Month, now.Day, config.Hour, config.Minutes, 0))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 9
0
        private void _scheduleTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            TvBusinessLayer layer           = new TvBusinessLayer();
            bool            scheduleEnabled = Convert.ToBoolean(layer.GetSetting("webepgScheduleEnabled", "true").Value);

            if (scheduleEnabled)
            {
                Setting         configSetting = layer.GetSetting("webepgSchedule", String.Empty);
                EPGWakeupConfig config        = new EPGWakeupConfig(configSetting.Value);
                if (ShouldRunNow())
                {
                    Log.Info("WebEPGImporter: WebEPG schedule {0}:{1} is due: {2}:{3}",
                             config.Hour, config.Minutes, DateTime.Now.Hour, DateTime.Now.Minute);
                    StartImport(null);
                    config.LastRun      = DateTime.Now;
                    configSetting.Value = config.SerializeAsString();
                    configSetting.Persist();
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Returns whether a schedule is due, and the EPG should run now.
        /// </summary>
        /// <returns></returns>
        private bool ShouldRunNow()
        {
            TvBusinessLayer layer  = new TvBusinessLayer();
            EPGWakeupConfig config = new EPGWakeupConfig(layer.GetSetting("webepgSchedule", String.Empty).Value);

            // check if schedule is due
            // check if we've already run today
            if (config.LastRun.Day != DateTime.Now.Day)
            {
                // check if we should run today
                if (ShouldRun(config.Days, DateTime.Now.DayOfWeek))
                {
                    // check if schedule is due
                    DateTime now = DateTime.Now;
                    if (now.Hour > config.Hour || (now.Hour == config.Hour && now.Minute >= config.Minutes))
                    {
                        return(true);
                    }
                }
            }
            return(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);
        }
Esempio n. 12
0
    /// <summary>
    /// Check if a reboot is due
    /// </summary>
    /// <returns>Returns whether the system should reboot now</returns>
    private bool ShouldRunNow()
    {
      TvBusinessLayer layer = new TvBusinessLayer();
      EPGWakeupConfig config = new EPGWakeupConfig((layer.GetSetting("PowerSchedulerRebootConfig", String.Empty).Value));

      // Check if this day is configured for reboot and there was no reboot yet
      DateTime now = DateTime.Now;
      if (ShouldRun(config.Days, now.DayOfWeek) && config.LastRun.Date < now.Date)
      {
        // Check if schedule is due
        if (now >= new DateTime(now.Year, now.Month, now.Day, config.Hour, config.Minutes, 0))
          return true;
      }
      return false;
    }
    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;
      }
    }
    /// <summary>
    /// Returns whether a schedule is due, and the EPG should run now.
    /// </summary>
    /// <returns></returns>
    private bool ShouldRunNow()
    {
      TvBusinessLayer layer = new TvBusinessLayer();
      EPGWakeupConfig config = new EPGWakeupConfig((layer.GetSetting("EPGWakeupConfig", String.Empty).Value));

      // check if schedule is due
      // check if we've already run today
      if (config.LastRun.Day != DateTime.Now.Day)
      {
        // check if we should run today
        if (ShouldRun(config.Days, DateTime.Now.DayOfWeek))
        {
          // check if schedule is due
          if (DateTime.Now.Hour >= config.Hour)
          {
            if (DateTime.Now.Minute >= config.Minutes)
            {
              return true;
            }
          }
        }
      }
      return false;
    }
    private void EPGThreadFunction()
    {
      // ShouldRun still returns true until LastRun is updated, 
      // shutdown is disallowed until then

      TvBusinessLayer layer = new TvBusinessLayer();
      EPGWakeupConfig config = new EPGWakeupConfig((layer.GetSetting("PowerSchedulerEPGWakeupConfig", String.Empty).Value));

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

      // start external command
      RunExternalCommand("epg");

      // try a forced start of EPG grabber if not already started 
      if (!_controller.EpgGrabberEnabled)
        _controller.EpgGrabberEnabled = true;

      // Fire the EPGScheduleDue event for EPG grabber plugins
      if (_epgScheduleDue != null)
      {
        lock (_epgScheduleDue)
        {
          if (_epgScheduleDue != null)
            _epgScheduleDue();
        }
      }

      // sleep 10 Seconds to give the grabbers time to kick off their threads,
      // so that they disallow shutdown
      // without this sleep the PS could be tempted to standby (wakeup/standby race condition)
      Thread.Sleep(10000);

      // Update last schedule run status
      config.LastRun = DateTime.Now;
      Setting s = layer.GetSetting("PowerSchedulerEPGWakeupConfig", String.Empty);
      s.Value = config.SerializeAsString();
      s.Persist();

      _epgThreadRunning = false;
    }
        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. 17
0
        public override void SaveSettings()
        {
            base.SaveSettings();

            _configFile.Info.GrabDays = (int)nMaxGrab.Value;

            _configFile.Channels      = new List <ChannelMap>();
            _configFile.RadioChannels = new List <ChannelMap>();

            foreach (ChannelMap channel in TvMappings.ChannelMapping.Values)
            {
                _configFile.Channels.Add(channel);
            }
            foreach (ChannelMap channel in RadioMappings.ChannelMapping.Values)
            {
                _configFile.RadioChannels.Add(channel);
            }

            Log.Info("WebEPG Config: Button: Save");
            string   confFile = _configFileDir + "\\WebEPG.xml";
            FileInfo config   = new FileInfo(confFile);

            if (config.Exists)
            {
                File.Delete(confFile.Replace(".xml", ".bak"));
                File.Move(confFile, confFile.Replace(".xml", ".bak"));
            }

            XmlSerializer s = new XmlSerializer(typeof(WebepgConfigFile));
            TextWriter    w = new StreamWriter(confFile);

            s.Serialize(w, _configFile);
            w.Close();

            TvBusinessLayer layer   = new TvBusinessLayer();
            Setting         setting = layer.GetSetting("webepgDestination", "db");

            switch (DestinationComboBox.SelectedIndex)
            {
            case 0:
                setting.Value = "db";
                break;

            case 1:
                setting.Value = "defxmltv";
                break;

            case 2:
                setting.Value = "xmltv";
                break;
            }
            setting.Persist();

            setting       = layer.GetSetting("webepgDestinationFolder");
            setting.Value = textBoxFolder.Text;
            setting.Persist();

            setting       = layer.GetSetting("webepgDeleteBeforeImport", "true");
            setting.Value = checkBoxDeleteBeforeImport.Checked ? "true" : "false";
            setting.Persist();

            setting       = layer.GetSetting("webepgScheduleEnabled", "true");
            setting.Value = ScheduleGrabCheckBox.Checked ? "true" : "false";
            setting.Persist();

            setting = layer.GetSetting("webepgSchedule", String.Empty);
            EPGWakeupConfig cfg    = new EPGWakeupConfig(setting.Value);
            EPGWakeupConfig newcfg = new EPGWakeupConfig();

            newcfg.Hour    = cfg.Hour;
            newcfg.Minutes = cfg.Minutes;
            // newcfg.Days = cfg.Days;
            newcfg.LastRun = cfg.LastRun;
            string[] time = grabTimeTextBox.Text.Split(System.Globalization.DateTimeFormatInfo.CurrentInfo.TimeSeparator[0]);
            newcfg.Hour    = Convert.ToInt32(time[0]);
            newcfg.Minutes = Convert.ToInt32(time[1]);
            CheckDay(newcfg, EPGGrabDays.Monday, MondayCheckBox.Checked);
            CheckDay(newcfg, EPGGrabDays.Tuesday, TuesdayCheckBox.Checked);
            CheckDay(newcfg, EPGGrabDays.Wednesday, WednesdayCheckBox.Checked);
            CheckDay(newcfg, EPGGrabDays.Thursday, ThursdayCheckBox.Checked);
            CheckDay(newcfg, EPGGrabDays.Friday, FridayCheckBox.Checked);
            CheckDay(newcfg, EPGGrabDays.Saturday, SaturdayCheckBox.Checked);
            CheckDay(newcfg, EPGGrabDays.Sunday, SundayCheckBox.Checked);

            if (!cfg.Equals(newcfg))
            {
                setting.Value = newcfg.SerializeAsString();
                setting.Persist();
            }
        }
Esempio n. 18
0
        public override void LoadSettings()
        {
            base.LoadSettings();

            Initialize();

            TvBusinessLayer layer = new TvBusinessLayer();

            switch (layer.GetSetting("webepgDestination", "db").Value)
            {
            case "db":
                DestinationComboBox.SelectedIndex = 0;
                break;

            case "defxmltv":
                DestinationComboBox.SelectedIndex = 1;
                break;

            case "xmltv":
                DestinationComboBox.SelectedIndex = 2;
                break;

            default:
                DestinationComboBox.SelectedIndex = 0;
                break;
            }

            textBoxFolder.Text = layer.GetSetting("webepgDestinationFolder").Value;
            checkBoxDeleteBeforeImport.Checked = Convert.ToBoolean(layer.GetSetting("webepgDeleteBeforeImport", "true").Value);

            LoadWebepgConfigFile();
            //RedrawList(null);

            // Schedule
            ScheduleGrabCheckBox.Checked = Convert.ToBoolean(layer.GetSetting("webepgScheduleEnabled", "true").Value);
            EPGWakeupConfig config = new EPGWakeupConfig(layer.GetSetting("webepgSchedule", String.Empty).Value);

            foreach (EPGGrabDays day in config.Days)
            {
                switch (day)
                {
                case EPGGrabDays.Monday:
                    MondayCheckBox.Checked = true;
                    break;

                case EPGGrabDays.Tuesday:
                    TuesdayCheckBox.Checked = true;
                    break;

                case EPGGrabDays.Wednesday:
                    WednesdayCheckBox.Checked = true;
                    break;

                case EPGGrabDays.Thursday:
                    ThursdayCheckBox.Checked = true;
                    break;

                case EPGGrabDays.Friday:
                    FridayCheckBox.Checked = true;
                    break;

                case EPGGrabDays.Saturday:
                    SaturdayCheckBox.Checked = true;
                    break;

                case EPGGrabDays.Sunday:
                    SundayCheckBox.Checked = true;
                    break;
                }
            }
            grabTimeTextBox.Text = String.Format("{0:00}:{1:00}", config.Hour, config.Minutes);
        }
Esempio n. 19
0
    /// <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. 20
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. 21
0
    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;
      }
    }