Exemple #1
0
        private void cmdTest_Click(object sender, EventArgs e)
        {
            DatabaseSizeInfo databaseSizeInfo = new DatabaseSizeInfo();
            string           lastStep         = "Opening connection";
            string           details          = "";

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                databaseSizeInfo.OpenConnection(txtServer.Text, chkIntegratedSec.Checked, txtUserName.Text, txtPassword.Text, (int)numericUpDownCmndTimeOut.Value);
                foreach (ListViewItem lvi in lvwDatabases.Items)
                {
                    DatabaseEntry dbe = (DatabaseEntry)lvi.Tag;
                    lastStep = string.Format("Getting database size for: {0}", dbe.Name);
                    long size = databaseSizeInfo.GetDatabaseSize(dbe.Name);
                    details += string.Format("{0} - {1}MB\r\n", dbe.Name, size);
                }

                databaseSizeInfo.CloseConnection();
                MessageBox.Show("Test completed successfully!\r\n" + details, "Testing", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Test failed!\r\nLast step: {0}\r\n{1}", lastStep, ex.Message), "Testing", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Exemple #2
0
        private void lblDatabase_DoubleClick(object sender, EventArgs e)
        {
            DatabaseSizeInfo databaseSizeInfo = new DatabaseSizeInfo();
            string           lastStep         = "Opening connection";
            string           details          = "";

            try
            {
                if (cboDatabase.Text.Length == 0)
                {
                    return;
                }
                Cursor.Current = Cursors.WaitCursor;
                databaseSizeInfo.OpenConnection(txtServer.Text, chkIntegratedSec.Checked, txtUserName.Text, txtPassword.Text, (int)numericUpDownCmndTimeOut.Value);

                lastStep = string.Format("Getting database size for: {0}", cboDatabase.Text);
                long size = databaseSizeInfo.GetDatabaseSize(cboDatabase.Text);
                details += string.Format("{0} - {1}MB\r\n", cboDatabase.Text, size);

                databaseSizeInfo.CloseConnection();
                MessageBox.Show("Getting specified database size!\r\n" + details, "Size", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Getting specified database size failed!\r\nLast step: {0}\r\n{1}", lastStep, ex.Message), "Size", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Exemple #3
0
        private void RefreshList()
        {
            try
            {
                lvwDatabases.BeginUpdate();
                Cursor.Current = Cursors.WaitCursor;

                DatabaseSizeInfo databaseSizeInfo = new DatabaseSizeInfo();
                databaseSizeInfo.OpenConnection(DatabaseSizeConfig.SqlServer, DatabaseSizeConfig.IntegratedSec, DatabaseSizeConfig.UserName, DatabaseSizeConfig.Password, DatabaseSizeConfig.CmndTimeOut);
                foreach (ListViewItem lvi in lvwDatabases.Items)
                {
                    DatabaseEntry dbe = (DatabaseEntry)lvi.Tag;
                    try
                    {
                        long size = databaseSizeInfo.GetDatabaseSize(dbe.Name);
                        lvi.SubItems[1].Text = size.ToString();
                        if (size >= dbe.ErrorSizeMB)
                        {
                            lvi.ImageIndex = 2;
                            lvi.BackColor  = Color.Salmon;
                        }
                        else if (size >= dbe.WarningSizeMB)
                        {
                            lvi.ImageIndex = 1;
                            lvi.BackColor  = Color.SandyBrown;
                        }
                        else
                        {
                            lvi.ImageIndex = 0;
                            lvi.BackColor  = SystemColors.Window;
                        }
                    }
                    catch (Exception innerEx)
                    {
                        lvi.SubItems[1].Text = innerEx.Message;
                        lvi.ImageIndex       = 2;
                        lvi.BackColor        = Color.Salmon;
                    }
                }
                databaseSizeInfo.CloseConnection();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                lvwDatabases.EndUpdate();
                Cursor.Current             = Cursors.Default;
                toolStripStatusLabel1.Text = "Last updated " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            }
        }
Exemple #4
0
        //internal List<DatabaseEntry> Databases = new List<DatabaseEntry>();

        public override MonitorStates GetState()
        {
            MonitorStates returnState         = MonitorStates.Good;
            StringBuilder plainTextDetails    = new StringBuilder();
            StringBuilder htmlTextTextDetails = new StringBuilder();

            LastDetailMsg.PlainText = "";
            LastDetailMsg.HtmlText  = "";

            LastError    = 0;
            LastErrorMsg = "";
            int  errorCount   = 0;
            int  warningCount = 0;
            int  okCount      = 0;
            long totalSize    = 0;

            try
            {
                DatabaseSizeInfo databaseSizeInfo = new DatabaseSizeInfo();
                databaseSizeInfo.OpenConnection(DatabaseSizeConfig.SqlServer, DatabaseSizeConfig.IntegratedSec, DatabaseSizeConfig.UserName, DatabaseSizeConfig.Password, DatabaseSizeConfig.CmndTimeOut);

                htmlTextTextDetails.AppendLine("<ul>");
                foreach (DatabaseEntry dbEntry in DatabaseSizeConfig.Databases)
                {
                    long size = databaseSizeInfo.GetDatabaseSize(dbEntry.Name);
                    totalSize += size;
                    if (size >= (long)dbEntry.ErrorSizeMB)
                    {
                        errorCount++;
                        plainTextDetails.AppendLine(string.Format("Database {0} - Size {1}MB - Error (trigger {2}MB)", dbEntry.Name, size, dbEntry.ErrorSizeMB));
                        htmlTextTextDetails.AppendLine(string.Format("<li>Database {0} - Size {1}MB - <b>Error</b> (trigger {2}MB)</li>", dbEntry.Name, size, dbEntry.ErrorSizeMB));
                    }
                    else if (size >= (long)dbEntry.WarningSizeMB)
                    {
                        warningCount++;
                        plainTextDetails.AppendLine(string.Format("Database {0} - Size {1}MB - Warning (trigger {2}MB", dbEntry.Name, size, dbEntry.WarningSizeMB));
                        htmlTextTextDetails.AppendLine(string.Format("<li>Database {0} - Size {1}MB - <b>Warning</b> (trigger {2}MB)</li>", dbEntry.Name, size, dbEntry.WarningSizeMB));
                    }
                    else
                    {
                        okCount++;
                        plainTextDetails.AppendLine(string.Format("Database {0} - Size {1}MB", dbEntry.Name, size));
                        htmlTextTextDetails.AppendLine(string.Format("<li>Database {0} - Size {1}MB</li>", dbEntry.Name, size));
                    }
                }
                LastDetailMsg.LastValue = totalSize;
                htmlTextTextDetails.AppendLine("</ul>");

                databaseSizeInfo.CloseConnection();

                if (errorCount > 0)
                {
                    returnState = MonitorStates.Error;
                }
                else if (warningCount > 0)
                {
                    returnState = MonitorStates.Warning;
                }
                else
                {
                    returnState = MonitorStates.Good;
                }
                LastDetailMsg.PlainText = plainTextDetails.ToString().TrimEnd('\r', '\n');
                LastDetailMsg.HtmlText  = htmlTextTextDetails.ToString();
            }
            catch (Exception ex)
            {
                LastError               = 1;
                LastErrorMsg            = ex.Message;
                LastDetailMsg.PlainText = ex.Message;
                LastDetailMsg.HtmlText  = string.Format("<blockquote>{0}</blockquote>", ex.Message);

                returnState = MonitorStates.Error;
            }

            return(returnState);
        }