예제 #1
0
        protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
        {
            Log.WriteSystemEventLog("MCEBuddy OnPowerEvent called by System, Event -> " + powerStatus.ToString(), EventLogEntryType.Information);

            MCEBuddyConf.GlobalMCEConfig = new MCEBuddyConf(GlobalDefs.ConfigFile); // Update the settings for global objects

            switch (powerStatus)
            {
            case PowerBroadcastStatus.PowerStatusChange:     // Something changed, lets find out if we are in battery mode or  a/c mode
                try
                {
                    Log.WriteSystemEventLog("Power Status Change Notification, Power Status -> " + System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus.ToString(), EventLogEntryType.Information);

                    if (System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus == System.Windows.Forms.PowerLineStatus.Offline) // If we are on battery power
                    {
                        if (MCEBuddyConf.GlobalMCEConfig.GeneralOptions.suspendOnBattery)                                                   // If we are requested to Pause on battery power
                        {
                            _pipeProxy.SuspendConversion(true);                                                                             // Suspend it
                        }
                    }
                    else if (_pipeProxy.WithinConversionTimes()) // Resume only if we are within Conversion times else it will auto resume at the right time
                    {
                        _pipeProxy.SuspendConversion(false);     // Resume it (assume A/C power)
                    }
                }
                catch (Exception e)
                {
                    Log.WriteSystemEventLog("Error trying to change suspend mode on Power Event in MCEBuddy " + e.ToString(), EventLogEntryType.Warning);
                }

                break;

            case PowerBroadcastStatus.QuerySuspend:     // Can the system go into suspend mode?
                try
                {
                    return(_pipeProxy.AllowSuspend());    // Check if the engine is ready to go into suspend mode
                }
                catch (Exception e)
                {
                    Log.WriteSystemEventLog("Error trying to get suspend permission from MCEBuddy " + e.ToString(), EventLogEntryType.Warning);
                    return(true);
                }

            case PowerBroadcastStatus.BatteryLow:  // On battery low automatically suspend the conversion
            case PowerBroadcastStatus.Suspend:     // System is being suspended, pause all activity and flush the buffers
                try
                {
                    _pipeProxy.SuspendConversion(true);     // suspend and buffers are flushed when suspended
                }
                catch (Exception e)
                {
                    Log.WriteSystemEventLog("Error trying to suspend MCEBuddy " + e.ToString(), EventLogEntryType.Warning);
                }

                break;

            case PowerBroadcastStatus.ResumeAutomatic:     // system resuming from suspend, resume MCEBuddy
            case PowerBroadcastStatus.ResumeCritical:
            case PowerBroadcastStatus.ResumeSuspend:
                try
                {
                    if (_pipeProxy.WithinConversionTimes())     // Resume only if we are within Conversion times else it will auto resume at the right time
                    {
                        _pipeProxy.SuspendConversion(false);    // Resume
                    }
                }
                catch (Exception e)
                {
                    Log.WriteSystemEventLog("Error trying to resume MCEBuddy " + e.ToString(), EventLogEntryType.Warning);
                }
                break;
            }

            return(true);
        }