コード例 #1
0
        private void TmCheckPower_Tick(object sender, EventArgs e)
        {
            var idleTimeMin = PcIdle.GetIdleTimeMin();

            // Refresh Form data.
            ShowPowerStatus();
            TbIdleTime.Text = idleTimeMin.ToString("D");

            if (NotifyVoice && NotifyWind)
            {
                // Check if activate Voice notification for idle time.
                IdleVoiceNotify = !NotifyWind || idleTimeMin >= PcIdle.MaxIdleTime;
            }

            if (!Battery.CheckPowerLevel())
            {
                Battery.AuxAlert = false;
                return;
            }
            BtnSpeak.Enabled = false;
            if (Battery.AuxAlert && (Voice.AuxNotVolume += 10) > 100)
            {
                Voice.AuxNotVolume = 100;
            }
            NewNotification($"{Settings.Default.PcName}. {Battery.Msg}");
            TmCheckPower.Stop();
            TmWaitForResp.Start();
            GbNextNot.Enabled = true;
            Application.DoEvents();
        }
コード例 #2
0
 private void AlertChecked(bool cancelVoice)
 {
     try
     {
         if (NotifyVoice && cancelVoice)
         {
             Voice.Checked();
         }
         if (Battery.Checked() && NotifyWind)
         {
             NotifyIcon.ShowBalloonTip(1000, @"Notificación del estado de batería", Battery.Msg, ToolTipIcon.Info);
         }
         AuxAlertTime           = (int)(AuxTimeBatteryCheck * 60);
         ProgBarNextAlert.Value = AuxAlertTime;
         LbTime.Text            = TimeSpan.FromSeconds(AuxAlertTime).ToString(@"mm\:ss");
         TmWaitForResp.Stop();
         Battery.AuxAlert = false;
         if (!TmCheckPower.Enabled)
         {
             TmCheckPower.Start();
         }
         GbNextNot.Enabled = false;
     }
     catch (Exception exp)
     {
         MessageBox.Show(exp.Message);
     }
 }
コード例 #3
0
        //private async Task CheckForUpdates()
        //{
        //    using (var manager = new UpdateManager(@"E:\Documents\Daniel\Google_Drive\PROGRAMACIÓN\C#\BatteryMonitor\Releases"))
        //    {
        //        await manager.UpdateApp();
        //    }
        //}

        #region FormEvents

        private void FormMain_Load(object sender, EventArgs e)
        {
            Battery = new Battery();
            PcIdle  = new PcIdle();
            //Battery.AddPowerModeChanged(PowerModeChanged);
            SystemEvents.PowerModeChanged += PowerModeChanged;
            ShowPowerStatus();
            BtnChecked.EnabledChanged += BtnChecked_EnabledChanged;

            // Get App Name and Version to show in the Form about.
            AppName    = Assembly.GetExecutingAssembly().GetName().Name;
            AppVersion = ApplicationDeployment.IsNetworkDeployed ? $@"v{ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString(4)}" : Assembly.GetExecutingAssembly().GetName().Version.ToString();

            try
            {
                Voice            = new Voice(VoiceCompleted);
                BtnSpeak.Enabled = true;
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, @"Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            LoadProperties();
            if (Battery.ChargeStatus == BatteryChargeStatus.NoSystemBattery)
            {
                NotifyIcon.Icon = Resources.ico_WithoutBatt;
                Icon            = Resources.ico_WithoutBatt;
                return;
            }
#if !DEBUG
            Height = 390;
#endif
            TmCheckPower.Start();
        }
コード例 #4
0
ファイル: FrmMain.cs プロジェクト: daniel-rr213/BatteryStatus
        private void NotificationsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var frmNotSetTime = new FrmNotSetTime(_timeBattChk, _auxTimeBattChk, PcInnactivity.MaxIdleTime, Battery.LowBattLevel, Battery.HighBattLevel);

            frmNotSetTime.ShowDialog();
            if (!frmNotSetTime.Changes)
            {
                return;
            }
            //Stop timers.
            TmCheckPower.Stop();
            TmWaitForResp.Stop();
            //Get frmNotSetTime values.
            _timeBattChk    = frmNotSetTime.TimeBattChk;
            _auxTimeBattChk = frmNotSetTime.AuxTimeBattChk;
            Battery.ChangeLowBattLevel(frmNotSetTime.LowBattery);
            Battery.ChangeHighBattLevel(frmNotSetTime.HighBattery);
            PcInnactivity.ChangeMaxIdleTime(frmNotSetTime.IdleTime);
            //Save in properties
            Settings.Default.BatteryHigh    = Battery.HighBattLevel;
            Settings.Default.BatteryLow     = Battery.LowBattLevel;
            Settings.Default.PcIdleTime     = PcInnactivity.MaxIdleTime;
            Settings.Default.TimeBattChk    = _timeBattChk;
            Settings.Default.TimeAuxBattChk = _auxTimeBattChk;
            Settings.Default.Save();
            //Changes timer intervals.
            TmCheckPower.Interval  = (int)_timeBattChk * 1000;
            TmWaitForResp.Interval = (int)_auxTimeBattChk * 60000;
            //Restart timers.
            TmCheckPower.Start();
            TmWaitForResp.Start();
        }
コード例 #5
0
        //TODO: Check the constant trigger event.
        private void PowerModeChanged(object sender, PowerModeChangedEventArgs e)
        {
            //ShowPowerStatus();
            switch (e.Mode)
            {
            case PowerModes.Resume:
                Battery.AuxAlert = false;
                break;

            case PowerModes.StatusChange:
                switch (Battery.ChargeStatus)
                {
                case BatteryChargeStatus.NoSystemBattery:
                    TmCheckPower.Stop();
                    TmWaitForResp.Stop();
                    //
                    var notifyIcon = Resources.ico_WithoutBatt;
                    NotifyIcon.Icon = notifyIcon;
                    Icon            = notifyIcon;
                    break;

                case BatteryChargeStatus.Charging:
                    if (!TmWaitForResp.Enabled)
                    {
                        break;
                    }
                    TmWaitForResp.Stop();
                    TmCheckPower.Start();
                    break;

                // ReSharper disable RedundantCaseLabel
                case BatteryChargeStatus.Unknown:
                case BatteryChargeStatus.High:
                case BatteryChargeStatus.Low:
                case BatteryChargeStatus.Critical:
                // ReSharper restore RedundantCaseLabel
                default:
                    //
                    //notifyIcon = Battery.IsCharging ? Resources.ico_chargingNormal : Resources.ico_DisconnectNormal;
                    //
                    if (!TmWaitForResp.Enabled)
                    {
                        break;
                    }
                    TmWaitForResp.Stop();
                    TmCheckPower.Start();
                    AlertChecked(false);
                    break;
                }
                break;

            case PowerModes.Suspend:
                Voice.Checked();
                break;

            default:
                throw new NotImplementedException();
            }
        }
コード例 #6
0
 private void TmWaitForResp_Tick(object sender, EventArgs e)
 {
     if (AuxAlertTime-- == 0)
     {
         // Reset time.
         AuxAlertTime = (int)(AuxTimeBatteryCheck * 60);
         TmWaitForResp.Stop();
         TmCheckPower.Start();
         return;
     }
     ShowPowerStatus();
     LbTime.Text            = TimeSpan.FromSeconds(AuxAlertTime).ToString(@"mm\:ss");
     ProgBarNextAlert.Value = AuxAlertTime;
 }
コード例 #7
0
ファイル: FrmMain.cs プロジェクト: daniel-rr213/BatteryStatus
        private void FormMain_Load(object sender, EventArgs e)
        {
            AutoRunLoad();
            Battery       = new Battery();
            PcInnactivity = new PcInnactivity();
            SystemEvents.PowerModeChanged += PowerModeChanged;
            ShowPowerStatus();
            BtnChecked.EnabledChanged += BtnChecked_EnabledChanged;

            try
            {
                Voice            = new Voice(VoiceCompleted);
                BtnSpeak.Enabled = true;
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, @"Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            LoadPropeties();
            TmCheckPower.Start();
        }
コード例 #8
0
        private void SettingsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //TODO: Fix the way to pass parameters.
            using (var formSettings = new FormSettings(TimeBatteryCheck, AuxTimeBatteryCheck, PcIdle.MaxIdleTime, Battery.LowBatteryLvl, Battery.HighBatteryLvl, Voice, NotifyWind, NotifyVoice, Battery.AlertStatus))
            {
                //Recall for check if there is an installed voice.
                Voice.GetVoices();
                // SHOW Form
                formSettings.ShowDialog();
                // Check if the user make any change.
                if (!formSettings.HasChanges)
                {
                    return;
                }
                #region Notification
                //Stop timers.
                // Save the Status of the Timer.
                //var isTmCheckPowerEnabled = TmCheckPower.Enabled;
                AlertChecked(false);
                TmCheckPower.Stop();
                TmWaitForResp.Stop();
                //
                Battery.ChangeAlertStatus(new[] { formSettings.ChBoxLowBat, formSettings.ChBoxHighBat });
                Battery.ChangePrevAlert(Any);
                Battery.ResetAlert();
                //Get formSettings values.
                NotifyWind          = formSettings.NotifyWind;
                NotifyVoice         = formSettings.NotifyVoice;
                TimeBatteryCheck    = formSettings.TimeBatChk;
                AuxTimeBatteryCheck = formSettings.AuxTimeBatChk;
                Battery.ChangeLowBatteryLvl(formSettings.LowBattery);
                Battery.ChangeHighBatteryLvl(formSettings.HighBattery);
                PcIdle.ChangeMaxIdleTime(formSettings.IdleTime);

                //Save in properties
                Settings.Default.BatteryHigh    = Battery.HighBatteryLvl;
                Settings.Default.BatteryLow     = Battery.LowBatteryLvl;
                Settings.Default.PcIdleTime     = PcIdle.MaxIdleTime;
                Settings.Default.TimeBattChk    = TimeBatteryCheck;
                Settings.Default.TimeAuxBattChk = AuxTimeBatteryCheck;
                Settings.Default.NotifyWind     = NotifyWind;
                Settings.Default.NotifyVoice    = NotifyVoice;
                Settings.Default.AlertStatus    = string.Join(",", Battery.AlertStatus);
                //Changes timer intervals.
                TmCheckPower.Interval    = (int)TimeBatteryCheck * 1000;
                AuxAlertTime             = (int)(AuxTimeBatteryCheck * 60);
                ProgBarNextAlert.Maximum = AuxAlertTime;
                //Restart timers.
                //TmCheckPower.Enabled = isTmCheckPowerEnabled;
                TmCheckPower.Start();
                #endregion
                #region Voz
                try
                {
                    Settings.Default.VoiceName = formSettings.CurrentVoice;
                    Settings.Default.VolNot    = formSettings.NotifyVolume;
                    Voice.ChangeCurrentVoice(formSettings.CurrentVoice);
                    Voice.ChangeNotVolume(formSettings.NotifyVolume);
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message, @"Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                #endregion
                Voice?.ChangePcName(formSettings.PcName);
                Settings.Default.PcName = formSettings.PcName;
                Settings.Default.Save();
            }
        }