//public List<RegistryQueryInstance> Queries = new List<RegistryQueryInstance>();

        #region IAgentConfig Members
        public void ReadConfiguration(string configurationString)
        {
            XmlDocument config = new XmlDocument();

            if (configurationString == null || configurationString.Length == 0)
            {
                config.LoadXml(Properties.Resources.RegistryQueryCollectorDefaultConfig);
            }
            else
            {
                config.LoadXml(configurationString);
            }
            XmlElement root = config.DocumentElement;

            Entries.Clear();
            foreach (XmlElement queryNode in root.SelectNodes("queries/query"))
            {
                RegistryQueryInstance queryEntry = new RegistryQueryInstance();
                queryEntry.Name                   = queryNode.ReadXmlElementAttr("name", "");
                queryEntry.UseRemoteServer        = bool.Parse(queryNode.ReadXmlElementAttr("useRemoteServer", "False"));
                queryEntry.Server                 = queryNode.ReadXmlElementAttr("server", "");
                queryEntry.RegistryHive           = RegistryQueryInstance.GetRegistryHiveFromString(queryNode.ReadXmlElementAttr("registryHive", ""));
                queryEntry.Path                   = queryNode.ReadXmlElementAttr("path", "");
                queryEntry.KeyName                = queryNode.ReadXmlElementAttr("keyName", "");
                queryEntry.ExpandEnvironmentNames = bool.Parse(queryNode.ReadXmlElementAttr("expandEnvironmentNames", "False"));

                queryEntry.ReturnValueIsNumber = bool.Parse(queryNode.ReadXmlElementAttr("returnValueIsNumber", "False"));
                queryEntry.SuccessValue        = queryNode.ReadXmlElementAttr("successValue", "");
                queryEntry.WarningValue        = queryNode.ReadXmlElementAttr("warningValue", "");
                queryEntry.ErrorValue          = queryNode.ReadXmlElementAttr("errorValue", "");
                queryEntry.ReturnValueInARange = bool.Parse(queryNode.ReadXmlElementAttr("returnValueInARange", "False"));
                queryEntry.ReturnValueInverted = bool.Parse(queryNode.ReadXmlElementAttr("returnValueInverted", "False"));
                Entries.Add(queryEntry);
            }
        }
Exemplo n.º 2
0
        private void cmdTest_Click(object sender, EventArgs e)
        {
            if (DoValidate())
            {
                string lastStep = "Initialize values";
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    RegistryQueryInstance testQueryInstance = new RegistryQueryInstance();
                    testQueryInstance.Name                   = txtName.Text;
                    testQueryInstance.UseRemoteServer        = chkUseRemoteServer.Checked;
                    testQueryInstance.Server                 = txtServer.Text;
                    testQueryInstance.Path                   = txtPath.Text;
                    testQueryInstance.KeyName                = txtKey.Text;
                    testQueryInstance.ExpandEnvironmentNames = chkExpandEnvNames.Checked;
                    testQueryInstance.RegistryHive           = RegistryQueryInstance.GetRegistryHiveFromString(cboRegistryHive.Text);

                    if (!chkValueIsANumber.Checked)
                    {
                        testQueryInstance.ReturnValueIsNumber = false;
                        testQueryInstance.ReturnValueInARange = false;
                        testQueryInstance.ReturnValueInverted = false;
                    }
                    else
                    {
                        testQueryInstance.ReturnValueIsNumber = true;
                        testQueryInstance.ReturnValueInARange = chkValueIsInARange.Checked;
                        testQueryInstance.ReturnValueInverted = !chkReturnValueNotInverted.Checked;
                    }

                    testQueryInstance.SuccessValue = cboSuccessValue.Text;
                    testQueryInstance.WarningValue = cboWarningValue.Text;
                    testQueryInstance.ErrorValue   = cboErrorValue.Text;

                    object returnValue = null;
                    returnValue = testQueryInstance.GetValue();
                    CollectorState state = testQueryInstance.EvaluateValue(returnValue);
                    if (state == CollectorState.Good)
                    {
                        MessageBox.Show(string.Format("Success!\r\nValue return: {0}", FormatUtils.FormatArrayToString(returnValue)), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (state == CollectorState.Warning)
                    {
                        MessageBox.Show(string.Format("Warning!\r\nValue return: {0}", FormatUtils.FormatArrayToString(returnValue)), "Test", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        MessageBox.Show(string.Format("Error!\r\nValue return: {0}", FormatUtils.FormatArrayToString(returnValue)), "Test", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("Failed!\r\nLast step: {0}\r\n{1}", lastStep, ex.Message), "Test", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }
        }
Exemplo n.º 3
0
 private void txtPath_Leave(object sender, EventArgs e)
 {
     if (txtPath.Text.Length > 0 && txtPath.Text.ToUpper().StartsWith("HKEY_"))
     {
         string[] parts = txtPath.Text.Split('\\');
         if (parts.Length > 1)
         {
             Microsoft.Win32.RegistryHive rh = RegistryQueryInstance.GetRegistryHiveFromString(parts[0]);
             cboRegistryHive.Text = rh.ToString();
             txtPath.Text         = txtPath.Text.Substring(parts[0].Length + 1);
         }
     }
 }
Exemplo n.º 4
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (DoValidate())
            {
                RegistryQueryInstance selectedEntry;
                if (SelectedEntry != null)
                {
                    selectedEntry = (RegistryQueryInstance)SelectedEntry;
                }
                else if (SelectedRegistryQueryInstance != null)
                {
                    selectedEntry = (RegistryQueryInstance)SelectedRegistryQueryInstance;
                }
                else
                {
                    selectedEntry = new RegistryQueryInstance();
                    SelectedEntry = selectedEntry;
                }

                selectedEntry.Name                   = txtName.Text;
                selectedEntry.UseRemoteServer        = chkUseRemoteServer.Checked;
                selectedEntry.Server                 = txtServer.Text;
                selectedEntry.Path                   = txtPath.Text;
                selectedEntry.KeyName                = txtKey.Text;
                selectedEntry.ExpandEnvironmentNames = chkExpandEnvNames.Checked;
                selectedEntry.RegistryHive           = RegistryQueryInstance.GetRegistryHiveFromString(cboRegistryHive.Text);

                if (!chkValueIsANumber.Checked)
                {
                    selectedEntry.ReturnValueIsNumber = false;
                    selectedEntry.ReturnValueInARange = false;
                    selectedEntry.ReturnValueInverted = false;
                }
                else
                {
                    selectedEntry.ReturnValueIsNumber = true;
                    selectedEntry.ReturnValueInARange = chkValueIsInARange.Checked;
                    selectedEntry.ReturnValueInverted = !chkReturnValueNotInverted.Checked;
                }

                selectedEntry.SuccessValue = cboSuccessValue.Text;
                selectedEntry.WarningValue = cboWarningValue.Text;
                selectedEntry.ErrorValue   = cboErrorValue.Text;
                DialogResult = System.Windows.Forms.DialogResult.OK;
                Close();
            }
        }
Exemplo n.º 5
0
        public override void OKClicked()
        {
            if (CheckOKEnabled())
            {
                if (SelectedConfig == null)
                {
                    SelectedConfig = new RegistryQueryCollectorConfig();
                }
                RegistryQueryCollectorConfig currentConfig = (RegistryQueryCollectorConfig)SelectedConfig;
                currentConfig.Entries.Clear();

                foreach (ListViewItem lvi in lvwEntries.Items)
                {
                    RegistryQueryInstance registryQueryInstance = (RegistryQueryInstance)lvi.Tag;
                    currentConfig.Entries.Add(registryQueryInstance);
                }
                DialogResult = System.Windows.Forms.DialogResult.OK;
                Close();
            }
        }
Exemplo n.º 6
0
 public override void EditItem()
 {
     if (lvwEntries.SelectedItems.Count > 0)
     {
         ListViewItem lvi = lvwEntries.SelectedItems[0];
         RegistryQueryCollectorEditInstance editQueryInstance = new RegistryQueryCollectorEditInstance();
         editQueryInstance.SelectedRegistryQueryInstance = (RegistryQueryInstance)lvi.Tag;
         if (editQueryInstance.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             lvi.Text             = editQueryInstance.SelectedRegistryQueryInstance.Name;
             lvi.SubItems[1].Text = (editQueryInstance.SelectedRegistryQueryInstance.UseRemoteServer ? editQueryInstance.SelectedRegistryQueryInstance.Server + "\\" : "") + RegistryQueryInstance.GetRegistryHiveFromString(editQueryInstance.SelectedRegistryQueryInstance.RegistryHive.ToString()).ToString() + "\\" + editQueryInstance.SelectedRegistryQueryInstance.Path;
             lvi.SubItems[2].Text = editQueryInstance.SelectedRegistryQueryInstance.KeyName;
             lvi.SubItems[3].Text = editQueryInstance.SelectedRegistryQueryInstance.SuccessValue;
             lvi.SubItems[4].Text = editQueryInstance.SelectedRegistryQueryInstance.WarningValue;
             lvi.SubItems[5].Text = editQueryInstance.SelectedRegistryQueryInstance.ErrorValue;
             lvi.Tag = editQueryInstance.SelectedRegistryQueryInstance;
             CheckOKEnabled();
         }
     }
 }
        public override void RefreshDisplayData()
        {
            try
            {
                lvwEntries.BeginUpdate();
                if (Collector != null && Collector.AgentConfig != null)
                {
                    foreach (ListViewItem lvi in lvwEntries.Items)
                    {
                        if (lvi.Tag is RegistryQueryInstance)
                        {
                            RegistryQueryInstance rq = (RegistryQueryInstance)lvi.Tag;

                            try
                            {
                                object         value        = rq.GetValue();
                                CollectorState currentState = rq.EvaluateValue(value);
                                if (value == null)
                                {
                                    lvi.SubItems[2].Text = "Null";
                                }
                                else
                                {
                                    lvi.SubItems[2].Text = value.ToString();
                                }
                                if (currentState == CollectorState.Good)
                                {
                                    lvi.ImageIndex = 0;
                                    lvi.BackColor  = SystemColors.Window;
                                }
                                else if (currentState == CollectorState.Warning)
                                {
                                    lvi.ImageIndex = 1;
                                    lvi.BackColor  = Color.SandyBrown;
                                }
                                else
                                {
                                    lvi.ImageIndex = 2;
                                    lvi.BackColor  = Color.Salmon;
                                }
                            }
                            catch (Exception ex)
                            {
                                lvi.SubItems[2].Text = ex.Message;
                                lvi.ImageIndex       = 2;
                                lvi.BackColor        = Color.Salmon;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                lvwEntries.EndUpdate();
                toolStripStatusLabelDetails.Text = "Last updated " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            }
        }
 public void LoadDisplayData()
 {
     if (Collector != null && Collector.AgentConfig != null)
     {
         lvwEntries.Items.Clear();
         foreach (RegistryQueryInstance rq in ((RegistryQueryCollectorConfig)Collector.AgentConfig).Queries)
         {
             ListViewItem lvi = new ListViewItem(rq.Name);
             lvi.SubItems.Add((rq.UseRemoteServer ? "[" + rq.Server + "]\\" : "") + RegistryQueryInstance.GetRegistryHiveFromString(rq.RegistryHive.ToString()).ToString() + "\\" + rq.Path + "\\@[" + rq.KeyName + "]");
             lvi.SubItems.Add("-");
             lvi.Tag = rq;
             lvwEntries.Items.Add(lvi);
         }
     }
 }