Ejemplo n.º 1
0
        private static void RenderToResponse(IHttpEntity response, ISparkView templateBase)
        {
            Encoding targetEncoding = Encoding.UTF8;

            response.ContentType.CharSet = targetEncoding.HeaderName;
            TextWriter writer     = null;
            bool       ownsWriter = false;

            try
            {
                if (response is ISupportsTextWriter)
                {
                    writer = ((ISupportsTextWriter)response).TextWriter;
                }
                else
                {
                    writer     = new DeterministicStreamWriter(response.Stream, targetEncoding, StreamActionOnDispose.None);
                    ownsWriter = true;
                }
                templateBase.RenderView(writer);
            }
            finally
            {
                if (ownsWriter)
                {
                    writer.Dispose();
                }
            }
        }
 protected void given_request_stream(string requestData, Encoding encoding)
 {
     given_request_stream(stream =>
     {
         using (var sw = new DeterministicStreamWriter(stream, encoding, StreamActionOnDispose.None))
         {
             sw.Write(requestData);
         }
     });
 }
Ejemplo n.º 3
0
 public void WriteTo(object entity, IHttpEntity response, string[] codecParameters)
 {
     if (response is ISupportsTextWriter)
     {
         TextWriter textWriter = ((ISupportsTextWriter)response).TextWriter;
         Render(entity, textWriter);
     }
     else
     {
         using (var streamWriter = new DeterministicStreamWriter(response.Stream, new UTF8Encoding(), StreamActionOnDispose.None))
         {
             Render(entity, streamWriter);
         }
     }
 }
Ejemplo n.º 4
0
        void RenderTarget(IHttpEntity response, object target)
        {
            var httpHandler = target as IHttpHandler;

            var targetEncoding = new UTF8Encoding(false);

            response.ContentType.CharSet = "utf-8";
            TextWriter writer       = null;
            var        isDisposable = target as IDisposable;
            bool       ownsWriter   = false;

            try
            {
                if (response is ISupportsTextWriter)
                {
                    writer = ((ISupportsTextWriter)response).TextWriter;
                }
                else
                {
                    writer = new DeterministicStreamWriter(response.Stream, targetEncoding, StreamActionOnDispose.None);

                    ownsWriter = true;
                }
                if (target is UserControl)
                {
                    var dummy = new Page();
                    dummy.Controls.Add(target as UserControl);
                    httpHandler = dummy;
                }
                if (httpHandler != null)
                {
                    HttpContext.Current.Server.Execute(httpHandler, writer, false);
                }
            }
            finally
            {
                if (isDisposable != null)
                {
                    isDisposable.Dispose();
                }
                if (ownsWriter)
                {
                    writer.Dispose();
                }
            }
        }
Ejemplo n.º 5
0
        private static void RenderTarget(IHttpEntity response, RazorViewBase target)
        {
            var targetEncoding = Encoding.UTF8;

            response.ContentType.CharSet = targetEncoding.HeaderName;
            TextWriter writer       = null;
            var        isDisposable = target as IDisposable;
            bool       ownsWriter   = false;

            try
            {
                if (response is ISupportsTextWriter)
                {
                    writer = ((ISupportsTextWriter)response).TextWriter;
                }
                else
                {
                    writer     = new DeterministicStreamWriter(response.Stream, targetEncoding, StreamActionOnDispose.None);
                    ownsWriter = true;
                }

                target.Output = writer;
                target.Execute();
            }
            finally
            {
                if (isDisposable != null)
                {
                    isDisposable.Dispose();
                }
                if (ownsWriter)
                {
                    writer.Dispose();
                }
            }
        }