Example #1
0
        private string GetQIValue(ListViewItem lvi, DirectoryServicesQueryCollectorConfigEntry dsQueryEntry)
        {
            string results = "";

            try
            {
                object         value        = dsQueryEntry.RunQuery();
                CollectorState currentstate = dsQueryEntry.GetState(value);

                results = FormatUtils.N(value, "[null]");
                if (currentstate == CollectorState.Error)
                {
                    lvi.ImageIndex = 3;
                }
                else if (currentstate == CollectorState.Warning)
                {
                    lvi.ImageIndex = 2;
                }
                else
                {
                    lvi.ImageIndex = 1;
                }
            }
            catch (Exception ex)
            {
                results = ex.Message;
            }
            return(results);
        }
Example #2
0
        private void cmdRunQuery_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                DirectoryServicesQueryCollectorConfigEntry testEntry = new DirectoryServicesQueryCollectorConfigEntry();
                testEntry.Name                   = txtName.Text;
                testEntry.DomainController       = txtDomainController.Text;
                testEntry.PropertiesToLoad       = txtPropertiestToLoad.Text;
                testEntry.ReturnCheckSequence    = optGWE.Checked ? CollectorAgentReturnValueCheckSequence.GWE : CollectorAgentReturnValueCheckSequence.EWG;
                testEntry.UseRowCountAsValue     = chkUseRowCount.Checked;
                testEntry.MaxRowsToEvaluate      = (int)maxRowsNumericUpDown.Value;
                testEntry.QueryFilterText        = txtQueryText.Text;
                testEntry.GoodScriptText         = txtSuccess.Text;
                testEntry.GoodResultMatchType    = (CollectorAgentReturnValueCompareMatchType)cboSuccessMatchType.SelectedIndex;
                testEntry.WarningScriptText      = txtWarning.Text;
                testEntry.WarningResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboWarningMatchType.SelectedIndex;
                testEntry.ErrorScriptText        = txtError.Text;
                testEntry.ErrorResultMatchType   = (CollectorAgentReturnValueCompareMatchType)cboErrorMatchType.SelectedIndex;

                object         results          = testEntry.RunQuery();
                CollectorState currentstate     = testEntry.GetState(results);
                string         formattedResults = results.ToString();
                if (formattedResults.Length > 255)
                {
                    formattedResults = formattedResults.Substring(0, 255);
                }
                MessageBox.Show(string.Format("Result: {0}\r\nValue(s): {1}", currentstate, formattedResults), "Test query", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                Cursor.Current = Cursors.Default;
                MessageBox.Show(ex.Message, "Run script", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }