From 5776c5ab58095f97c0ae127d57877155c04f72bd Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 13 Sep 2010 17:59:51 -0700 Subject: [PATCH] Adding Capture method for WebForms --HG-- branch : theming --- src/Orchard/Mvc/ViewPage.cs | 21 ++++++++++++++++++++- src/Orchard/Mvc/ViewUserControl.cs | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Orchard/Mvc/ViewPage.cs b/src/Orchard/Mvc/ViewPage.cs index 9ed73ffbc..a0c41d652 100644 --- a/src/Orchard/Mvc/ViewPage.cs +++ b/src/Orchard/Mvc/ViewPage.cs @@ -2,6 +2,7 @@ using System.IO; using System.Web; using System.Web.Mvc; +using System.Web.UI; using Autofac; using Orchard.DisplayManagement; using Orchard.Localization; @@ -50,11 +51,29 @@ namespace Orchard.Mvc { } public IDisposable Capture(Action callback) { - throw new NotImplementedException(); + return new ViewContextSubstitution(Writer, callback); } } + public class ViewContextSubstitution : IDisposable { + private readonly HtmlTextWriter _context; + private readonly Action _callback; + private readonly TextWriter _oldWriter; + private readonly TextWriter _writer; + + public ViewContextSubstitution(HtmlTextWriter context, Action callback) { + _context = context; + _oldWriter = _context.InnerWriter; + _callback = callback; + _context.InnerWriter = _writer = new StringWriter(); + } + + public void Dispose() { + _callback(new HtmlString(_writer.ToString())); + _context.InnerWriter = _oldWriter; + } + } public class ViewPage : ViewPage { } } \ No newline at end of file diff --git a/src/Orchard/Mvc/ViewUserControl.cs b/src/Orchard/Mvc/ViewUserControl.cs index 13b386d2b..69ff8792d 100644 --- a/src/Orchard/Mvc/ViewUserControl.cs +++ b/src/Orchard/Mvc/ViewUserControl.cs @@ -53,7 +53,7 @@ namespace Orchard.Mvc { } public IDisposable Capture(Action callback) { - throw new NotImplementedException(); + return new ViewContextSubstitution(Writer, callback); } }