Пример #1
0
 private void removeToolStripButton_Click(object sender, EventArgs e)
 {
     if (lvwPerfCounters.SelectedItems.Count > 0)
     {
         if (MessageBox.Show("Are you sure you want to remove the selected entry(s)?", "Remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
         {
             foreach (ListViewItem lvi in lvwPerfCounters.SelectedItems)
             {
                 QMPerfCounterInstance removeItem = (QMPerfCounterInstance)lvi.Tag;
                 PFConfig.QMPerfCounters.Remove(removeItem);
                 lvwPerfCounters.Items.Remove(lvi);
             }
         }
     }
 }
Пример #2
0
        public void ReadConfig(XmlDocument config)
        {
            XmlElement root = config.DocumentElement;

            QMPerfCounters.Clear();
            foreach (XmlElement pcNode in root.SelectNodes("performanceCounters/performanceCounter"))
            {
                QMPerfCounterInstance qmPerfCounterInstance = new QMPerfCounterInstance();
                qmPerfCounterInstance.Computer            = pcNode.ReadXmlElementAttr("computer", ".");
                qmPerfCounterInstance.Category            = pcNode.ReadXmlElementAttr("category", "Processor");
                qmPerfCounterInstance.Counter             = pcNode.ReadXmlElementAttr("counter", "% Processor Time");
                qmPerfCounterInstance.Instance            = pcNode.ReadXmlElementAttr("instance", "");
                qmPerfCounterInstance.ReturnValueInverted = bool.Parse(pcNode.ReadXmlElementAttr("returnValueInverted", "False"));
                qmPerfCounterInstance.WarningValue        = float.Parse(pcNode.ReadXmlElementAttr("warningValue", "80"));
                qmPerfCounterInstance.ErrorValue          = float.Parse(pcNode.ReadXmlElementAttr("errorValue", "100"));
                QMPerfCounters.Add(qmPerfCounterInstance);
            }
        }
Пример #3
0
 private void RefreshList()
 {
     Cursor.Current = Cursors.WaitCursor;
     try
     {
         lvwPerfCounters.BeginUpdate();
         foreach (ListViewItem lvi in lvwPerfCounters.Items)
         {
             try
             {
                 QMPerfCounterInstance pc = (QMPerfCounterInstance)lvi.Tag;
                 float currentValue       = pc.GetNextValue();
                 lvi.SubItems[1].Text = currentValue.ToString("F3");
                 MonitorStates currentState = pc.GetState(currentValue);
                 if (currentState == MonitorStates.Good)
                 {
                     lvi.ImageIndex = 0;
                     lvi.BackColor  = SystemColors.Window;
                 }
                 else if (currentState == MonitorStates.Warning)
                 {
                     lvi.ImageIndex = 1;
                     lvi.BackColor  = Color.SandyBrown;
                 }
                 else
                 {
                     lvi.ImageIndex = 2;
                     lvi.BackColor  = Color.Salmon;
                 }
             }
             catch (Exception ex)
             {
                 lvi.SubItems[1].Text = ex.Message;
             }
         }
         toolStripStatusLabel1.Text = "Last updated: " + DateTime.Now.ToString("yyyy-mm-dd HH:mm:ss");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     lvwPerfCounters.EndUpdate();
     Cursor.Current = Cursors.Default;
 }
Пример #4
0
 private void cmdOK_Click(object sender, EventArgs e)
 {
     if (CheckForValidCounter())
     {
         SelectedPCInstance = new QMPerfCounterInstance()
         {
             Computer = txtComputer.Text,
             Category = lvwCategories.SelectedItems[0].Text,
             Counter  = lvwCounters.SelectedItems[0].Text
         };
         if (lvwInstances.SelectedItems.Count > 0)
         {
             SelectedPCInstance.Instance = lvwInstances.SelectedItems[0].Text;
         }
         else
         {
             SelectedPCInstance.Instance = "";
         }
         DialogResult = System.Windows.Forms.DialogResult.OK;
         Close();
     }
 }
Пример #5
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (txtComputer.Text.Length == 0)
            {
                MessageBox.Show("You must specify the computer!", "Computer", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtComputer.Focus();
            }
            else if (cboCategory.SelectedIndex == -1)
            {
                MessageBox.Show("You must specify the category!", "Category", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cboCategory.Focus();
            }
            else if (cboCounter.SelectedIndex == -1)
            {
                MessageBox.Show("You must specify the counter!", "Counter", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cboCounter.Focus();
            }
            else if (cboInstance.Items.Count > 0 && cboInstance.SelectedIndex == -1)
            {
                MessageBox.Show("You must specify the instance!", "Instance", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cboInstance.Focus();
            }
            //else if (cboScale.SelectedIndex == -1)
            //{
            //    MessageBox.Show("You must specify the scale!", "Scale", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    cboScale.Focus();
            //}
            else
            {
                try
                {
                    //string key = txtComputer.Text + "\\" + cboCategory.Text + "\\" + cboCounter.Text + "\\";
                    //if (cboInstance.Text.Length > 0)
                    //{
                    //    if (cboInstance.Text.Contains("\\"))
                    //        key += "\"" + cboInstance.Text + "\"";
                    //    else
                    //        key += cboInstance.Text;
                    //}
                    //key += "\\" + cboScale.SelectedItem.ToString();
                    //key += "\\" + cboPlotStyle.SelectedIndex.ToString();
                    SelectedPCInstance                     = new QMPerfCounterInstance();
                    SelectedPCInstance.Computer            = txtComputer.Text;
                    SelectedPCInstance.Category            = cboCategory.Text;
                    SelectedPCInstance.Counter             = cboCounter.Text;
                    SelectedPCInstance.Instance            = cboInstance.Text;
                    SelectedPCInstance.ReturnValueInverted = invertValuesCheckBox.Checked;
                    SelectedPCInstance.WarningValue        = (float)warningNumericUpDown.Value;
                    SelectedPCInstance.ErrorValue          = (float)errorNumericUpDown.Value;

                    SelectedPCInstance.InitializePerfCounter();
                    //SelectedPCMonInstance.Scale = double.Parse(cboScale.SelectedItem.ToString());
                    //SelectedPCMonInstance.PlotStyle = cboPlotStyle.SelectedIndex;
                    //SelectedPCMonInstance.PlotColor = pictureBoxColor.BackColor;
                    //InitialColor = pictureBoxColor.BackColor;
                    //SelectedPCMonInstance.CreatePCInstance();

                    DialogResult = DialogResult.OK;
                    Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }