Exemplo n.º 1
0
        private void HandlePowerModeChanged(object sender, PowerModeChangedEventArgs e)
        {
            Debug.WriteLine($"{nameof(HandlePowerModeChanged)} triggered: {e.Mode}");
            PowerBroadcastStatus powerBroadcastStatus = new PowerBroadcastStatus();

            Debug.WriteLine($"{nameof(powerBroadcastStatus)} = {powerBroadcastStatus}");
            PowerLineStatus powerLineStatus = SystemInformation.PowerStatus.PowerLineStatus;

            Debug.WriteLine($"{nameof(powerLineStatus)} = {powerLineStatus} --- Is Running Battery? {(powerLineStatus == PowerLineStatus.Offline)}");

            switch (e.Mode)
            {
            case PowerModes.Resume:
                // online state resumed
                break;

            case PowerModes.StatusChange:
                // status changed from AC to battery or vice-versa
                Debug.WriteLine($"{nameof(HandlePowerModeChanged)} received {e.Mode} -- current {nameof(PowerBroadcastStatus)} is {powerBroadcastStatus}");
                switch (powerLineStatus)
                {
                case PowerLineStatus.Online:
                    _alertManager.NotifyPowerFromWall();
                    break;

                case PowerLineStatus.Offline:
                    _alertManager.NotifyPowerOnBattery();
                    break;

                case PowerLineStatus.Unknown:
                    Debug.WriteLine($"Unable to process value '{powerBroadcastStatus}'.  Exiting early.");
                    break;

                default:
                    throw new NotSupportedException($"Unsure how to handle status of '{powerLineStatus}' !!");
                }
                break;

            case PowerModes.Suspend:
                // going into suspended power mode
                break;
            }

            _currentPowerMode       = e.Mode;
            _currentPowerLineStatus = powerLineStatus;
        }
 public void TriggerBatteryToAc()
 {
     OnPowerEvent(PowerBroadcastStatus.PowerStatusChange);
     _alertManager.NotifyPowerFromWall();
 }