public override void LoadDisplayData()
 {
     if (Collector != null && Collector.AgentConfig != null)
     {
         SqlTableSizeCollectorConfig sqlTableSizeCollectorConfig = (SqlTableSizeCollectorConfig)Collector.AgentConfig;
         lvwEntries.Items.Clear();
         lvwEntries.Groups.Clear();
         foreach (SqlTableSizeCollectorEntry tableSizeEntry in sqlTableSizeCollectorConfig.Entries)
         {
             ListViewGroup group = new ListViewGroup(tableSizeEntry.ToString(), tableSizeEntry.ToString());
             group.Tag = tableSizeEntry;
             lvwEntries.Groups.Add(group);
             foreach (var tableEntry in tableSizeEntry.Tables)
             {
                 ListViewItem lvi = new ListViewItem(tableEntry.TableName);
                 lvi.Group      = group;
                 lvi.ImageIndex = 0;
                 lvi.SubItems.Add("-");
                 lvi.Tag = tableEntry;
                 lvwEntries.Items.Add(lvi);
             }
         }
     }
     base.LoadDisplayData();
 }
        //public override MonitorState RefreshState()
        //{
        //    MonitorState returnState = new MonitorState();
        //    string lastAction = "";
        //    int errors = 0;
        //    int warnings = 0;
        //    int success = 0;
        //    double totalValue = 0;

        //    try
        //    {
        //        SqlTableSizeCollectorConfig currentConfig = (SqlTableSizeCollectorConfig)AgentConfig;

        //        returnState.RawDetails = string.Format("Querying {0} database(s)", currentConfig.Entries.Count);
        //        returnState.HtmlDetails = string.Format("<b>Querying {0} database(s)</b>", currentConfig.Entries.Count);
        //        returnState.CurrentValue = 0;
        //        foreach (SqlTableSizeCollectorEntry entry in currentConfig.Entries)
        //        {
        //            entry.RefreshRowCounts();
        //            List<Tuple<TableSizeEntry, CollectorState>> states = entry.GetStates();

        //            MonitorState entryState = new MonitorState() { ForAgent = entry.Description };

        //            foreach (var tableEntryState in states)
        //            {
        //                if (tableEntryState.Item1.RowCount > 0)
        //                    totalValue += tableEntryState.Item1.RowCount;
        //                if (tableEntryState.Item2 == CollectorState.Error)
        //                {
        //                    errors++;
        //                    entryState.ChildStates.Add(
        //                            new MonitorState()
        //                            {
        //                                State = CollectorState.Error,
        //                                ForAgent = tableEntryState.Item1.TableName,
        //                                CurrentValue = string.Format("{0} row(s)", tableEntryState.Item1.RowCount),
        //                                RawDetails = tableEntryState.Item1.RowCount > 0 ? "(Trigger '" + tableEntryState.Item1.ErrorValue.ToString() + "')" : tableEntryState.Item1.ErrorStr
        //                                //RawDetails = string.Format("'{0}' - {1} (Error, {2})", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount, (tableEntryState.Item1.RowCount > 0 ? "Trigger " + tableEntryState.Item1.ErrorValue.ToString() : tableEntryState.Item1.ErrorStr)),
        //                                //HtmlDetails = string.Format("'{0}' - {1} (<b>Error, {2}</b>)", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount, (tableEntryState.Item1.RowCount > 0 ? "Trigger " + tableEntryState.Item1.ErrorValue.ToString() : tableEntryState.Item1.ErrorStr))
        //                            });
        //                }
        //                else if (tableEntryState.Item2 == CollectorState.Warning)
        //                {
        //                    warnings++;
        //                    entryState.ChildStates.Add(
        //                        new MonitorState()
        //                        {
        //                            State = CollectorState.Warning,
        //                            ForAgent = tableEntryState.Item1.TableName,
        //                            CurrentValue = string.Format("{0} row(s)", tableEntryState.Item1.RowCount),
        //                            RawDetails = string.Format("(Trigger '{0}')", tableEntryState.Item1.WarningValue)
        //                            //RawDetails = string.Format("'{0}' - {1} (Warning, Trigger {2})", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount, tableEntryState.Item1.WarningValue),
        //                            //HtmlDetails = string.Format("'{0}' - {1} (<b>Warning, Trigger {2}</b>)", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount, tableEntryState.Item1.WarningValue)
        //                        });
        //                }
        //                else
        //                {
        //                    success++;
        //                    entryState.ChildStates.Add(
        //                        new MonitorState()
        //                        {
        //                            State = CollectorState.Good,
        //                            ForAgent = tableEntryState.Item1.TableName,
        //                            CurrentValue = string.Format("{0} row(s)", tableEntryState.Item1.RowCount) //,
        //                            //RawDetails = string.Format("'{0}' - {1}", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount),
        //                            //HtmlDetails = string.Format("'{0}' - {1}", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount)
        //                        });
        //                }
        //            }
        //            entryState.CurrentValue = totalValue;
        //            returnState.ChildStates.Add(entryState);
        //        }

        //        if (errors > 0 && warnings == 0 && success == 0) // any errors
        //            returnState.State = CollectorState.Error;
        //        else if (errors > 0 || warnings > 0) //any warnings
        //            returnState.State = CollectorState.Warning;
        //        else
        //            returnState.State = CollectorState.Good;
        //    }
        //    catch (Exception ex)
        //    {
        //        returnState.RawDetails = ex.Message;
        //        returnState.HtmlDetails = string.Format("<p><b>Last action:</b> {0}</p><blockquote>{1}</blockquote>", lastAction, ex.Message);
        //        returnState.State = CollectorState.Error;
        //    }
        //    return returnState;
        //}

        public override List <System.Data.DataTable> GetDetailDataTables()
        {
            List <System.Data.DataTable> tables        = new List <System.Data.DataTable>();
            SqlTableSizeCollectorConfig  currentConfig = (SqlTableSizeCollectorConfig)AgentConfig;

            foreach (SqlTableSizeCollectorEntry entry in currentConfig.Entries)
            {
                entry.RefreshRowCounts();
                tables.Add(entry.GetDetailDataTable());
            }

            return(tables);
        }
 public override void LoadList()
 {
     if (SelectedConfig != null)
     {
         SqlTableSizeCollectorConfig sqlDbSizeConfig = (SqlTableSizeCollectorConfig)SelectedConfig;
         lvwEntries.Items.Clear();
         foreach (SqlTableSizeCollectorEntry sqlTableSizeEntry in sqlDbSizeConfig.Entries)
         {
             ListViewItem lvi = new ListViewItem(sqlTableSizeEntry.ToString());
             lvi.SubItems.Add(sqlTableSizeEntry.Tables.Count().ToString());
             lvi.Tag = sqlTableSizeEntry;
             lvwEntries.Items.Add(lvi);
         }
     }
     base.LoadList();
 }
        public override void OKClicked()
        {
            if (SelectedConfig == null)
            {
                SelectedConfig = new SqlTableSizeCollectorConfig();
            }
            SqlTableSizeCollectorConfig sqlDbSizeConfig = (SqlTableSizeCollectorConfig)SelectedConfig;

            sqlDbSizeConfig.Entries.Clear();
            foreach (ListViewItem lvi in lvwEntries.Items)
            {
                SqlTableSizeCollectorEntry sqlTableSizeEntry = (SqlTableSizeCollectorEntry)lvi.Tag;
                sqlDbSizeConfig.Entries.Add(sqlTableSizeEntry);
            }
            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
 public SqlTableSizeCollector()
 {
     AgentConfig = new SqlTableSizeCollectorConfig();
 }
Beispiel #6
0
        public override MonitorState RefreshState()
        {
            MonitorState returnState = new MonitorState();
            string       lastAction  = "";
            int          errors      = 0;
            int          warnings    = 0;
            int          success     = 0;
            double       totalValue  = 0;

            try
            {
                SqlTableSizeCollectorConfig currentConfig = (SqlTableSizeCollectorConfig)AgentConfig;

                returnState.RawDetails   = string.Format("Querying {0} database(s)", currentConfig.Entries.Count);
                returnState.HtmlDetails  = string.Format("<b>Querying {0} database(s)</b>", currentConfig.Entries.Count);
                returnState.CurrentValue = 0;
                foreach (SqlTableSizeCollectorEntry entry in currentConfig.Entries)
                {
                    entry.RefreshRowCounts();
                    List <Tuple <TableSizeEntry, CollectorState> > states = entry.GetStates();

                    MonitorState entryState = new MonitorState()
                    {
                        ForAgent = entry.Description
                    };

                    foreach (var tableEntryState in states)
                    {
                        if (tableEntryState.Item1.RowCount > 0)
                        {
                            totalValue += tableEntryState.Item1.RowCount;
                        }
                        if (tableEntryState.Item2 == CollectorState.Error)
                        {
                            errors++;
                            entryState.ChildStates.Add(
                                new MonitorState()
                            {
                                State        = CollectorState.Error,
                                ForAgent     = tableEntryState.Item1.TableName,
                                CurrentValue = string.Format("{0} row(s)", tableEntryState.Item1.RowCount),
                                RawDetails   = tableEntryState.Item1.RowCount > 0 ? "(Trigger '" + tableEntryState.Item1.ErrorValue.ToString() + "')" : tableEntryState.Item1.ErrorStr
                                               //RawDetails = string.Format("'{0}' - {1} (Error, {2})", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount, (tableEntryState.Item1.RowCount > 0 ? "Trigger " + tableEntryState.Item1.ErrorValue.ToString() : tableEntryState.Item1.ErrorStr)),
                                               //HtmlDetails = string.Format("'{0}' - {1} (<b>Error, {2}</b>)", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount, (tableEntryState.Item1.RowCount > 0 ? "Trigger " + tableEntryState.Item1.ErrorValue.ToString() : tableEntryState.Item1.ErrorStr))
                            });
                        }
                        else if (tableEntryState.Item2 == CollectorState.Warning)
                        {
                            warnings++;
                            entryState.ChildStates.Add(
                                new MonitorState()
                            {
                                State        = CollectorState.Warning,
                                ForAgent     = tableEntryState.Item1.TableName,
                                CurrentValue = string.Format("{0} row(s)", tableEntryState.Item1.RowCount),
                                RawDetails   = string.Format("(Trigger '{0}')", tableEntryState.Item1.WarningValue)
                                               //RawDetails = string.Format("'{0}' - {1} (Warning, Trigger {2})", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount, tableEntryState.Item1.WarningValue),
                                               //HtmlDetails = string.Format("'{0}' - {1} (<b>Warning, Trigger {2}</b>)", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount, tableEntryState.Item1.WarningValue)
                            });
                        }
                        else
                        {
                            success++;
                            entryState.ChildStates.Add(
                                new MonitorState()
                            {
                                State        = CollectorState.Good,
                                ForAgent     = tableEntryState.Item1.TableName,
                                CurrentValue = string.Format("{0} row(s)", tableEntryState.Item1.RowCount) //,
                                                                                                           //RawDetails = string.Format("'{0}' - {1}", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount),
                                                                                                           //HtmlDetails = string.Format("'{0}' - {1}", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount)
                            });
                        }
                    }
                    entryState.CurrentValue = totalValue;
                    returnState.ChildStates.Add(entryState);
                }

                if (errors > 0 && warnings == 0 && success == 0) // any errors
                {
                    returnState.State = CollectorState.Error;
                }
                else if (errors > 0 || warnings > 0) //any warnings
                {
                    returnState.State = CollectorState.Warning;
                }
                else
                {
                    returnState.State = CollectorState.Good;
                }
            }
            catch (Exception ex)
            {
                returnState.RawDetails  = ex.Message;
                returnState.HtmlDetails = string.Format("<p><b>Last action:</b> {0}</p><blockquote>{1}</blockquote>", lastAction, ex.Message);
                returnState.State       = CollectorState.Error;
            }
            return(returnState);
        }
        public override MonitorState GetState()
        {
            MonitorState returnState = new MonitorState()
            {
                State = CollectorState.Good
            };
            StringBuilder plainTextDetails    = new StringBuilder();
            StringBuilder htmlTextTextDetails = new StringBuilder();
            string        lastAction          = "";
            int           errors     = 0;
            int           warnings   = 0;
            int           success    = 0;
            double        totalValue = 0;

            try
            {
                SqlTableSizeCollectorConfig sqlTableSizeConfig = (SqlTableSizeCollectorConfig)AgentConfig;
                plainTextDetails.AppendLine(string.Format("Database table size(s)"));
                htmlTextTextDetails.AppendLine(string.Format("Database table size(s)"));

                foreach (SqlTableSizeCollectorEntry sqlTableSizeEntry in sqlTableSizeConfig.Entries)
                {
                    lastAction = string.Format("Getting table sizes for '{0}\\{1}'", sqlTableSizeEntry.SqlServer, sqlTableSizeEntry.Database);

                    sqlTableSizeEntry.RefreshRowCounts();
                    List <Tuple <TableSizeEntry, CollectorState> > states = sqlTableSizeEntry.GetStates();
                    plainTextDetails.AppendLine(string.Format("\tDatabase {0}", sqlTableSizeEntry));
                    htmlTextTextDetails.AppendLine(string.Format("<b>Database {0}</b>", sqlTableSizeEntry));
                    htmlTextTextDetails.AppendLine("<ul>");
                    foreach (var tableEntryState in states)
                    {
                        if (tableEntryState.Item1.RowCount > 0)
                        {
                            totalValue += tableEntryState.Item1.RowCount;
                        }
                        if (tableEntryState.Item2 == CollectorState.Error)
                        {
                            errors++;
                            if (tableEntryState.Item1.RowCount > 0)
                            {
                                plainTextDetails.AppendLine(string.Format("\t\t{0} - value '{1}' - Error (trigger {2})", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount, tableEntryState.Item1.ErrorValue));
                                htmlTextTextDetails.AppendLine(string.Format("<li>{0} - Value '{1}' - <b>Error</b> (trigger {2})</li>", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount, tableEntryState.Item1.ErrorValue));
                            }
                            else
                            {
                                plainTextDetails.AppendLine(string.Format("\t\t{0} - value '{1}' - Error ({2})", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount, tableEntryState.Item1.ErrorStr));
                                htmlTextTextDetails.AppendLine(string.Format("<li>{0} - Value '{1}' - <b>Error</b> ({2})</li>", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount, tableEntryState.Item1.ErrorStr));
                            }
                        }
                        else if (tableEntryState.Item2 == CollectorState.Warning)
                        {
                            warnings++;
                            plainTextDetails.AppendLine(string.Format("\t\t{0} - value '{1}' - Warning (trigger {2})", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount, tableEntryState.Item1.WarningValue));
                            htmlTextTextDetails.AppendLine(string.Format("<li>{0} - Value '{1}' - <b>Warning</b> (trigger {2})</li>", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount, tableEntryState.Item1.WarningValue));
                        }
                        else
                        {
                            plainTextDetails.AppendLine(string.Format("\t\t{0} - value '{1}'", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount));
                            htmlTextTextDetails.AppendLine(string.Format("<li>{0} - Value '{1}'</li>", tableEntryState.Item1.TableName, tableEntryState.Item1.RowCount));
                            success++;
                        }
                    }
                    htmlTextTextDetails.AppendLine("</ul>");
                }

                if (errors > 0 && warnings == 0)
                {
                    returnState.State = CollectorState.Error;
                }
                else if (warnings > 0)
                {
                    returnState.State = CollectorState.Warning;
                }
                returnState.RawDetails   = plainTextDetails.ToString().TrimEnd('\r', '\n');
                returnState.HtmlDetails  = htmlTextTextDetails.ToString();
                returnState.CurrentValue = totalValue;
            }
            catch (Exception ex)
            {
                returnState.RawDetails  = string.Format("Last step: '{0}\r\n{1}", lastAction, ex.Message);
                returnState.HtmlDetails = string.Format("<blockquote>Last step: '{0}<br />{1}</blockquote>", lastAction, ex.Message);
                returnState.State       = CollectorState.Error;
            }
            return(returnState);
        }