Пример #1
0
        protected override void Render(HtmlTextWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            //
            // Retrieve the ID of the error to display and read it from
            // the log.
            //

            string errorId = StringEtc.MaskNull(this.Request.QueryString["id"]);

            if (errorId.Length == 0)
            {
                return;
            }

            ErrorLogEntry errorEntry = this.ErrorLog.GetError(errorId);

            if (errorEntry == null)
            {
                return;
            }

            //
            // If we have a host (ASP.NET) formatted HTML message
            // for the error then just stream it out as our response.
            //

            if (errorEntry.Error.WebHostHtmlMessage.Length != 0)
            {
                writer.Write(errorEntry.Error.WebHostHtmlMessage);
            }
        }
Пример #2
0
        /// <summary>
        /// Renders a collection as a table in HTML document body.
        /// </summary>
        /// <remarks>
        /// This method is called by <see cref="RenderCollections"/> to
        /// format a diagnostic collection from <see cref="Error"/> object.
        /// </remarks>

        protected virtual void RenderCollection(NameValueCollection collection, string caption)
        {
            if (collection == null || collection.Count == 0)
            {
                return;
            }

            HtmlTextWriter writer = this.Writer;

            writer.RenderBeginTag(HtmlTextWriterTag.H1);
            HttpUtility.HtmlEncode(caption, writer);
            writer.RenderEndTag(); // </h1>
            writer.WriteLine();

            //
            // Write a table with each key in the left column
            // and its value in the right column.
            //

            writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "5");
            writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
            writer.AddAttribute(HtmlTextWriterAttribute.Border, "1");
            writer.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
            writer.RenderBeginTag(HtmlTextWriterTag.Table);

            //
            // Write the column headings.
            //

            writer.AddAttribute(HtmlTextWriterAttribute.Valign, "top");
            writer.RenderBeginTag(HtmlTextWriterTag.Tr);

            writer.AddAttribute(HtmlTextWriterAttribute.Align, "left");
            writer.RenderBeginTag(HtmlTextWriterTag.Th);
            writer.Write("Name");
            writer.RenderEndTag(); // </th>

            writer.AddAttribute(HtmlTextWriterAttribute.Align, "left");
            writer.RenderBeginTag(HtmlTextWriterTag.Th);
            writer.Write("Value");
            writer.RenderEndTag(); // </th>

            writer.RenderEndTag(); // </tr>

            //
            // Write the main body of the table containing keys
            // and values in a two-column layout.
            //

            foreach (string key in collection.Keys)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Valign, "top");
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);

                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                HttpUtility.HtmlEncode(key, writer);
                writer.RenderEndTag(); // </td>

                writer.RenderBeginTag(HtmlTextWriterTag.Td);

                string value = StringEtc.MaskNull(collection[key]);

                if (value.Length != 0)
                {
                    HttpUtility.HtmlEncode(value, writer);
                }
                else
                {
                    writer.Write("&nbsp;");
                }

                writer.RenderEndTag(); // </td>

                writer.RenderEndTag(); // </tr>
            }

            writer.RenderEndTag(); // </table>
            writer.WriteLine();
        }
Пример #3
0
 public static void AssertStringNotEmpty(string s)
 {
     BaseDebug.Assert(StringEtc.MaskNull(s).Length != 0);
 }
Пример #4
0
        /// <summary>
        /// Schedules the error to be e-mailed synchronously.
        /// </summary>

        protected virtual void ReportError(Error error)
        {
            if (error == null)
            {
                throw new ArgumentNullException("error");
            }

            //
            // Start by checking if we have a sender and a recipient.
            // These values may be null if someone overrides the
            // implementation of Init but does not override the
            // MailSender and MailRecipient properties.
            //

            string sender    = StringEtc.MaskNull(this.MailSender);
            string recipient = StringEtc.MaskNull(this.MailRecipient);

            if (sender.Length == 0 || recipient.Length == 0)
            {
                return;
            }

            //
            // Create the mail, setting up the sender and recipient.
            //

            MailMessage mail = new MailMessage();

            mail.From = new MailAddress(sender);
            mail.To.Add(new MailAddress(recipient));

            //
            // Format the mail subject.
            //

            string subjectFormat = StringEtc.MaskNull(this.MailSubjectFormat);

            if (subjectFormat.Length == 0)
            {
                subjectFormat = "Error ({1}): {0}";
            }

            mail.Subject = string.Format(subjectFormat, error.Message, error.Type);

            //
            // Format the mail body.
            //

            ErrorTextFormatter formatter = CreateErrorFormatter();

            StringWriter bodyWriter = new StringWriter();

            formatter.Format(bodyWriter, error);
            mail.Body = bodyWriter.ToString();

            switch (formatter.MimeType)
            {
            case "text/html": mail.IsBodyHtml = true; break;

            case "text/plain": mail.IsBodyHtml = false;  break;

            default:
            {
                throw new ApplicationException(string.Format(
                                                   "The error mail module does not know how to handle the {1} media type that is created by the {0} formatter.",
                                                   formatter.GetType().FullName, formatter.MimeType));
            }
            }

            //
            // Provide one last hook to pre-process the mail and then send
            // it off.
            //

            try
            {
                PreSendMail(mail, error);
                SendMail(mail);
            }
            finally
            {
                DisposeMail(mail);
            }
        }