EmptyString() public static méthode

public static EmptyString ( string s, string filler ) : string
s string
filler string
Résultat string
 public override string ToString()
 {
     return(Mask.EmptyString(Exception.Message, Exception.GetType().FullName));
 }
Exemple #2
0
 public override string ToString()
 {
     return(Mask.EmptyString(MemberName, "<?member>")
            + "@" + Mask.EmptyString(FilePath, "<?filename>")
            + ":" + LineNumber.ToInvariantString());
 }
        public override void Execute()
        {
            WriteLiteral("\r\n");



            #line 5 "..\..\ErrorMailHtmlPage.cshtml"

            // NB cast is not really required, but aids with intellisense!
            var error = (Error)this.Error;

            var about = PoweredBy.GetAbout(HttpRuntime.Cache, (version, fileVersion, product, copyright) => new
            {
                Version = version != null
                ? version.ToString()
                : fileVersion != null
                ? fileVersion.ToString()
                : "?.?.?.?",
                Product   = Mask.EmptyString(product, "(product)"),
                Copyright = copyright,
            });



            #line default
            #line hidden
            WriteLiteral("<html>\r\n    <head>\r\n        <title>Error: ");



            #line 22 "..\..\ErrorMailHtmlPage.cshtml"
            Write(error.Message);


            #line default
            #line hidden
            WriteLiteral(@"</title>
        <style type=""text/css"">
            body { font-family: verdana, arial, helvetic; font-size: x-small; }
            table.collection { border-collapse: collapse; border-spacing: 0; border: 1px solid black; width: 100% }
            table.collection tr { vertical-align: top; }
            table.collection th { text-align: left; border: 1px solid black; padding: 4px; font-weight: bold; }
            table.collection td { border: 1px solid black; padding: 4px; }
            td, th, pre { font-size: x-small; } 
            #errorDetail { padding: 1em; background-color: #FFFFCC; } 
            #errorMessage { font-size: medium; font-style: italic; color: maroon; }
            h1 { font-size: small; }
        </style>
    </head>
    <body>
        <p id=""errorMessage"">");



            #line 36 "..\..\ErrorMailHtmlPage.cshtml"
            Write(error.Type);


            #line default
            #line hidden
            WriteLiteral(": ");



            #line 36 "..\..\ErrorMailHtmlPage.cshtml"
            Write(error.Message);


            #line default
            #line hidden
            WriteLiteral("</p>\r\n");



            #line 37 "..\..\ErrorMailHtmlPage.cshtml"
            if (error.Time != DateTime.MinValue)
            {
            #line default
            #line hidden
                WriteLiteral("            <p>Generated: ");



            #line 39 "..\..\ErrorMailHtmlPage.cshtml"
                Write(error.Time.ToUniversalTime().ToString("r"));


            #line default
            #line hidden
                WriteLiteral("</p>\r\n");



            #line 40 "..\..\ErrorMailHtmlPage.cshtml"
            }


            #line default
            #line hidden


            #line 41 "..\..\ErrorMailHtmlPage.cshtml"
            if (error.Detail.Length != 0)
            {
            #line default
            #line hidden


                WriteLiteral("<pre id=\"errorDetail\">");



            #line 46 "..\..\ErrorMailHtmlPage.cshtml"
                Write(error.Detail);


            #line default
            #line hidden
                WriteLiteral("</pre>\r\n");



            #line 47 "..\..\ErrorMailHtmlPage.cshtml"
            }


            #line default
            #line hidden


            #line 48 "..\..\ErrorMailHtmlPage.cshtml"
            foreach (var collection in
                     from collection in new[]
            {
                new
                {
                    Id = "ServerVariables",
                    Title = "Server Variables",
                    Items = error.ServerVariables,
                }
            }
                     let data = collection.Items
                                where data != null && data.Count > 0
                                let items = from i in Enumerable.Range(0, data.Count)
                                            select KeyValuePair.Create(data.GetKey(i), data[i])
                                            select new
            {
                collection.Id,
                collection.Title,
                Items = items.OrderBy(e => e.Key, StringComparer.OrdinalIgnoreCase)
            }
                     )
            {
            #line default
            #line hidden
                WriteLiteral("            <div id=\"");



            #line 70 "..\..\ErrorMailHtmlPage.cshtml"
                Write(collection.Id);


            #line default
            #line hidden
                WriteLiteral("\">\r\n                <h1>");



            #line 71 "..\..\ErrorMailHtmlPage.cshtml"
                Write(collection.Title);


            #line default
            #line hidden
                WriteLiteral("</h1>\r\n                <table class=\"collection\">\r\n                    <tr><th>Na" +
                             "me</th>            \r\n                        <th>Value</th></tr>\r\n");



            #line 75 "..\..\ErrorMailHtmlPage.cshtml"
                foreach (var item in collection.Items)
                {
            #line default
            #line hidden
                    WriteLiteral("                        <tr><td>");



            #line 77 "..\..\ErrorMailHtmlPage.cshtml"
                    Write(item.Key);


            #line default
            #line hidden
                    WriteLiteral("</td>\r\n                            <td>");



            #line 78 "..\..\ErrorMailHtmlPage.cshtml"
                    Write(item.Value);


            #line default
            #line hidden
                    WriteLiteral("</td></tr>\r\n");



            #line 79 "..\..\ErrorMailHtmlPage.cshtml"
                }


            #line default
            #line hidden
                WriteLiteral("                </table>\r\n            </div>\r\n");



            #line 82 "..\..\ErrorMailHtmlPage.cshtml"
            }


            #line default
            #line hidden
            WriteLiteral("        <p>Powered by <a href=\"http://elmah.googlecode.com/\">");



            #line 83 "..\..\ErrorMailHtmlPage.cshtml"
            Write(about.Product);


            #line default
            #line hidden
            WriteLiteral("</a>, \r\n            version ");



            #line 84 "..\..\ErrorMailHtmlPage.cshtml"
            Write(about.Version);


            #line default
            #line hidden
            WriteLiteral("\r\n            ");



            #line 85 "..\..\ErrorMailHtmlPage.cshtml"
            Write(about.Copyright);


            #line default
            #line hidden
            WriteLiteral(" \r\n            Licensed under <a href=\"http://www.apache.org/licenses/LICENSE-2.0" +
                         "\">Apache License, Version 2.0</a>. \r\n        </p>\r\n    </body>\r\n</html>\r\n");
        }
Exemple #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 OnInit but does not override the
            // MailSender and MailRecipient properties.
            //

            string sender        = Mask.NullString(this.MailSender);
            string recipient     = Mask.NullString(this.MailRecipient);
            string copyRecipient = Mask.NullString(this.MailCopyRecipient);

#if NET_1_0 || NET_1_1
            //
            // The sender can be defaulted in the <system.net> settings in 2.0
            //

            if (sender.Length == 0)
            {
                return;
            }
#endif

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

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

            MailMessage mail = new MailMessage();
            mail.Priority = this.MailPriority;

#if NET_1_0 || NET_1_1
            mail.From = sender;
            mail.To   = recipient;

            if (copyRecipient.Length > 0)
            {
                mail.Cc = copyRecipient;
            }
#else
            mail.From = new MailAddress(sender);
            mail.To.Add(recipient);

            if (copyRecipient.Length > 0)
            {
                mail.CC.Add(copyRecipient);
            }
#endif
            //
            // Format the mail subject.
            //

            string subjectFormat = Mask.EmptyString(this.MailSubjectFormat, "Error ({1}): {0}");
            mail.Subject = string.Format(subjectFormat, error.Message, error.Type).
                           Replace('\r', ' ').Replace('\n', ' ');

            //
            // Format the mail body.
            //

            ErrorTextFormatter formatter = CreateErrorFormatter();

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

            switch (formatter.MimeType)
            {
#if NET_1_0 || NET_1_1
            case "text/html": mail.BodyFormat = MailFormat.Html; break;

            case "text/plain": mail.BodyFormat = MailFormat.Text; break;
#else
            case "text/html": mail.IsBodyHtml = true; break;

            case "text/plain": mail.IsBodyHtml = false; break;
#endif
            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));
            }
            }

#if NET_1_1
            //
            // If the mail needs to be delivered to a particular SMTP server
            // then set-up the corresponding CDO configuration fields of the
            // mail message.
            //

            string smtpServer = Mask.NullString(this.SmtpServer);

            if (smtpServer.Length > 0)
            {
                IDictionary fields = mail.Fields;

                fields.Add(CdoConfigurationFields.SendUsing, /* cdoSendUsingPort */ 2);
                fields.Add(CdoConfigurationFields.SmtpServer, smtpServer);
                int smtpPort = this.SmtpPort;
                fields.Add(CdoConfigurationFields.SmtpServerPort, smtpPort <= 0 ? 25 : smtpPort);

                //
                // If the SMTP server requires authentication (indicated by
                // non-blank user name and password settings) then set-up
                // the corresponding CDO configuration fields of the mail
                // message.
                //

                string userName = Mask.NullString(this.AuthUserName);
                string password = Mask.NullString(this.AuthPassword);

                if (userName.Length > 0 && password.Length > 0)
                {
                    fields.Add(CdoConfigurationFields.SmtpAuthenticate, 1);
                    fields.Add(CdoConfigurationFields.SendUserName, userName);
                    fields.Add(CdoConfigurationFields.SendPassword, password);
                }
            }
#endif
            MailAttachment     ysodAttachment = null;
            ErrorMailEventArgs args           = new ErrorMailEventArgs(error, mail);

            try
            {
                //
                // If an HTML message was supplied by the web host then attach
                // it to the mail if not explicitly told not to do so.
                //

                if (!NoYsod && error.WebHostHtmlMessage.Length > 0)
                {
                    ysodAttachment = CreateHtmlAttachment("YSOD", error.WebHostHtmlMessage);

                    if (ysodAttachment != null)
                    {
                        mail.Attachments.Add(ysodAttachment);
                    }
                }

                //
                // Send off the mail with some chance to pre- or post-process
                // using event.
                //

                OnMailing(args);
                if (UseExchangeWebServices)
                {
                    SendExchangeMail(mail);
                }
                else
                {
                    SendMail(mail);
                }
                OnMailed(args);
            }
            finally
            {
#if NET_1_0 || NET_1_1
                //
                // Delete any attached files, if necessary.
                //

                if (ysodAttachment != null)
                {
                    File.Delete(ysodAttachment.Filename);
                    mail.Attachments.Remove(ysodAttachment);
                }
#endif
                OnDisposingMail(args);

#if !NET_1_0 && !NET_1_1
                mail.Dispose();
#endif
            }
        }
Exemple #5
0
        public override void Execute()
        {
            WriteLiteral("\r\n");



            WriteLiteral("\r\n");



            #line 12 "..\..\MasterPage.cshtml"

            var basePageName = Request.ServerVariables["URL"];

            var now = DateTime.Now;
            var tz  = TimeZone.CurrentTimeZone;

            var about = PoweredBy.GetAbout(Context.Cache, (version, fileVersion, product, copyright) => new
            {
                Version = version != null
                  ? version.ToString()
                  : fileVersion != null
                  ? fileVersion.ToString()
                  : "?.?.?.?",
                Product   = Mask.EmptyString(product, "(product)"),
                Copyright = copyright,
            });

            var speedBarItems = (SpeedBarItems ?? Enumerable.Empty <SpeedBar.FormattedItem>()).ToArray();



            #line default
            #line hidden
            WriteLiteral("<!DOCTYPE html>\r\n<html>\r\n    <head>\r\n");



            #line 34 "..\..\MasterPage.cshtml"
            if (!string.IsNullOrEmpty(Title))
            {
            #line default
            #line hidden
                WriteLiteral("            <title>");



            #line 36 "..\..\MasterPage.cshtml"
                Write(Title);


            #line default
            #line hidden
                WriteLiteral("</title>\r\n");



            #line 37 "..\..\MasterPage.cshtml"
            }


            #line default
            #line hidden


            #line 38 "..\..\MasterPage.cshtml"



            #line default
            #line hidden
            WriteLiteral(@"        <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
        <!--[if lt IE 9]>
          <script src=""http://html5shim.googlecode.com/svn/trunk/html5.js""></script>
        <![endif]-->
        <link rel=""stylesheet"" type=""text/css"" href=""");



            #line 43 "..\..\MasterPage.cshtml"
            Write(basePageName);


            #line default
            #line hidden
            WriteLiteral("/stylesheet?h=");



            #line 43 "..\..\MasterPage.cshtml"
            Write(Uri.EscapeDataString(StyleSheetHelper.StyleSheetHash));


            #line default
            #line hidden
            WriteLiteral("\" />\r\n        <style type=\"text/css\">\r\n          body {\r\n            padding-top:" +
                         " 60px;\r\n          }\r\n        </style>\r\n    </head>\r\n    <body>\r\n");



            #line 51 "..\..\MasterPage.cshtml"
            if (speedBarItems.Any())
            {
            #line default
            #line hidden
                WriteLiteral(@"            <div id=""topnavbar"" class=""navbar navbar-fixed-top"">
                <div class=""navbar-inner"">
                    <div class=""container"">
                        <a class=""brand"" href=""http://elmah.googlecode.com/"">ELMAH</a>
                        ");



            #line 57 "..\..\MasterPage.cshtml"
                Write(SpeedBar.Render(Request.Browser, speedBarItems));


            #line default
            #line hidden
                WriteLiteral("\r\n                    </div>\r\n                </div>\r\n            </div>\r\n");



            #line 61 "..\..\MasterPage.cshtml"
            }


            #line default
            #line hidden
            WriteLiteral("        <div class=\"container-fluid\">\r\n            \r\n            ");



            #line 64 "..\..\MasterPage.cshtml"
            Write(RenderBody());


            #line default
            #line hidden
            WriteLiteral("\r\n            \r\n            <footer id=\"Footer\">\r\n                <span>Powered b" +
                         "y <a href=\"http://elmah.googlecode.com/\">");



            #line 67 "..\..\MasterPage.cshtml"
            Write(about.Product);


            #line default
            #line hidden
            WriteLiteral("</a>, \r\n                    version ");



            #line 68 "..\..\MasterPage.cshtml"
            Write(about.Version);


            #line default
            #line hidden
            WriteLiteral(".\r\n                    ");



            #line 69 "..\..\MasterPage.cshtml"
            Write(about.Copyright);


            #line default
            #line hidden
            WriteLiteral(" \r\n                    Licensed under <a href=\"http://www.apache.org/licenses/LIC" +
                         "ENSE-2.0\">Apache License, Version 2.0</a>. \r\n                </span>\r\n          " +
                         "      Server date is ");



            #line 72 "..\..\MasterPage.cshtml"
            Write(now.ToString("D", CultureInfo.InvariantCulture));


            #line default
            #line hidden
            WriteLiteral(". \r\n                Server time is ");



            #line 73 "..\..\MasterPage.cshtml"
            Write(now.ToString("T", CultureInfo.InvariantCulture));


            #line default
            #line hidden
            WriteLiteral(". \r\n                All dates and times displayed are in the \r\n                ");



            #line 75 "..\..\MasterPage.cshtml"
            Write(tz.IsDaylightSavingTime(now) ? tz.DaylightName : tz.StandardName);


            #line default
            #line hidden
            WriteLiteral(" zone. \r\n                ");



            #line 76 "..\..\MasterPage.cshtml"
            Write(Footnote);


            #line default
            #line hidden
            WriteLiteral("\r\n            </footer>\r\n        </div>\r\n    </body>\r\n</html>\r\n");
        }
Exemple #6
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 OnInit but does not override the
            // MailSender and MailRecipient properties.
            //

            var sender        = this.MailSender ?? string.Empty;
            var recipient     = this.MailRecipient ?? string.Empty;
            var copyRecipient = this.MailCopyRecipient ?? string.Empty;

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

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

            var mail = new MailMessage();

            mail.Priority = this.MailPriority;

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

            if (copyRecipient.Length > 0)
            {
                mail.CC.Add(copyRecipient);
            }

            //
            // Format the mail subject.
            //

            var subjectFormat = Mask.EmptyString(this.MailSubjectFormat, "Error ({1}): {0}");

            mail.Subject = string.Format(subjectFormat, error.Message, error.Type).
                           Replace('\r', ' ').Replace('\n', ' ');

            //
            // Format the mail body.
            //

            var formatter = CreateErrorFormatter();

            var 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));
            }
            }

            var args = new ErrorMailEventArgs(error, mail);

            try
            {
                //
                // If an HTML message was supplied by the web host then attach
                // it to the mail if not explicitly told not to do so.
                //

                if (!NoYsod && error.WebHostHtmlMessage.Length > 0)
                {
                    var ysodAttachment = CreateHtmlAttachment("YSOD", error.WebHostHtmlMessage);

                    if (ysodAttachment != null)
                    {
                        mail.Attachments.Add(ysodAttachment);
                    }
                }

                //
                // Send off the mail with some chance to pre- or post-process
                // using event.
                //

                OnMailing(args);
                SendMail(mail);
                OnMailed(args);
            }
            finally
            {
                OnDisposingMail(args);
                mail.Dispose();
            }
        }
Exemple #7
0
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (_result != null)
            {
                throw new InvalidOperationException("An asynchronous operation is already pending.");
            }

            HttpRequest         request = context.Request;
            NameValueCollection query   = request.QueryString;

            //
            // Limit the download by some maximum # of records?
            //

            _maxDownloadCount = Math.Max(0, Convert.ToInt32(query["limit"], CultureInfo.InvariantCulture));

            //
            // Determine the desired output format.
            //

            string format = Mask.EmptyString(query["format"], "csv").ToLower(CultureInfo.InvariantCulture);

            switch (format)
            {
            case "csv": _format = new CsvFormat(context); break;

            case "jsonp": _format = new JsonPaddingFormat(context); break;

            case "html-jsonp": _format = new JsonPaddingFormat(context, /* wrapped */ true); break;

            default:
                throw new Exception("Request log format is not supported.");
            }

            Debug.Assert(_format != null);

            //
            // Emit format header, initialize and then fetch results.
            //

            context.Response.BufferOutput = false;
            _format.Header();

            AsyncResult result = _result = new AsyncResult(extraData);

            _log            = ErrorLog.GetDefault(context);
            _pageIndex      = 0;
            _lastBeatTime   = DateTime.Now;
            _context        = context;
            _callback       = cb;
            _errorEntryList = new List <ErrorLogEntry>(_pageSize);

            _log.BeginGetErrors(_pageIndex, _pageSize, _errorEntryList,
                                new AsyncCallback(GetErrorsCallback), null);

            return(result);
        }
Exemple #8
0
        public override void Execute()
        {
            WriteLiteral("\r\n");



            #line 3 "..\..\PoweredBy.cshtml"

            var about = GetAbout((version, fileVersion, product, copyright) => new
            {
                Version = version != null
                  ? version.ToString()
                  : fileVersion != null
                  ? fileVersion.ToString()
                  : "?.?.?.?",
                Product   = Mask.EmptyString(product, "(product)"),
                Copyright = copyright,
            });


            #line default
            #line hidden
            WriteLiteral("<span>\r\n    Powered by <a href=\"http://elmah.googlecode.com/\">");



            #line 15 "..\..\PoweredBy.cshtml"
            Write(about.Product);


            #line default
            #line hidden
            WriteLiteral("</a>,\r\n    version ");



            #line 16 "..\..\PoweredBy.cshtml"
            Write(about.Version);


            #line default
            #line hidden


            #line 16 "..\..\PoweredBy.cshtml"

#if DEBUG
            #line default
            #line hidden
            WriteLiteral(" (");



            #line 18 "..\..\PoweredBy.cshtml"
            Write(Build.Configuration);


            #line default
            #line hidden
            WriteLiteral(")");



            #line 18 "..\..\PoweredBy.cshtml"
                                    #endif


            #line default
            #line hidden
            WriteLiteral(".\r\n    ");



            #line 20 "..\..\PoweredBy.cshtml"
            Write(about.Copyright);


            #line default
            #line hidden
            WriteLiteral("\r\n    Licensed under <a href=\"http://www.apache.org/licenses/LICENSE-2.0\">Apache " +
                         "License, Version 2.0</a>.\r\n</span>\r\n");
        }