Exemple #1
0
        public MainForm()
        {
            LogLevels = new List <NameValuePair>();

            LogLevels.Add(new NameValuePair()
            {
                name = "Event", id = (int)NutLog.ELogLevel.Event
            });
            LogLevels.Add(new NameValuePair()
            {
                name = "Trace", id = (int)NutLog.ELogLevel.Trace
            });
            LogLevels.Add(new NameValuePair()
            {
                name = "Debug", id = (int)NutLog.ELogLevel.Debug
            });

            InitializeComponent();

            cboLogLevel.DisplayMember = "name";
            cboLogLevel.ValueMember   = "id";
            cboLogLevel.DataSource    = LogLevels;

            notifyIcon.Icon = Properties.Resources.NotifyIcon;

            NutLog.LogEvent += NutLog_LogEvent;
            nut              = new NutControl(application: true);
            nut.nut.update  += Nut_update;

            InitDisplay();
        }
Exemple #2
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            nut.cfg.afterSeconds     = int.Parse(txtSecondsOnBattery.Text);
            nut.cfg.secondsRemaining = int.Parse(txtSecondRemaining.Text);
            nut.cfg.percentRemaining = int.Parse(txtPercentRemaining.Text);
            nut.cfg.hostname         = txtHostname.Text;
            nut.cfg.port             = int.Parse(txtPort.Text);
            nut.cfg.upsDevice        = txtUPSDevice.Text;
            nut.cfg.pollPeriod       = int.Parse(txtPollPeriod.Text);
            if (txtPassword.TextLength > 0)
            {
                nut.cfg.password = txtPassword.Text;
            }
            nut.cfg.minimiseToTray   = chkMinimiseToTray.Checked;
            nut.cfg.startWithWindows = chkStartWithWindows.Checked;
            nut.cfg.logLevel         = (NutLog.ELogLevel)cboLogLevel.SelectedValue;

            if (nut.cfg.startWithWindows && nut.cfg.runAs == NutConfig.ERunAs.Application)
            {
                Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", Application.ProductName, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
            }
            else
            {
                Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", Application.ProductName, "");
            }

            nut.cfg.write();

            nut.Stop();
            nut.nut.update -= Nut_update;

            nut             = new NutControl(application: true);
            nut.nut.update += Nut_update;
            nut.Start();
        }