コード例 #1
0
ファイル: EmailViewResult.cs プロジェクト: kwolsey/postal
        /// <summary>
        /// Writes the email preview in the given format.
        /// </summary>
        /// <returns>The content type for the HTTP response.</returns>
        public string ExecuteResult(TextWriter writer, RequestUrl url, string format = null)
        {
            var result      = Renderer.Render(Email, url);
            var mailMessage = Parser.Parse(result, Email);

            // no special requests; render what's in the template
            if (string.IsNullOrEmpty(format))
            {
                if (!mailMessage.IsBodyHtml)
                {
                    writer.WriteAsync(result);
                    return(TextContentType);
                }

                var template = Extract(result);
                template.Write(writer);
                return(HtmlContentType);
            }

            // Check if alternative
            var alternativeContentType = CheckAlternativeViews(writer, mailMessage, format);

            if (!string.IsNullOrEmpty(alternativeContentType))
            {
                return(alternativeContentType);
            }

            if (format == "text")
            {
                if (mailMessage.IsBodyHtml)
                {
                    throw new NotSupportedException("No text view available for this email");
                }

                writer.Write(result);
                return(TextContentType);
            }

            if (format == "html")
            {
                if (!mailMessage.IsBodyHtml)
                {
                    throw new NotSupportedException("No html view available for this email");
                }

                var template = Extract(result);
                template.Write(writer);
                return(HtmlContentType);
            }

            throw new NotSupportedException(string.Format("Unsupported format {0}", format));
        }
コード例 #2
0
ファイル: EmailParser.cs プロジェクト: kwolsey/postal
 public EmailParser(IEmailViewRenderer alternativeViewRenderer, RequestUrl url)
 {
     this.alternativeViewRenderer = alternativeViewRenderer;
     _url = url;
 }
コード例 #3
0
ファイル: EmailViewRenderer.cs プロジェクト: kwolsey/postal
 /// <summary>
 /// Renders an email view.
 /// </summary>
 /// <param name="email">The email to render.</param>
 /// <param name="requsetFeature">IHttpRequestFeature</param>
 /// <param name="viewName">Optional email view name override. If null then the email's ViewName property is used instead.</param>
 /// <returns>The rendered email view output.</returns>
 public virtual string Render(Email email, RequestUrl url, string viewName = null)
コード例 #4
0
ファイル: EmailViewResult.cs プロジェクト: kwolsey/postal
        /// <summary>
        /// Creates a new <see cref="EmailViewResult"/>.
        /// </summary>
#if ASPNET5
        public EmailViewResult(Email email, IEmailViewRenderer renderer, IEmailParser parser, IServiceProvider serviceProvider, RequestUrl url)
        {
            Email       = email;
            Renderer    = renderer ?? new EmailViewRenderer(serviceProvider);
            Parser      = parser ?? new EmailParser(Renderer, url);
            _requestUrl = url;
        }