Example #1
0
        // Get the current property values from PowerManager.
        // This method is called on startup.
        private void GetPowerSettings()
        {
            settings.PowerPersonality = PowerManager.PowerPersonality.ToString();
            settings.PowerSource      = PowerManager.PowerSource.ToString();
            settings.BatteryPresent   = PowerManager.IsBatteryPresent;
            settings.UpsPresent       = PowerManager.IsUpsPresent;
            settings.MonitorOn        = PowerManager.IsMonitorOn;
            settings.MonitorRequired  = PowerManager.MonitorRequired;

            if (PowerManager.IsBatteryPresent)
            {
                settings.BatteryShortTerm   = PowerManager.IsBatteryShortTerm;
                settings.BatteryLifePercent = PowerManager.BatteryLifePercent;

                BatteryState batteryState = PowerManager.GetCurrentBatteryState();

                string batteryStateStr = string.Format(
                    "ACOnline: {1}{0}Max Charge: {2} mWh{0}Current Charge: {3} mWh{0}Charge Rate: {4} {0}Estimated Time Remaining: {5}{0}Suggested Critical Battery Charge: {6} mWh{0}Suggested Battery Warning Charge: {7} mWh{0}",
                    Environment.NewLine,
                    batteryState.ACOnline,
                    batteryState.MaxCharge,
                    batteryState.CurrentCharge,
                    batteryState.ACOnline == true ? "N/A" : batteryState.ChargeRate.ToString() + " mWh",
                    batteryState.ACOnline == true ? "N/A" : batteryState.EstimatedTimeRemaining.ToString(),
                    batteryState.SuggestedCriticalBatteryCharge,
                    batteryState.SuggestedBatteryWarningCharge
                    );

                settings.BatteryState = batteryStateStr;
            }
        }
Example #2
0
        public void DischargeRateIsNegativeIfNotPluggedIn()
        {
            BatteryState s = PowerManager.GetCurrentBatteryState();

            if (!s.ACOnline)
            {
                Assert.True(s.ChargeRate < 0);
            }
        }
Example #3
0
        private void btnBatarya_Click(object sender, EventArgs e)
        {
            lblBesleme.Text = PowerManager.PowerSource.ToString();

            BatteryState batteryState = PowerManager.GetCurrentBatteryState();

            progressBar1.Value   = PowerManager.BatteryLifePercent;
            lblSarjYuzde.Text    = PowerManager.BatteryLifePercent.ToString() + "%";
            lblMaksimumSarj.Text = batteryState.MaxCharge + " mWh";
            lblGecerliSarj.Text  = batteryState.CurrentCharge + " mWh";
        }
Example #4
0
        public void ConfirmBatteryState()
        {
            BatteryState s = PowerManager.GetCurrentBatteryState();

            Assert.InRange(s.CurrentCharge, 0, int.MaxValue);
            // TODO: add more tests with heuristics here (i.e. when not plugged in, est time remaining < a reasonable number, etc.)
            Assert.InRange(s.EstimatedTimeRemaining, TimeSpan.MinValue, TimeSpan.MaxValue);
            Assert.InRange(s.MaxCharge, 0, int.MaxValue);

            // The max values below are just numbers we picked.
            Assert.InRange(s.SuggestedBatteryWarningCharge, 0, 10000);
            Assert.InRange(s.SuggestedCriticalBatteryCharge, 0, 10000);
        }
Example #5
0
        // Get the current property values from PowerManager.
        // This method is called on startup.
        private void GetPowerSettings()
        {
            settings.PowerPersonality = PowerManager.PowerPersonality.ToString();
            settings.PowerSource      = PowerManager.PowerSource.ToString();
            settings.BatteryPresent   = PowerManager.IsBatteryPresent;
            settings.UpsPresent       = PowerManager.IsUpsPresent;
            settings.MonitorOn        = PowerManager.IsMonitorOn;
            settings.MonitorRequired  = PowerManager.MonitorRequired;

            if (PowerManager.IsBatteryPresent)
            {
                settings.BatteryShortTerm   = PowerManager.IsBatteryShortTerm;
                settings.BatteryLifePercent = PowerManager.BatteryLifePercent;
                settings.BatteryState       = PowerManager.GetCurrentBatteryState().ToString();
            }
        }
Example #6
0
        static void PowerManager_BatteryLifePercentChanged(object sender, EventArgs e)
        {
            BatteryLifePercent = PowerManager.BatteryLifePercent;
            Log.Write("BatteryLifePercent changed to: " + BatteryLifePercent);

            BatteryState state = PowerManager.GetCurrentBatteryState();

            if (state.CurrentCharge <= state.SuggestedCriticalBatteryCharge)
            {
                if (Engine.Instance.IsRunning())
                {
                    Engine.Instance.Stop();
                }
            }
            else
            {
                if (!Engine.Instance.IsRunning())
                {
                    Engine.Instance.Start();
                }
            }
        }
Example #7
0
 public void PowerSourceCorrespondsToAcOnlineProperty(bool acOnlineState, PowerSource powerSourceState) => Assert.Equal <bool>(
     acOnlineState == PowerManager.GetCurrentBatteryState().ACOnline,
     powerSourceState == PowerManager.PowerSource);
Example #8
0
 public static void GetBatteryRemaining()
 {
     BatteryState batteryState = PowerManager.GetCurrentBatteryState();
     bool         isInternet   = NetworkListManager.IsConnectedToInternet;
 }