Ejemplo n.º 1
0
        void GenerateMessageBody(
            MailMessage msg,
            WebBaseEventCollection events,
            DateTime lastNotificationUtc,
            int discardedSinceLastNotification,
            int eventsInBuffer,
            int notificationSequence,
            EventNotificationType notificationType,
            int eventsInNotification,
            int eventsRemaining,
            int messagesInNotification,
            int eventsLostDueToMessageLimit,
            int messageSequence,
            out bool fatalError)
        {
            StringWriter writer = new StringWriter(CultureInfo.InstalledUICulture);

            MailEventNotificationInfo info = new MailEventNotificationInfo(
                msg,
                events,
                lastNotificationUtc,
                discardedSinceLastNotification,
                eventsInBuffer,
                notificationSequence,
                notificationType,
                eventsInNotification,
                eventsRemaining,
                messagesInNotification,
                eventsLostDueToMessageLimit,
                messageSequence);

            CallContext.SetData(CurrentEventsName, info);

            try {
                TemplatedMailErrorFormatterGenerator gen = new TemplatedMailErrorFormatterGenerator(events.Count + eventsRemaining, _detailedTemplateErrors);
                HttpServerUtility.ExecuteLocalRequestAndCaptureResponse(_templateUrl, writer, gen);

                fatalError = gen.ErrorFormatterCalled;

                if (fatalError)
                {
                    msg.Subject = HttpUtility.HtmlEncode(SR.GetString(SR.WebEvent_event_email_subject_template_error,
                                                                      notificationSequence.ToString(CultureInfo.InstalledUICulture),
                                                                      messageSequence.ToString(CultureInfo.InstalledUICulture),
                                                                      SubjectPrefix));
                }

                msg.Body       = writer.ToString();
                msg.IsBodyHtml = true;
            }
            finally {
                CallContext.FreeNamedDataSlot(CurrentEventsName);
            }
        }