From 845a1cd9a39eafdc4ccb177aee7f47b25c8e3134 Mon Sep 17 00:00:00 2001 From: loudej Date: Sat, 19 Dec 2009 01:54:08 +0000 Subject: [PATCH] Refactoring content capture into a InnerWriter substitution. Adding content dictionary to layout context. --HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4044311 --- .../UI/ContentCapture/ContentCaptureFilter.cs | 24 ----- .../UI/ContentCapture/ContentCaptureStream.cs | 92 ------------------- .../UI/ContentCapture/IContentCapture.cs | 11 --- 3 files changed, 127 deletions(-) delete mode 100644 src/Orchard/UI/ContentCapture/ContentCaptureFilter.cs delete mode 100644 src/Orchard/UI/ContentCapture/ContentCaptureStream.cs delete mode 100644 src/Orchard/UI/ContentCapture/IContentCapture.cs diff --git a/src/Orchard/UI/ContentCapture/ContentCaptureFilter.cs b/src/Orchard/UI/ContentCapture/ContentCaptureFilter.cs deleted file mode 100644 index a7244d57b..000000000 --- a/src/Orchard/UI/ContentCapture/ContentCaptureFilter.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.IO; -using System.Web.Mvc; -using Orchard.Mvc.Filters; - -namespace Orchard.UI.ContentCapture { - public class ContentCaptureFilter : FilterProvider, IResultFilter { - private readonly IContentCapture _contentCapture; - - public ContentCaptureFilter(IContentCapture contentCapture) { - //_contentCapture = contentCapture; - } - - public void OnResultExecuting(ResultExecutingContext filterContext) { - //if (filterContext.Result is ViewResult) { - // _contentCapture.CaptureStream = filterContext.HttpContext.Response.Filter; - // filterContext.HttpContext.Response.Filter = _contentCapture as Stream; - // filterContext.HttpContext.Response.Buffer = false; - //} - } - - public void OnResultExecuted(ResultExecutedContext filterContext) { - } - } -} \ No newline at end of file diff --git a/src/Orchard/UI/ContentCapture/ContentCaptureStream.cs b/src/Orchard/UI/ContentCapture/ContentCaptureStream.cs deleted file mode 100644 index 5647ec31b..000000000 --- a/src/Orchard/UI/ContentCapture/ContentCaptureStream.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace Orchard.UI.ContentCapture { - public class ContentCaptureStream : Stream, IContentCapture { - private List _contentBuffer; - private string _contentCaptureName; - private readonly Dictionary _contents; - - public ContentCaptureStream() { - _contents = new Dictionary(20); - } - - public Stream CaptureStream { get; set; } - - public override bool CanRead { - get { return CaptureStream.CanRead; } - } - - public override bool CanSeek { - get { return CaptureStream.CanSeek; } - } - - public override bool CanWrite { - get { return CaptureStream.CanWrite; } - } - - public override long Length { - get { return CaptureStream.Length; } - } - - public override long Position { - get { return CaptureStream.Position; } - set { CaptureStream.Position = value; } - } - - public override void Flush() { - CaptureStream.Flush(); - } - - public override int Read(byte[] buffer, int offset, int count) { - return CaptureStream.Read(buffer, offset, count); - } - - public override long Seek(long offset, SeekOrigin origin) { - return CaptureStream.Seek(offset, origin); - } - - public override void SetLength(long value) { - CaptureStream.SetLength(value); - } - - public override void Write(byte[] buffer, int offset, int count) { - if (_contentCaptureName != null) - _contentBuffer.AddRange(buffer); - else - CaptureStream.Write(buffer, 0, buffer.Length); - } - - public Dictionary GetContents() { - if (_contentCaptureName != null) - throw new ApplicationException("Can not get contents while capturing content"); - - Dictionary contents = new Dictionary(_contents.Count); - - foreach (KeyValuePair content in contents) - contents.Add(content.Key, content.Value); - _contents.Clear(); - - return contents; - } - - public void BeginContentCapture(string name) { - if (_contentCaptureName != null) - throw new ApplicationException("There is already content being captured"); - - _contentBuffer = new List(5000); - _contentCaptureName = name; - } - - public void EndContentCapture() { - if (_contentCaptureName == null) - throw new ApplicationException("There is currently no content being captured"); - - _contents.Add(_contentCaptureName, Encoding.UTF8.GetString(_contentBuffer.ToArray(), 0, _contentBuffer.Count)); - _contentCaptureName = null; - _contentBuffer = null; - } - } -} \ No newline at end of file diff --git a/src/Orchard/UI/ContentCapture/IContentCapture.cs b/src/Orchard/UI/ContentCapture/IContentCapture.cs deleted file mode 100644 index 7cecb254f..000000000 --- a/src/Orchard/UI/ContentCapture/IContentCapture.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Generic; -using System.IO; - -namespace Orchard.UI.ContentCapture { - public interface IContentCapture : IDependency { - Stream CaptureStream { get; set; } - Dictionary GetContents(); - void BeginContentCapture(string name); - void EndContentCapture(); - } -} \ No newline at end of file