/// <summary>
        /// Returns a page of errors from the folder in descending order
        /// of logged time as defined by the sortable filenames.
        /// </summary>

        public override int GetErrors(int pageIndex, int pageSize, IList errorEntryList)
        {
            if (pageIndex < 0)
            {
                throw new ArgumentOutOfRangeException("pageIndex", pageIndex, null);
            }

            if (pageSize < 0)
            {
                throw new ArgumentOutOfRangeException("pageSize", pageSize, null);
            }

            /* Get all files in directory */
            string        logPath = LogPath;
            DirectoryInfo dir     = new DirectoryInfo(logPath);

            if (!dir.Exists)
            {
                return(0);
            }

            FileSystemInfo[] infos = dir.GetFiles("error-*.xml");

            if (infos.Length < 1)
            {
                return(0);
            }

            string[] files = new string[infos.Length];
            int      count = 0;

            /* Get files that are not marked with system and hidden attributes */
            foreach (FileSystemInfo info in infos)
            {
                if (IsUserFile(info.Attributes))
                {
                    files[count++] = Path.Combine(logPath, info.Name);
                }
            }

            InvariantStringArray.Sort(files, 0, count);
            Array.Reverse(files, 0, count);

            if (errorEntryList != null)
            {
                /* Find the proper page */
                int firstIndex = pageIndex * pageSize;
                int lastIndex  = (firstIndex + pageSize < count) ? firstIndex + pageSize : count;

                /* Open them up and rehydrate the list */
                for (int i = firstIndex; i < lastIndex; i++)
                {
                    XmlTextReader reader = new XmlTextReader(files[i]);

                    try
                    {
                        while (reader.IsStartElement("error"))
                        {
                            string id    = reader.GetAttribute("errorId");
                            Error  error = ErrorXml.Decode(reader);
                            errorEntryList.Add(new ErrorLogEntry(this, id, error));
                        }
                    }
                    finally
                    {
                        reader.Close();
                    }
                }
            }

            /* Return how many are total */
            return(count);
        }
Example #2
0
        private void RenderCollection(HtmlTextWriter writer,
                                      NameValueCollection collection, string id, string title)
        {
            Debug.Assert(writer != null);
            Debug.AssertStringNotEmpty(id);
            Debug.AssertStringNotEmpty(title);

            //
            // If the collection isn't there or it's empty, then bail out.
            //

            if (collection == null || collection.Count == 0)
            {
                return;
            }

            //
            // Surround the entire section with a <div> element.
            //

            writer.AddAttribute(HtmlTextWriterAttribute.Id, id);
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            //
            // Write out the table caption.
            //

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "table-caption");
            writer.RenderBeginTag(HtmlTextWriterTag.P);
            this.HtmlEncode(title, writer);
            writer.RenderEndTag(); // </p>
            writer.WriteLine();

            //
            // Some values can be large and add scroll bars to the page
            // as well as ruin some formatting. So we encapsulate the
            // table into a scrollable view that is controlled via the
            // style sheet.
            //

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "scroll-view");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            //
            // Create a table to display the name/value pairs of the
            // collection in 2 columns.
            //

            Table table = new Table();

            table.CellSpacing = 0;

            //
            // Create the header row and columns.
            //

            TableRow headRow = new TableRow();

            TableHeaderCell headCell;

            headCell          = new TableHeaderCell();
            headCell.Wrap     = false;
            headCell.Text     = "Name";
            headCell.CssClass = "name-col";

            headRow.Cells.Add(headCell);

            headCell          = new TableHeaderCell();
            headCell.Wrap     = false;
            headCell.Text     = "Value";
            headCell.CssClass = "value-col";

            headRow.Cells.Add(headCell);

            table.Rows.Add(headRow);

            //
            // Create a row for each entry in the collection.
            //

            string[] keys = collection.AllKeys;
            InvariantStringArray.Sort(keys);

            for (int keyIndex = 0; keyIndex < keys.Length; keyIndex++)
            {
                string key = keys[keyIndex];

                TableRow bodyRow = new TableRow();
                bodyRow.CssClass = keyIndex % 2 == 0 ? "even-row" : "odd-row";

                TableCell cell;

                //
                // Create the key column.
                //

                cell          = new TableCell();
                cell.Text     = HtmlEncode(key);
                cell.CssClass = "key-col";

                bodyRow.Cells.Add(cell);

                //
                // Create the value column.
                //

                cell          = new TableCell();
                cell.Text     = HtmlEncode(collection[key]);
                cell.CssClass = "value-col";

                bodyRow.Cells.Add(cell);

                table.Rows.Add(bodyRow);
            }

            //
            // Write out the table and close container tags.
            //

            table.RenderControl(writer);

            writer.RenderEndTag(); // </div>
            writer.WriteLine();

            writer.RenderEndTag(); // </div>
            writer.WriteLine();
        }