Пример #1
0
        public void ReadConfiguration(XmlDocument config)
        {
            XmlElement root = config.DocumentElement;

            Queries.Clear();
            foreach (XmlElement queryNode in root.SelectNodes("queries/query"))
            {
                QueryInstance queryEntry = new QueryInstance();
                queryEntry.Name                    = queryNode.ReadXmlElementAttr("name", "");
                queryEntry.SqlServer               = queryNode.ReadXmlElementAttr("sqlServer", "");
                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 summaryQueryNode = queryNode.SelectSingleNode("summaryQuery");
                queryEntry.UseSPForSummary       = bool.Parse(summaryQueryNode.ReadXmlElementAttr("useSP", "False"));
                queryEntry.ReturnValueIsNumber   = bool.Parse(summaryQueryNode.ReadXmlElementAttr("returnValueIsNumber", "True"));
                queryEntry.ReturnValueInverted   = bool.Parse(summaryQueryNode.ReadXmlElementAttr("returnValueInverted", "False"));
                queryEntry.WarningValue          = summaryQueryNode.ReadXmlElementAttr("warningValue", "1");
                queryEntry.ErrorValue            = summaryQueryNode.ReadXmlElementAttr("errorValue", "2");
                queryEntry.SuccessValue          = summaryQueryNode.ReadXmlElementAttr("successValue", "[any]");
                queryEntry.UseRowCountAsValue    = bool.Parse(summaryQueryNode.ReadXmlElementAttr("useRowCountAsValue", "False"));
                queryEntry.UseExecuteTimeAsValue = bool.Parse(summaryQueryNode.ReadXmlElementAttr("useExecuteTimeAsValue", "False"));
                queryEntry.SummaryQuery          = summaryQueryNode.InnerText;

                XmlNode detailQueryNode = queryNode.SelectSingleNode("detailQuery");
                queryEntry.UseSPForDetail = bool.Parse(detailQueryNode.ReadXmlElementAttr("useSP", "False"));
                queryEntry.DetailQuery    = detailQueryNode.InnerText;
                Queries.Add(queryEntry);
            }
        }
Пример #2
0
 private void addWithSameConnectionDetailsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (lvwQueries.SelectedItems.Count > 0 && lvwQueries.SelectedItems[0].Tag is QueryInstance)
     {
         EditSqlQueryInstance editSqlQueryInstance = new EditSqlQueryInstance();
         QueryInstance        masterToCopy         = (QueryInstance)lvwQueries.SelectedItems[0].Tag;
         QueryInstance        sqlQueryInstanceCopy = new QueryInstance()
         {
             SqlServer          = masterToCopy.SqlServer,
             Database           = masterToCopy.Database,
             IntegratedSecurity = masterToCopy.IntegratedSecurity,
             UserName           = masterToCopy.UserName,
             Password           = masterToCopy.Password,
             CmndTimeOut        = masterToCopy.CmndTimeOut
         };
         editSqlQueryInstance.SelectedQueryInstance = sqlQueryInstanceCopy;
         if (editSqlQueryInstance.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             ListViewItem lvi = new ListViewItem(editSqlQueryInstance.SelectedQueryInstance.Name);
             lvi.SubItems.Add(editSqlQueryInstance.SelectedQueryInstance.SqlServer + "\\" + editSqlQueryInstance.SelectedQueryInstance.Database);
             lvi.SubItems.Add(editSqlQueryInstance.SelectedQueryInstance.WarningValue);
             lvi.SubItems.Add(editSqlQueryInstance.SelectedQueryInstance.ErrorValue);
             lvi.Tag = editSqlQueryInstance.SelectedQueryInstance;
             lvwQueries.Items.Add(lvi);
             CheckOKEnabled();
             CheckButtonsEnable();
         }
     }
 }
Пример #3
0
        private string GetQIValue(ListViewItem lvi, QueryInstance queryInstance)
        {
            string results = "";

            try
            {
                object        value        = queryInstance.RunQuery();
                MonitorStates currentstate = queryInstance.GetState(value);

                results = FormatUtils.N(value, "[null]");
                if (currentstate == MonitorStates.Error)
                {
                    lvi.ImageIndex = 3;
                }
                else if (currentstate == MonitorStates.Warning)
                {
                    lvi.ImageIndex = 2;
                }
                else
                {
                    lvi.ImageIndex = 1;
                }
            }
            catch (Exception ex)
            {
                results = ex.Message;
            }
            return(results);
        }
Пример #4
0
        private void LoadDetailView()
        {
            lvwDetails.BeginUpdate();
            lvwDetails.Items.Clear();
            lvwDetails.Columns.Clear();
            if (lvwResults.SelectedItems.Count >= 1 && lvwResults.SelectedItems[0].Tag is QueryInstance)
            {
                QueryInstance queryInstance = (QueryInstance)lvwResults.SelectedItems[0].Tag;
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    DataSet ds = queryInstance.RunDetailQuery();
                    foreach (DataColumn currentDataColumn in ds.Tables[0].Columns)
                    {
                        ColumnHeader newColumn = new ColumnHeader();
                        newColumn.Tag  = currentDataColumn;
                        newColumn.Text = currentDataColumn.Caption;

                        if ((currentDataColumn.DataType == typeof(UInt64)) || (currentDataColumn.DataType == typeof(UInt32)) || (currentDataColumn.DataType == typeof(UInt16)) ||
                            (currentDataColumn.DataType == typeof(Int64)) || (currentDataColumn.DataType == typeof(Int32)) || (currentDataColumn.DataType == typeof(Int16)))
                        {
                            newColumn.TextAlign = HorizontalAlignment.Right;
                        }
                        else
                        {
                            newColumn.TextAlign = HorizontalAlignment.Left;
                        }
                        lvwDetails.Columns.Add(newColumn);
                    }
                    foreach (DataRow r in ds.Tables[0].Rows)
                    {
                        ListViewItem lvi = new ListViewItem(FormatUtils.N(r[0], "[Null]"));
                        for (int i = 1; i < lvwDetails.Columns.Count; i++)
                        {
                            lvi.SubItems.Add(FormatUtils.N(r[i], "[Null]"));
                        }
                        lvwDetails.Items.Add(lvi);
                    }
                    lvwDetails.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "View details", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }
            lvwDetails.EndUpdate();
            exportToolStripButton.Enabled = lvwResults.SelectedItems.Count > 0;
        }
Пример #5
0
 private void cmdOK_Click(object sender, EventArgs e)
 {
     if (CheckOKEnabled())
     {
         SqlQueryConfig = new SQLQueryConfig();
         foreach (ListViewItem lvi in lvwQueries.Items)
         {
             QueryInstance queryInstance = (QueryInstance)lvi.Tag;
             SqlQueryConfig.Queries.Add(queryInstance);
         }
         DialogResult = System.Windows.Forms.DialogResult.OK;
         Close();
     }
 }
Пример #6
0
 private void showSQLQueryToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (lvwResults.SelectedItems.Count > 0)
     {
         bool autoRefreshTemp = refreshTimer.Enabled;
         refreshTimer.Enabled = false;
         QueryInstance   queryInstance   = (QueryInstance)lvwResults.SelectedItems[0].Tag;
         EditDetailQuery editDetailQuery = new EditDetailQuery();
         editDetailQuery.SelectedQueryInstance = queryInstance;
         if (editDetailQuery.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             lvwResults.SelectedItems[0].Tag = editDetailQuery.SelectedQueryInstance;
         }
         refreshTimer.Enabled = autoRefreshTemp;
     }
 }
Пример #7
0
        private void EditSqlQueryInstance_Load(object sender, EventArgs e)
        {
            if (SelectedQueryInstance == null)
            {
                SelectedQueryInstance = new QueryInstance();
            }
            txtName.Text                   = SelectedQueryInstance.Name;
            txtServer.Text                 = SelectedQueryInstance.SqlServer;
            txtDatabase.Text               = SelectedQueryInstance.Database;
            chkIntegratedSec.Checked       = SelectedQueryInstance.IntegratedSecurity;
            txtUserName.Text               = SelectedQueryInstance.UserName;
            txtPassword.Text               = SelectedQueryInstance.Password;
            numericUpDownCmndTimeOut.Value = SelectedQueryInstance.CmndTimeOut;
            chkUseSPForSummary.Checked     = SelectedQueryInstance.UseSPForSummary;

            if (!SelectedQueryInstance.ReturnValueIsNumber)
            {
                cboReturnType.SelectedIndex = 0;
            }
            else if (!SelectedQueryInstance.UseRowCountAsValue && !SelectedQueryInstance.UseExecuteTimeAsValue)
            {
                cboReturnType.SelectedIndex = 1;
            }
            else if (SelectedQueryInstance.UseRowCountAsValue)
            {
                cboReturnType.SelectedIndex = 2;
            }
            else
            {
                cboReturnType.SelectedIndex = 3;
            }

            chkReturnValueNotInverted.Checked = !SelectedQueryInstance.ReturnValueInverted;
            cboSuccessValue.Text               = SelectedQueryInstance.SuccessValue;
            cboWarningValue.Text               = SelectedQueryInstance.WarningValue;
            cboErrorValue.Text                 = SelectedQueryInstance.ErrorValue;
            chkUseSPForDetail.Checked          = SelectedQueryInstance.UseSPForDetail;
            chkUsePersistentConnection.Checked = SelectedQueryInstance.UsePersistentConnection;
            txtApplicationName.Text            = SelectedQueryInstance.ApplicationName;
        }
Пример #8
0
 private void RefreshList()
 {
     try
     {
         lvwResults.BeginUpdate();
         Cursor.Current = Cursors.WaitCursor;
         foreach (ListViewItem lvi in lvwResults.Items)
         {
             QueryInstance queryInstance = (QueryInstance)lvi.Tag;
             lvi.SubItems[1].Text = GetQIValue(lvi, queryInstance);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Refresh", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         Cursor.Current = Cursors.Default;
         lvwResults.EndUpdate();
     }
     LoadDetailView();
 }
Пример #9
0
        //private void chkIsReturnValueInt_CheckedChanged(object sender, EventArgs e)
        //{
        //    chkReturnValueNotInverted.Enabled = chkIsReturnValueInt.Checked;
        //    chkUseRowCountAsValue.Enabled = chkIsReturnValueInt.Checked;
        //}
        #endregion

        #region Button click events
        private void cmdTest_Click(object sender, EventArgs e)
        {
            if (DoValidate())
            {
                string lastStep = "Initialize values";
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    QueryInstance testQueryInstance = new QueryInstance();
                    testQueryInstance.Name               = txtName.Text;
                    testQueryInstance.SqlServer          = txtServer.Text;
                    testQueryInstance.Database           = txtDatabase.Text;
                    testQueryInstance.IntegratedSecurity = chkIntegratedSec.Checked;
                    testQueryInstance.UserName           = txtUserName.Text;
                    testQueryInstance.Password           = txtPassword.Text;
                    testQueryInstance.CmndTimeOut        = (int)numericUpDownCmndTimeOut.Value;
                    testQueryInstance.UseSPForSummary    = chkUseSPForSummary.Checked;
                    testQueryInstance.SummaryQuery       = txtStateQuery.Text;
                    if (cboReturnType.SelectedIndex == 0)
                    {
                        testQueryInstance.ReturnValueIsNumber   = false;
                        testQueryInstance.UseRowCountAsValue    = false;
                        testQueryInstance.UseExecuteTimeAsValue = false;
                    }
                    else
                    {
                        testQueryInstance.ReturnValueIsNumber = true;
                        if (cboReturnType.SelectedIndex == 2)
                        {
                            testQueryInstance.UseRowCountAsValue = true;
                        }
                        else if (cboReturnType.SelectedIndex == 3)
                        {
                            testQueryInstance.UseExecuteTimeAsValue = true;
                            chkReturnValueNotInverted.Checked       = true;
                        }
                    }
                    testQueryInstance.ReturnValueInverted = !chkReturnValueNotInverted.Checked;
                    testQueryInstance.SuccessValue        = cboSuccessValue.Text;
                    testQueryInstance.WarningValue        = cboWarningValue.Text;
                    testQueryInstance.ErrorValue          = cboErrorValue.Text;
                    testQueryInstance.UseSPForDetail      = chkUseSPForDetail.Checked;
                    testQueryInstance.DetailQuery         = txtDetailQuery.Text;
                    testQueryInstance.ApplicationName     = txtApplicationName.Text;

                    lastStep = "Run summary query";
                    object returnValue = testQueryInstance.RunQuery();
                    if (!testQueryInstance.UseRowCountAsValue && !testQueryInstance.UseExecuteTimeAsValue && !returnValue.IsNumber())
                    {
                        throw new Exception(string.Format("Return value is not an integer!\r\nValue returned: {0}", returnValue));
                    }

                    //if (!testQueryInstance.ReturnValueIsNumber)
                    //{
                    //    lastStep = "Run summary query";
                    //    returnValue = testQueryInstance.RunQueryWithSingleResult();
                    //}
                    //else if (!testQueryInstance.UseRowCountAsValue && !testQueryInstance.UseExecuteTimeAsValue)
                    //{
                    //    lastStep = "Run summary query (value is number)";
                    //    returnValue = testQueryInstance.RunQueryWithSingleResult();
                    //    if (!returnValue.IsNumber())
                    //        throw new Exception(string.Format("Return value is not an integer!\r\nValue returned: {0}", returnValue));
                    //}
                    //else if (testQueryInstance.UseRowCountAsValue)
                    //{
                    //    lastStep = "Run summary query (row count as value)";
                    //    returnValue = testQueryInstance.RunQueryWithCountResult();
                    //}
                    //else
                    //{
                    //    lastStep = "Run summary query (execution time as value)";
                    //    returnValue = testQueryInstance.RunQueryWithExecutionTimeResult();
                    //}

                    //testing detail query
                    List <DataColumn> columns = new List <DataColumn>(); // = testQueryInstance.GetDetailQueryColumns();
                    lastStep = "Testing detail query";
                    DataSet ds = testQueryInstance.RunDetailQuery();
                    lastStep = "Testing detail query - Getting column names";
                    columns.AddRange((from DataColumn c in ds.Tables[0].Columns
                                      select c).ToArray());

                    MessageBox.Show(string.Format("Success!\r\nSummary value return: {0}\r\nDetail row count: {1}\r\nDetail columns returned: {2}", returnValue, ds.Tables[0].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;
                }
            }
        }