コード例 #1
0
 private bool OnPowerEvent(PowerEventType powerStatus)
 {
     switch (powerStatus)
     {
     case PowerEventType.ResumeAutomatic:
     case PowerEventType.ResumeCritical:
     case PowerEventType.ResumeSuspend:
         // note: this event may not arrive unless the user has moved the mouse or hit a key
         // so, we should also handle ResumeAutomatic and ResumeCritical (as done above)
         Resume();
         break;
     }
     return(true);
 }
コード例 #2
0
ファイル: Service1.cs プロジェクト: usermonk/MediaPortal-1
        private bool OnPowerEventHandler(PowerEventType powerStatus)
        {
            Log.Debug("OnPowerEventHandler: PowerStatus: {0}", powerStatus);

            switch (powerStatus)
            {
            case PowerEventType.StandBy:
            case PowerEventType.Suspend:
                _controller.OnSuspend();
                return(true);

            case PowerEventType.QuerySuspend:
            case PowerEventType.QueryStandBy:
                if (_controller != null)
                {
                    if (_controller.CanSuspend)
                    {
                        //OnStop();
                        return(true);
                    }
                    return(false);
                }
                return(true);

            case PowerEventType.QuerySuspendFailed:
            case PowerEventType.QueryStandByFailed:
                if (!_controller.EpgGrabberEnabled)
                {
                    _controller.EpgGrabberEnabled = true;
                }
                return(true);

            case PowerEventType.ResumeAutomatic:
            case PowerEventType.ResumeCritical:
            case PowerEventType.ResumeSuspend:
                _controller.OnResume();
                return(true);
            }
            return(true);
        }
コード例 #3
0
ファイル: TvServerPlugin.cs プロジェクト: rob-opsi/ARGUS-TV
        private bool OnPowerEvent(PowerEventType powerStatus)
        {
            lock (this)
            {
                switch (powerStatus)
                {
                case PowerEventType.QuerySuspend:
                case PowerEventType.QueryStandBy:
                    return(true);

                case PowerEventType.Suspend:
                case PowerEventType.StandBy:
                    Log.Debug("ArgusTV.Recorder.MediaPortalTvServer: System is entering standby");
                    _tvServerNeedsRestart = true;
                    return(true);

                case PowerEventType.QuerySuspendFailed:
                case PowerEventType.QueryStandByFailed:
                    Log.Debug("ArgusTV.Recorder.MediaPortalTvServer: Entering standby was denied");
                    return(true);

                case PowerEventType.ResumeAutomatic:
                    Log.Debug("ArgusTV.Recorder.MediaPortalTvServer: System has resumed automatically from standby");
                    Resume();
                    return(true);

                case PowerEventType.ResumeCritical:
                    Log.Debug("ArgusTV.Recorder.MediaPortalTvServer: System has resumed from standby after a critical suspend");
                    Resume();
                    return(true);

                case PowerEventType.ResumeSuspend:
                    Log.Debug("ArgusTV.Recorder.MediaPortalTvServer: System has resumed from standby");
                    Resume();
                    return(true);
                }
                return(true);
            }
        }
コード例 #4
0
    private bool OnPowerEventHandler(PowerEventType powerStatus)
    {
      Log.Debug("OnPowerEventHandler: PowerStatus: {0}", powerStatus);

      switch (powerStatus)
      {
        case PowerEventType.StandBy:
        case PowerEventType.Suspend:
          _controller.OnSuspend();
          return true;
        case PowerEventType.QuerySuspend:
        case PowerEventType.QueryStandBy:
          if (_controller != null)
          {
            if (_controller.CanSuspend)
            {
              //OnStop();
              return true;
            }
            return false;
          }
          return true;
        case PowerEventType.QuerySuspendFailed:
        case PowerEventType.QueryStandByFailed:
          if (!_controller.EpgGrabberEnabled)
            _controller.EpgGrabberEnabled = true;
          return true;
        case PowerEventType.ResumeAutomatic:
        case PowerEventType.ResumeCritical:
        case PowerEventType.ResumeSuspend:
          _controller.OnResume();
          return true;
      }
      return true;
    }
コード例 #5
0
    protected bool OnPowerEvent(PowerEventType powerStatus)
    {
      Log.Debug("OnPowerEvent: PowerStatus: {0}", powerStatus);

      bool accept = true;
      List<PowerEventHandler> powerEventPreventers = new List<PowerEventHandler>();
      List<PowerEventHandler> powerEventAllowers = new List<PowerEventHandler>();

      // Make a copy of _powerEventHandlers, because the handler might call AddPowerEventHandler
      // or RemovePowerEventHandler when executing thus generating an exception when we iterate.
      List<PowerEventHandler> listCopy = new List<PowerEventHandler>();
      foreach (PowerEventHandler handler in _powerEventHandlers)
      {
        listCopy.Add((PowerEventHandler)handler.Clone());
      }
      // Now iterate the 'copy'
      foreach (PowerEventHandler handler in listCopy)
      {
        bool result = handler(powerStatus);
        if (result == false)
        {
          accept = false;
          powerEventPreventers.Add(handler);
        }
        else
          powerEventAllowers.Add(handler);
      }
      if (accept)
        return true;
      if (powerEventPreventers.Count > 0)
        foreach (PowerEventHandler handler in powerEventPreventers)
          Log.Debug("PowerStatus:{0} rejected by {1}", powerStatus, handler.Target.ToString());

      // if query suspend: 
      // everybody that allowed the standby now must receive a deny event
      // since we will not get a QuerySuspendFailed message by the OS when
      // we return false to QuerySuspend
      if (powerStatus == PowerEventType.QuerySuspend ||
          powerStatus == PowerEventType.QueryStandBy)
      {
        foreach (PowerEventHandler handler in powerEventAllowers)
        {
          handler(powerStatus == PowerEventType.QuerySuspend
                    ? PowerEventType.QuerySuspendFailed
                    : PowerEventType.QueryStandByFailed);
        }
      }
      else if (powerStatus == PowerEventType.ResumeAutomatic ||
               powerStatus == PowerEventType.ResumeCritical ||
               powerStatus == PowerEventType.ResumeStandBy ||
               powerStatus == PowerEventType.ResumeSuspend
        )
      {
        _controller.ExecutePendingDeletions();
        // call Recording-folder cleanup, just in case we have empty folders.
      }


      return false;
    }
コード例 #6
0
        private bool OnPowerEvent(PowerEventType powerStatus)
        {
            lock (this)
            {
                switch (powerStatus)
                {
                    case PowerEventType.QuerySuspend:
                    case PowerEventType.QueryStandBy:
                        return true;

                    case PowerEventType.Suspend:
                    case PowerEventType.StandBy:
                        Log.Debug("ArgusTV.Recorder.MediaPortalTvServer: System is entering standby");
                        _tvServerNeedsRestart = true;
                        return true;

                    case PowerEventType.QuerySuspendFailed:
                    case PowerEventType.QueryStandByFailed:
                        Log.Debug("ArgusTV.Recorder.MediaPortalTvServer: Entering standby was denied");
                        return true;

                    case PowerEventType.ResumeAutomatic:
                        Log.Debug("ArgusTV.Recorder.MediaPortalTvServer: System has resumed automatically from standby");
                        Resume();
                        return true;

                    case PowerEventType.ResumeCritical:
                        Log.Debug("ArgusTV.Recorder.MediaPortalTvServer: System has resumed from standby after a critical suspend");
                        Resume();
                        return true;

                    case PowerEventType.ResumeSuspend:
                        Log.Debug("ArgusTV.Recorder.MediaPortalTvServer: System has resumed from standby");
                        Resume();
                        return true;
                }
                return true;
            }
        }
コード例 #7
0
ファイル: Service1.cs プロジェクト: usermonk/MediaPortal-1
        protected bool OnPowerEvent(PowerEventType powerStatus)
        {
            Log.Debug("OnPowerEvent: PowerStatus: {0}", powerStatus);

            bool accept = true;
            List <PowerEventHandler> powerEventPreventers = new List <PowerEventHandler>();
            List <PowerEventHandler> powerEventAllowers   = new List <PowerEventHandler>();

            // Make a copy of _powerEventHandlers, because the handler might call AddPowerEventHandler
            // or RemovePowerEventHandler when executing thus generating an exception when we iterate.
            List <PowerEventHandler> listCopy = new List <PowerEventHandler>();

            foreach (PowerEventHandler handler in _powerEventHandlers)
            {
                listCopy.Add((PowerEventHandler)handler.Clone());
            }
            // Now iterate the 'copy'
            foreach (PowerEventHandler handler in listCopy)
            {
                bool result = handler(powerStatus);
                if (result == false)
                {
                    accept = false;
                    powerEventPreventers.Add(handler);
                }
                else
                {
                    powerEventAllowers.Add(handler);
                }
            }
            if (accept)
            {
                return(true);
            }
            if (powerEventPreventers.Count > 0)
            {
                foreach (PowerEventHandler handler in powerEventPreventers)
                {
                    Log.Debug("PowerStatus:{0} rejected by {1}", powerStatus, handler.Target.ToString());
                }
            }

            // if query suspend:
            // everybody that allowed the standby now must receive a deny event
            // since we will not get a QuerySuspendFailed message by the OS when
            // we return false to QuerySuspend
            if (powerStatus == PowerEventType.QuerySuspend ||
                powerStatus == PowerEventType.QueryStandBy)
            {
                foreach (PowerEventHandler handler in powerEventAllowers)
                {
                    handler(powerStatus == PowerEventType.QuerySuspend
                    ? PowerEventType.QuerySuspendFailed
                    : PowerEventType.QueryStandByFailed);
                }
            }
            else if (powerStatus == PowerEventType.ResumeAutomatic ||
                     powerStatus == PowerEventType.ResumeCritical ||
                     powerStatus == PowerEventType.ResumeStandBy ||
                     powerStatus == PowerEventType.ResumeSuspend
                     )
            {
                _controller.ExecutePendingDeletions();
                // call Recording-folder cleanup, just in case we have empty folders.
            }


            return(false);
        }
コード例 #8
0
 public static extern IntPtr RequestPowerNotifications(IntPtr hMsgQ, PowerEventType Flags);
コード例 #9
0
    private bool OnPowerEvent(PowerEventType powerStatus)
    {
      switch (powerStatus)
      {
        // This event is triggered only on Windows XP
        case PowerEventType.QuerySuspend:
          Log.Debug("PS: QUERYSUSPEND");
          if (_currentStandbyMode == StandbyMode.AwayModeRequested)
          {
            // We reject all requests for suspend when a suspend should not be allowed
            Log.Debug("PS: Suspend queried while away mode is required - deny suspend");
            return false;
          }
          if (_denyQuerySuspend)
          {
            // We reject all requests for suspend not coming from PowerScheduler by returning false.
            // Instead we start our own shutdown thread that issues a new QUERYSUSPEND that we will accept.
            // Always try to Hibernate (S4). If system is set to S3, then Hibernate will fail and result will be S3
            Log.Debug("PS: Suspend queried by another application - deny suspend and start own suspend sequence");
            SuspendSystem("System", (int)RestartOptions.Hibernate, false);
            return false;
          }
          return true;

        case PowerEventType.Suspend:
          Log.Debug("PS: SUSPEND");
          OnSuspend();
          return true;

        // This event is triggered only on Windows XP
        case PowerEventType.QuerySuspendFailed:
          Log.Debug("PS: QUERYSUSPENDFAILED");
          // Another application prevents our suspend
          _QuerySuspendFailedCount--;
          return true;

        case PowerEventType.ResumeAutomatic:
          Log.Debug("PS: RESUMEAUTOMATIC");
          OnResume();
          return true;

        case PowerEventType.ResumeCritical:
          Log.Debug("PS: RESUMECRITICAL");
          OnResume();
          return true;

        case PowerEventType.ResumeSuspend:
          // Note: This event is triggered when the user has moved the mouse or hit a key
          // ResumeAutomatic or ResumeCritical have triggered before, so no need to call OnResume()
          Log.Debug("PS: RESUMESUSPEND");
          _lastUserTime = DateTime.Now;
          return true;
      }
      return true;
    }
コード例 #10
0
 private bool OnPowerEvent(PowerEventType powerStatus)
 {
   switch (powerStatus)
   {
     case PowerEventType.ResumeAutomatic:
     case PowerEventType.ResumeCritical:
     case PowerEventType.ResumeSuspend:
       // note: this event may not arrive unless the user has moved the mouse or hit a key
       // so, we should also handle ResumeAutomatic and ResumeCritical (as done above)
       Resume();
       break;
   }
   return true;
 }
コード例 #11
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            eventType = (PowerEventType)Enum.Parse(typeof(PowerEventType), Request["Type"]);

            web     = SPContext.Current.Web;
            list    = SPContext.Current.List;
            feature = web.Features[PowerEventReceiversConstants.FeatureId];

            switch (eventType)
            {
            case PowerEventType.Item:
                propNameScript      = PowerEventReceiversConstants.PowerItemEventReceiverPropNamePrefixScript + list.RootFolder.Url;
                propNameSequence    = PowerEventReceiversConstants.PowerListEventReceiverPropNamePrefixSequence + list.RootFolder.Url;
                propNameSynchronous = PowerEventReceiversConstants.PowerWebEventReceiverPropNamePrefixSynchronous + list.RootFolder.Url;
                eventDefinitionType = typeof(PowerItemEventReceiver).FullName;
                targetName          = list.Title;
                redirectUrl         = list.ParentWeb.Url + "/_layouts/listedit.aspx?List=" + HttpUtility.UrlEncode(list.ID.ToString());
                break;

            case PowerEventType.List:
                propNameScript      = PowerEventReceiversConstants.PowerListEventReceiverPropNamePrefixScript + list.RootFolder.Url;
                propNameSequence    = PowerEventReceiversConstants.PowerListEventReceiverPropNamePrefixSequence + list.RootFolder.Url;
                propNameSynchronous = PowerEventReceiversConstants.PowerWebEventReceiverPropNamePrefixSynchronous + list.RootFolder.Url;
                eventDefinitionType = typeof(PowerListEventReceiver).FullName;
                targetName          = list.Title;
                redirectUrl         = list.ParentWeb.Url + "/_layouts/listedit.aspx?List=" + HttpUtility.UrlEncode(list.ID.ToString());
                break;

            case PowerEventType.Web:
                propNameScript      = PowerEventReceiversConstants.PowerWebEventReceiverPropNamePrefixScript;
                propNameSequence    = PowerEventReceiversConstants.PowerWebEventReceiverPropNamePrefixScript + web.ID.ToString();
                propNameSynchronous = PowerEventReceiversConstants.PowerWebEventReceiverPropNamePrefixSynchronous + web.ID.ToString();
                eventDefinitionType = typeof(PowerWebEventReceiver).FullName;
                targetName          = web.Title;
                redirectUrl         = web.Url + "/_layouts/settings.aspx";
                break;

            default:
                throw new Exception("Unknown event type!");
            }

            scriptProperty      = feature.Properties[propNameScript];
            sequenceProperty    = feature.Properties[propNameSequence];
            synchronousProperty = feature.Properties[propNameSynchronous];

            if (web.CurrentUser.IsSiteAdmin == false)
            {
                throw new SecurityException();
            }

            if (IsPostBack == false)
            {
                if (scriptProperty != null)
                {
                    scriptBox.Text = scriptProperty.Value;
                }
                else
                {
                    switch (eventType)
                    {
                    case PowerEventType.Item:
                        scriptBox.Text = PowerEventReceiversConstants.PowerItemEventReceiverScriptTemplate;
                        break;

                    case PowerEventType.List:
                        scriptBox.Text = PowerEventReceiversConstants.PowerListEventReceiverScriptTemplate;
                        break;

                    case PowerEventType.Web:
                        scriptBox.Text = PowerEventReceiversConstants.PowerWebEventReceiverScriptTemplate;
                        break;

                    default:
                        throw new Exception("Unknown event type!");
                    }
                }

                if (sequenceProperty != null)
                {
                    sequenceNumber.Text = sequenceProperty.Value;
                }
                if (synchronousProperty != null)
                {
                    checkBoxSynchronous.Checked = Boolean.Parse(synchronousProperty.Value);
                }
            }

            saveButton.Click   += new EventHandler(saveButton_Click);
            cancelButton.Click += new EventHandler(cancelButton_Click);
        }
コード例 #12
0
    private void Resume(PowerEventType powerStatus)
    {
      if (powerStatus == PowerEventType.ResumeAutomatic)
        Log.Debug("PowerScheduler: System has resumed automatically from standby");
      else if (powerStatus == PowerEventType.ResumeCritical)
        Log.Debug("PowerScheduler: System has resumed from standby after a critical suspend");
      else if (powerStatus == PowerEventType.ResumeSuspend)
        Log.Debug("PowerScheduler: System has resumed from standby");

      if (!_standby)
        return;

      lock (this)
      {
        // INSIDE lock!!! to avoid clash with CheckForStandBy --->
        _lastUserTime = DateTime.Now;
        if (_idle)
        {
          Log.Info("PowerScheduler: System changed from idle state to busy state");
          _idle = false;
          SendPowerSchedulerEvent(PowerSchedulerEventType.SystemBusy);
        }
        _standby = false;
        // <--- INSIDE lock!!!

        // if real resume, run command
        RunExternalCommand("wakeup");

        // reinitialize TVController if system is configured to do so and not already done
        ReInitController();
      }

      if (!_controller.EpgGrabberEnabled)
        _controller.EpgGrabberEnabled = true;
      SendPowerSchedulerEvent(PowerSchedulerEventType.ResumedFromStandby);
    }
コード例 #13
0
 private void Suspend(PowerEventType powerStatus)
 {
   if (powerStatus == PowerEventType.Suspend)
     Log.Debug("PowerScheduler: System is going to suspend");
   else if (powerStatus == PowerEventType.StandBy)
     Log.Debug("PowerScheduler: System is going to standby");
   _denySuspendQuery = true; // reset the flag
   _standby = true;
   _controller.EpgGrabberEnabled = false;
   SetWakeupTimer();
   DeInitController();
   RunExternalCommand("suspend");
   SendPowerSchedulerEvent(PowerSchedulerEventType.EnteringStandby, false);
 }
コード例 #14
0
 private bool OnPowerEvent(PowerEventType powerStatus)
 {
   switch (powerStatus)
   {
     case PowerEventType.QuerySuspend:
     case PowerEventType.QueryStandBy:
       Log.Debug("PowerScheduler: System wants to enter standby (query)");
       // First request for suspend, this we will reject by returning false.
       // Instead we will start a shutdown thread that will de-init and last will 
       // issue a new suspend query that will accept.
       if (_denySuspendQuery)
       {
         Log.Debug("PowerScheduler: Suspend queried, starting suspend sequence");
         // Always try to Hibernate (S4). If system is set to S3, then Hibernate will fail and result will be S3
         SuspendSystem("System", (int)RestartOptions.Hibernate, false);
         return false;
       }
       return true;
     case PowerEventType.Suspend:
     case PowerEventType.StandBy:
       Suspend(powerStatus);
       return true;
     case PowerEventType.QuerySuspendFailed:
     case PowerEventType.QueryStandByFailed:
       _querySuspendFailed--;
       Log.Debug("PowerScheduler: Entering standby was disallowed (blocked)");
       return true;
     case PowerEventType.ResumeAutomatic:
     case PowerEventType.ResumeCritical:
     case PowerEventType.ResumeSuspend:
       // note: this event may not arrive unless the user has moved the mouse or hit a key
       // so, we should also handle ResumeAutomatic and ResumeCritical (as done above)
       Resume(powerStatus);
       return true;
   }
   return true;
 }