private void cmdTest_Click(object sender, EventArgs e)
        {
            string lastStep = "Initialize values";
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                SqlQueryCollectorEntry testEntry = new SqlQueryCollectorEntry();
                testEntry.Name = txtName.Text;
                testEntry.DataSourceType = optOLEDb.Checked ? DataSourceType.OLEDB : DataSourceType.SqlServer;
                testEntry.Server = txtServer.Text;
                testEntry.Database = txtDatabase.Text;
                testEntry.IntegratedSecurity = chkIntegratedSec.Checked;
                testEntry.UserName = txtUserName.Text;
                testEntry.Password = txtPassword.Text;
                testEntry.ConnectionString = txtConnectionString.Text;

                testEntry.ApplicationName = txtApplicationName.Text;
                testEntry.CmndTimeOut = (int)numericUpDownCmndTimeOut.Value;
                testEntry.UsePersistentConnection = chkUsePersistentConnection.Checked;

                testEntry.UseSPForStateQuery = chkUseSPForState.Checked;
                testEntry.StateQuery = txtStateQuery.Text;

                testEntry.UseSPForDetailQuery = chkUseSPForDetail.Checked;
                testEntry.DetailQuery = txtDetailQuery.Text;

                testEntry.ValueReturnCheckSequence = optEWG.Checked ? CollectorAgentReturnValueCheckSequence.EWG : CollectorAgentReturnValueCheckSequence.GWE;

                testEntry.ValueReturnType = (DataBaseQueryValueReturnType)cboReturnType.SelectedIndex;
                testEntry.SuccessMatchType = (CollectorAgentReturnValueCompareMatchType)cboSuccessMatchType.SelectedIndex;
                testEntry.SuccessValueOrMacro = txtGoodValueOrMacro.Text;
                testEntry.WarningMatchType = (CollectorAgentReturnValueCompareMatchType)cboWarningMatchType.SelectedIndex;
                testEntry.WarningValueOrMacro = txtWarningValueOrMacro.Text;
                testEntry.ErrorMatchType = (CollectorAgentReturnValueCompareMatchType)cboErrorMatchType.SelectedIndex;
                testEntry.ErrorValueOrMacro = txtErrorValueOrMacro.Text;

                lastStep = "Run state query";
                object returnValue = testEntry.GetStateQueryValue();
                lastStep = "Run detail query";
                DataTable dt = testEntry.GetDetailQueryDataTable();
                lastStep = "Run detail query - Getting column names";
                List<DataColumn> columns = new List<DataColumn>();
                columns.AddRange((from DataColumn c in dt.Columns
                                  select c).ToArray());

                MessageBox.Show(string.Format("Success!\r\nState value return: {0}\r\nDetail row count: {1}\r\nDetail columns returned: {2}", returnValue, dt.Rows.Count, columns.ToCSVString()), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            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;
            }
        }
Esempio n. 2
0
        public void FromXml(string configurationString)
        {
            XmlDocument config = new XmlDocument();

            config.LoadXml(configurationString);
            Entries.Clear();
            XmlElement root = config.DocumentElement;

            foreach (XmlElement queryNode in root.SelectNodes("queries/query"))
            {
                SqlQueryCollectorEntry queryEntry = new SqlQueryCollectorEntry();
                queryEntry.Name                    = queryNode.ReadXmlElementAttr("name", "");
                queryEntry.DataSourceType          = queryNode.ReadXmlElementAttr("dataSourceType", "SqlServer").ToLower() == "oledb" ? DataSourceType.OLEDB : DataSourceType.SqlServer;
                queryEntry.ConnectionString        = queryNode.ReadXmlElementAttr("connStr", "");
                queryEntry.ProviderName            = queryNode.ReadXmlElementAttr("provider", "");
                queryEntry.FileName                = queryNode.ReadXmlElementAttr("fileName", "");
                queryEntry.Server                  = queryNode.ReadXmlElementAttr("server", "");
                queryEntry.Database                = queryNode.ReadXmlElementAttr("database", "");
                queryEntry.IntegratedSecurity      = bool.Parse(queryNode.ReadXmlElementAttr("integratedSec", "True"));
                queryEntry.UserName                = queryNode.ReadXmlElementAttr("userName", "");
                queryEntry.Password                = queryNode.ReadXmlElementAttr("password", "");
                queryEntry.CmndTimeOut             = int.Parse(queryNode.ReadXmlElementAttr("cmndTimeOut", "60"));
                queryEntry.UsePersistentConnection = bool.Parse(queryNode.ReadXmlElementAttr("usePersistentConnection", "False"));
                queryEntry.ApplicationName         = queryNode.ReadXmlElementAttr("applicationName", "QuickMon");

                XmlNode alertTriggersNode = queryNode.SelectSingleNode("alertTriggers");
                queryEntry.ValueReturnType          = DataBaseQueryValueReturnTypeConverter.FromString(alertTriggersNode.ReadXmlElementAttr("valueReturnType", "RawValue"));
                queryEntry.ValueReturnCheckSequence = CollectorAgentReturnValueCompareEngine.CheckSequenceTypeFromString(alertTriggersNode.ReadXmlElementAttr("checkSequence", "EWG"));

                XmlNode successNode = alertTriggersNode.SelectSingleNode("success");
                queryEntry.SuccessMatchType    = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(successNode.ReadXmlElementAttr("matchType", "Match"));
                queryEntry.SuccessValueOrMacro = successNode.ReadXmlElementAttr("value", "[any]");

                XmlNode warningNode = alertTriggersNode.SelectSingleNode("warning");
                queryEntry.WarningMatchType    = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(warningNode.ReadXmlElementAttr("matchType", "Match"));
                queryEntry.WarningValueOrMacro = warningNode.ReadXmlElementAttr("value", "0");

                XmlNode errorNode = alertTriggersNode.SelectSingleNode("error");
                queryEntry.ErrorMatchType    = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(errorNode.ReadXmlElementAttr("matchType", "Match"));
                queryEntry.ErrorValueOrMacro = errorNode.ReadXmlElementAttr("value", "[null]");

                XmlNode stateQueryNode = queryNode.SelectSingleNode("stateQuery");
                queryEntry.UseSPForStateQuery = stateQueryNode.ReadXmlElementAttr("useSP", false);
                queryEntry.StateQuery         = stateQueryNode.InnerText;

                XmlNode detailQueryNode = queryNode.SelectSingleNode("detailQuery");
                queryEntry.UseSPForDetailQuery = detailQueryNode.ReadXmlElementAttr("useSP", false);
                queryEntry.DetailQuery         = detailQueryNode.InnerText;

                Entries.Add(queryEntry);
            }
        }
        //#region ICollectorConfigEntryEditWindow
        //public ICollectorConfigEntry SelectedEntry { get; set; }
        //public QuickMonDialogResult ShowEditEntry()
        //{
        //    return (QuickMonDialogResult)ShowDialog();
        //} 
        //#endregion

        #region Form events
        private void SqlQueryCollectorEditEntry_Load(object sender, EventArgs e)
        {            
            try
            {                
                SqlQueryCollectorEntry selectedEntry;
                if (SelectedEntry == null)
                    SelectedEntry = new SqlQueryCollectorEntry() { DataSourceType = Collectors.DataSourceType.SqlServer };
                selectedEntry = (SqlQueryCollectorEntry)SelectedEntry;                

                txtName.Text = selectedEntry.Name;
                optOLEDb.Checked = selectedEntry.DataSourceType == DataSourceType.OLEDB;
                optSqlServer.Checked = selectedEntry.DataSourceType == DataSourceType.SqlServer;
                txtServer.Text = selectedEntry.Server;
                txtDatabase.Text = selectedEntry.Database;
                chkIntegratedSec.Checked = selectedEntry.IntegratedSecurity;
                txtUserName.Text = selectedEntry.UserName;
                txtPassword.Text = selectedEntry.Password;

                txtConnectionString.Text = selectedEntry.ConnectionString;

                txtApplicationName.Text = selectedEntry.ApplicationName;
                numericUpDownCmndTimeOut.SaveValueSet(selectedEntry.CmndTimeOut);
                chkUsePersistentConnection.Checked = selectedEntry.UsePersistentConnection;

                chkUseSPForState.Checked = selectedEntry.UseSPForStateQuery;
                txtStateQuery.Text = selectedEntry.StateQuery;

                chkUseSPForDetail.Checked = selectedEntry.UseSPForDetailQuery;
                txtDetailQuery.Text = selectedEntry.DetailQuery;

                optEWG.Checked = selectedEntry.ValueReturnCheckSequence == CollectorAgentReturnValueCheckSequence.EWG;
                optGWE.Checked = selectedEntry.ValueReturnCheckSequence == CollectorAgentReturnValueCheckSequence.GWE;
                cboReturnType.SelectedIndex = (int)selectedEntry.ValueReturnType;
                cboSuccessMatchType.SelectedIndex = (int)selectedEntry.SuccessMatchType;
                txtGoodValueOrMacro.Text = selectedEntry.SuccessValueOrMacro;
                cboWarningMatchType.SelectedIndex = (int)selectedEntry.WarningMatchType;
                txtWarningValueOrMacro.Text = selectedEntry.WarningValueOrMacro;
                cboErrorMatchType.SelectedIndex = (int)selectedEntry.ErrorMatchType;
                txtErrorValueOrMacro.Text = selectedEntry.ErrorValueOrMacro;

                SetDataSourceSelection();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void cmdOK_Click(object sender, EventArgs e)
        {
            SqlQueryCollectorEntry selectedEntry;
            if (SelectedEntry == null)
                SelectedEntry = new SqlQueryCollectorEntry() { DataSourceType = Collectors.DataSourceType.SqlServer };
            selectedEntry = (SqlQueryCollectorEntry)SelectedEntry;

            selectedEntry.Name = txtName.Text;
            selectedEntry.DataSourceType = optOLEDb.Checked ? DataSourceType.OLEDB : DataSourceType.SqlServer;
            selectedEntry.Server = txtServer.Text;
            selectedEntry.Database = txtDatabase.Text;
            selectedEntry.IntegratedSecurity = chkIntegratedSec.Checked;
            selectedEntry.UserName = txtUserName.Text;
            selectedEntry.Password = txtPassword.Text;
            selectedEntry.ConnectionString = txtConnectionString.Text;

            selectedEntry.ApplicationName = txtApplicationName.Text;
            selectedEntry.CmndTimeOut = (int)numericUpDownCmndTimeOut.Value;
            selectedEntry.UsePersistentConnection = chkUsePersistentConnection.Checked;

            selectedEntry.UseSPForStateQuery = chkUseSPForState.Checked;
            selectedEntry.StateQuery = txtStateQuery.Text;

            selectedEntry.UseSPForDetailQuery = chkUseSPForDetail.Checked;
            selectedEntry.DetailQuery = txtDetailQuery.Text;

            selectedEntry.ValueReturnCheckSequence = optEWG.Checked ? CollectorAgentReturnValueCheckSequence.EWG : CollectorAgentReturnValueCheckSequence.GWE;

            selectedEntry.ValueReturnType = (DataBaseQueryValueReturnType)cboReturnType.SelectedIndex;
            selectedEntry.SuccessMatchType = (CollectorAgentReturnValueCompareMatchType)cboSuccessMatchType.SelectedIndex;
            selectedEntry.SuccessValueOrMacro = txtGoodValueOrMacro.Text;
            selectedEntry.WarningMatchType = (CollectorAgentReturnValueCompareMatchType)cboWarningMatchType.SelectedIndex;
            selectedEntry.WarningValueOrMacro = txtWarningValueOrMacro.Text;
            selectedEntry.ErrorMatchType = (CollectorAgentReturnValueCompareMatchType)cboErrorMatchType.SelectedIndex;
            selectedEntry.ErrorValueOrMacro = txtErrorValueOrMacro.Text;

            SelectedEntry = selectedEntry;

            DialogResult = DialogResult.OK;
            Close();
        }
Esempio n. 5
0
        public void FromXml(string configurationString)
        {
            XmlDocument config = new XmlDocument();

            config.LoadXml(configurationString);
            Entries.Clear();
            XmlElement root = config.DocumentElement;

            //Version 4 config
            foreach (XmlElement queryNode in root.SelectNodes("queries/query"))
            {
                SqlQueryCollectorEntry queryEntry = new SqlQueryCollectorEntry();
                queryEntry.Name                    = queryNode.ReadXmlElementAttr("name", "");
                queryEntry.DataSourceType          = queryNode.ReadXmlElementAttr("dataSourceType", "SqlServer").ToLower() == "oledb" ? DataSourceType.OLEDB : DataSourceType.SqlServer;
                queryEntry.ConnectionString        = queryNode.ReadXmlElementAttr("connStr", "");
                queryEntry.ProviderName            = queryNode.ReadXmlElementAttr("provider", "");
                queryEntry.FileName                = queryNode.ReadXmlElementAttr("fileName", "");
                queryEntry.Server                  = queryNode.ReadXmlElementAttr("server", "");
                queryEntry.Database                = queryNode.ReadXmlElementAttr("database", "");
                queryEntry.IntegratedSecurity      = bool.Parse(queryNode.ReadXmlElementAttr("integratedSec", "True"));
                queryEntry.UserName                = queryNode.ReadXmlElementAttr("userName", "");
                queryEntry.Password                = queryNode.ReadXmlElementAttr("password", "");
                queryEntry.CmndTimeOut             = int.Parse(queryNode.ReadXmlElementAttr("cmndTimeOut", "60"));
                queryEntry.UsePersistentConnection = bool.Parse(queryNode.ReadXmlElementAttr("usePersistentConnection", "False"));
                queryEntry.ApplicationName         = queryNode.ReadXmlElementAttr("applicationName", "QuickMon");
                queryEntry.PrimaryUIValue          = queryNode.ReadXmlElementAttr("primaryUIValue", false);


                XmlNode alertTriggersNode = queryNode.SelectSingleNode("alertTriggers");
                queryEntry.ValueReturnType     = DataBaseQueryValueReturnTypeConverter.FromString(alertTriggersNode.ReadXmlElementAttr("valueReturnType", "RawValue"));
                queryEntry.ReturnCheckSequence = CollectorAgentReturnValueCompareEngine.CheckSequenceTypeFromString(alertTriggersNode.ReadXmlElementAttr("checkSequence", "EWG"));

                XmlNode successNode = alertTriggersNode.SelectSingleNode("success");
                queryEntry.GoodResultMatchType = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(successNode.ReadXmlElementAttr("matchType", "Match"));
                queryEntry.GoodValue           = successNode.ReadXmlElementAttr("value", "[any]");

                XmlNode warningNode = alertTriggersNode.SelectSingleNode("warning");
                queryEntry.WarningResultMatchType = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(warningNode.ReadXmlElementAttr("matchType", "Match"));
                queryEntry.WarningValue           = warningNode.ReadXmlElementAttr("value", "0");

                XmlNode errorNode = alertTriggersNode.SelectSingleNode("error");
                queryEntry.ErrorResultMatchType = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(errorNode.ReadXmlElementAttr("matchType", "Match"));
                queryEntry.ErrorValue           = errorNode.ReadXmlElementAttr("value", "[null]");

                XmlNode stateQueryNode = queryNode.SelectSingleNode("stateQuery");
                queryEntry.UseSPForStateQuery = stateQueryNode.ReadXmlElementAttr("useSP", false);
                queryEntry.StateQuery         = stateQueryNode.InnerText;

                //XmlNode detailQueryNode = queryNode.SelectSingleNode("detailQuery");
                //queryEntry.UseSPForDetailQuery = detailQueryNode.ReadXmlElementAttr("useSP", false);
                //queryEntry.DetailQuery = detailQueryNode.InnerText;

                Entries.Add(queryEntry);
            }

            //version 5 config
            foreach (XmlElement carvceEntryNode in root.SelectNodes("carvcesEntries/carvceEntry"))
            {
                XmlNode dataSourceNode            = carvceEntryNode.SelectSingleNode("dataSource");
                SqlQueryCollectorEntry queryEntry = new SqlQueryCollectorEntry();
                queryEntry.Name                    = dataSourceNode.ReadXmlElementAttr("name", "");
                queryEntry.DataSourceType          = dataSourceNode.ReadXmlElementAttr("dataSourceType", "SqlServer").ToLower() == "oledb" ? DataSourceType.OLEDB : DataSourceType.SqlServer;
                queryEntry.ConnectionString        = dataSourceNode.ReadXmlElementAttr("connStr", "");
                queryEntry.ProviderName            = dataSourceNode.ReadXmlElementAttr("provider", "");
                queryEntry.FileName                = dataSourceNode.ReadXmlElementAttr("fileName", "");
                queryEntry.Server                  = dataSourceNode.ReadXmlElementAttr("server", "");
                queryEntry.Database                = dataSourceNode.ReadXmlElementAttr("database", "");
                queryEntry.IntegratedSecurity      = bool.Parse(dataSourceNode.ReadXmlElementAttr("integratedSec", "True"));
                queryEntry.UserName                = dataSourceNode.ReadXmlElementAttr("userName", "");
                queryEntry.Password                = dataSourceNode.ReadXmlElementAttr("password", "");
                queryEntry.CmndTimeOut             = int.Parse(dataSourceNode.ReadXmlElementAttr("cmndTimeOut", "60"));
                queryEntry.UsePersistentConnection = bool.Parse(dataSourceNode.ReadXmlElementAttr("usePersistentConnection", "False"));
                queryEntry.ApplicationName         = dataSourceNode.ReadXmlElementAttr("applicationName", "QuickMon");
                queryEntry.PrimaryUIValue          = dataSourceNode.ReadXmlElementAttr("primaryUIValue", false);
                queryEntry.OutputValueUnit         = dataSourceNode.ReadXmlElementAttr("outputValueUnit", "");

                XmlNode stateQueryNode = dataSourceNode.SelectSingleNode("stateQuery");
                queryEntry.UseSPForStateQuery = stateQueryNode.ReadXmlElementAttr("useSP", false);
                queryEntry.StateQuery         = stateQueryNode.InnerText;

                //XmlNode detailQueryNode = dataSourceNode.SelectSingleNode("detailQuery");
                //queryEntry.UseSPForDetailQuery = detailQueryNode.ReadXmlElementAttr("useSP", false);
                //queryEntry.DetailQuery = detailQueryNode.InnerText;

                XmlNode testConditionsNode = carvceEntryNode.SelectSingleNode("testConditions");
                if (testConditionsNode != null)
                {
                    queryEntry.ReturnCheckSequence = CollectorAgentReturnValueCompareEngine.CheckSequenceTypeFromString(testConditionsNode.ReadXmlElementAttr("testSequence", "gwe"));
                    queryEntry.ValueReturnType     = DataBaseQueryValueReturnTypeConverter.FromString(testConditionsNode.ReadXmlElementAttr("valueReturnType", "RawValue"));
                    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;
                    queryEntry.ValueReturnType     = DataBaseQueryValueReturnType.RawValue;
                }

                Entries.Add(queryEntry);
            }
        }