private void EditRegistryQueryInstance_Shown(object sender, EventArgs e)
        {
            RegistryQueryCollectorConfigEntry selectedEntry = (RegistryQueryCollectorConfigEntry)SelectedEntry;

            if (selectedEntry != null)
            {
                txtName.Text = selectedEntry.Name;
                chkUseRemoteServer.Checked    = selectedEntry.UseRemoteServer;
                txtServer.Text                = selectedEntry.Server;
                cboRegistryHive.SelectedIndex =
                    selectedEntry.RegistryHive == Microsoft.Win32.RegistryHive.LocalMachine ? 0 :
                    selectedEntry.RegistryHive == Microsoft.Win32.RegistryHive.ClassesRoot ? 1 :
                    selectedEntry.RegistryHive == Microsoft.Win32.RegistryHive.CurrentUser ? 2 :
                    selectedEntry.RegistryHive == Microsoft.Win32.RegistryHive.Users ? 3 :
                    selectedEntry.RegistryHive == Microsoft.Win32.RegistryHive.CurrentConfig ? 4 : 0;
                txtPath.Text = selectedEntry.Path;
                txtKey.Text  = selectedEntry.KeyName;
                chkExpandEnvNames.Checked         = selectedEntry.ExpandEnvironmentNames;
                chkValueIsANumber.Checked         = selectedEntry.ReturnValueIsNumber;
                chkValueIsInARange.Checked        = selectedEntry.ReturnValueInARange;
                chkReturnValueNotInverted.Checked = !selectedEntry.ReturnValueInverted;
                cboSuccessValue.Text = selectedEntry.SuccessValue;
                cboWarningValue.Text = selectedEntry.WarningValue;
                cboErrorValue.Text   = selectedEntry.ErrorValue;
            }
        }
        private void cmdTest_Click(object sender, EventArgs e)
        {
            if (DoValidate())
            {
                string lastStep = "Initialize values";
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    RegistryQueryCollectorConfigEntry testQueryInstance = new RegistryQueryCollectorConfigEntry();
                    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           = RegistryQueryCollectorConfigEntry.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;
                }
            }
        }
예제 #3
0
        public void FromXml(string configurationString)
        {
            XmlDocument config = new XmlDocument();

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

            Entries.Clear();
            foreach (XmlElement queryNode in root.SelectNodes("queries/query"))
            {
                RegistryQueryCollectorConfigEntry queryEntry = new RegistryQueryCollectorConfigEntry();
                queryEntry.Name                   = queryNode.ReadXmlElementAttr("name", "");
                queryEntry.UseRemoteServer        = bool.Parse(queryNode.ReadXmlElementAttr("useRemoteServer", "False"));
                queryEntry.Server                 = queryNode.ReadXmlElementAttr("server", "");
                queryEntry.RegistryHive           = RegistryQueryCollectorConfigEntry.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);
            }
        }
 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 = RegistryQueryCollectorConfigEntry.GetRegistryHiveFromString(parts[0]);
             cboRegistryHive.Text = rh.ToString();
             txtPath.Text         = txtPath.Text.Substring(parts[0].Length + 1);
         }
     }
 }
        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (DoValidate())
            {
                if (SelectedEntry == null)
                {
                    SelectedEntry = new RegistryQueryCollectorConfigEntry();
                }
                RegistryQueryCollectorConfigEntry selectedEntry = (RegistryQueryCollectorConfigEntry)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           = RegistryQueryCollectorConfigEntry.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();
            }
        }
예제 #6
0
        public void FromXml(string configurationString)
        {
            XmlDocument config = new XmlDocument();

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

            Entries.Clear();
            //Version 4 config
            foreach (XmlElement queryNode in root.SelectNodes("queries/query"))
            {
                RegistryQueryCollectorConfigEntry queryEntry = new RegistryQueryCollectorConfigEntry();
                queryEntry.Name                   = queryNode.ReadXmlElementAttr("name", "");
                queryEntry.UseRemoteServer        = bool.Parse(queryNode.ReadXmlElementAttr("useRemoteServer", "False"));
                queryEntry.Server                 = queryNode.ReadXmlElementAttr("server", "");
                queryEntry.RegistryHive           = RegistryQueryCollectorConfigEntry.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.GoodValue              = queryNode.ReadXmlElementAttr("successValue", "");
                queryEntry.GoodResultMatchType    = CollectorAgentReturnValueCompareMatchType.Match;
                queryEntry.WarningValue           = queryNode.ReadXmlElementAttr("warningValue", "");
                queryEntry.WarningResultMatchType = CollectorAgentReturnValueCompareMatchType.Match;
                queryEntry.ErrorValue             = queryNode.ReadXmlElementAttr("errorValue", "");
                queryEntry.ErrorResultMatchType   = CollectorAgentReturnValueCompareMatchType.Match;

                //queryEntry.ReturnValueInARange = bool.Parse(queryNode.ReadXmlElementAttr("returnValueInARange", "False"));
                //queryEntry.ReturnValueInverted = bool.Parse(queryNode.ReadXmlElementAttr("returnValueInverted", "False"));
                queryEntry.PrimaryUIValue = queryNode.ReadXmlElementAttr("primaryUIValue", false);
                Entries.Add(queryEntry);
            }
            //version 5 config
            foreach (XmlElement carvceEntryNode in root.SelectNodes("carvcesEntries/carvceEntry"))
            {
                XmlNode dataSourceNode = carvceEntryNode.SelectSingleNode("dataSource");
                RegistryQueryCollectorConfigEntry queryEntry = new RegistryQueryCollectorConfigEntry();
                queryEntry.Name                   = dataSourceNode.ReadXmlElementAttr("name", "");
                queryEntry.UseRemoteServer        = bool.Parse(dataSourceNode.ReadXmlElementAttr("useRemoteServer", "False"));
                queryEntry.Server                 = dataSourceNode.ReadXmlElementAttr("server", "");
                queryEntry.RegistryHive           = RegistryQueryCollectorConfigEntry.GetRegistryHiveFromString(dataSourceNode.ReadXmlElementAttr("registryHive", ""));
                queryEntry.Path                   = dataSourceNode.ReadXmlElementAttr("path", "");
                queryEntry.KeyName                = dataSourceNode.ReadXmlElementAttr("keyName", "");
                queryEntry.ExpandEnvironmentNames = bool.Parse(dataSourceNode.ReadXmlElementAttr("expandEnvironmentNames", "False"));
                //queryEntry.ReturnValueIsNumber = bool.Parse(dataSourceNode.ReadXmlElementAttr("returnValueIsNumber", "False"));
                queryEntry.PrimaryUIValue  = dataSourceNode.ReadXmlElementAttr("primaryUIValue", false);
                queryEntry.OutputValueUnit = dataSourceNode.ReadXmlElementAttr("outputValueUnit", "");

                XmlNode testConditionsNode = carvceEntryNode.SelectSingleNode("testConditions");
                if (testConditionsNode != null)
                {
                    queryEntry.ReturnCheckSequence = CollectorAgentReturnValueCompareEngine.CheckSequenceTypeFromString(testConditionsNode.ReadXmlElementAttr("testSequence", "gwe"));
                    XmlNode goodScriptNode = testConditionsNode.SelectSingleNode("success");
                    queryEntry.GoodResultMatchType = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(goodScriptNode.ReadXmlElementAttr("testType", "match"));
                    queryEntry.GoodValue           = goodScriptNode.InnerText;

                    XmlNode warningScriptNode = testConditionsNode.SelectSingleNode("warning");
                    queryEntry.WarningResultMatchType = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(warningScriptNode.ReadXmlElementAttr("testType", "match"));
                    queryEntry.WarningValue           = warningScriptNode.InnerText;

                    XmlNode errorScriptNode = testConditionsNode.SelectSingleNode("error");
                    queryEntry.ErrorResultMatchType = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(errorScriptNode.ReadXmlElementAttr("testType", "match"));
                    queryEntry.ErrorValue           = errorScriptNode.InnerText;
                }
                else
                {
                    queryEntry.ReturnCheckSequence = CollectorAgentReturnValueCheckSequence.GWE;
                }

                Entries.Add(queryEntry);
            }
        }