Esempio 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();
			}
		}
 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);
         }
     }
 }
        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();
                }
            }
        }
Esempio n. 4
0
        void RenderTarget(IHttpEntity response, object target)
        {
            var httpHandler = target as IHttpHandler;

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