Well that is certainly very interesting, never really touched this in the past.
Problem is, that it does not really solve my problem.

My use case is the following:
I need to send mails that, during generation, are conscient of the
current context (IEngine and anything else that flows around at the
time). Not having context, as a side effect, does not allow me to use
view components.
So I figured it would be cool, if, within a controller/action I could
do more or less this:
                
                public void ConfirmCompletedOrder(){
                        var order = somehowGetIt();
                        PropertyBag["order"] = order;
                        string messageBody = GetAsString("Order", "Info", 
order.Id,
Context); // that invokes
                        // OrderController.Info(order.Id), captures
the response as string and returns it
                        var message = new Message();
                        message.Body = messageBody();
                        SendMessage(message);
                }

While your code shows me how to get the current controller's response
as a string (and manipulate it), I wonder how this could be done for a
different action, on a different controller and only when needed.
Currently sending mails is done by directly invoking the view engine,
bypassing the controller/action. I wonder what is the advantage of
this...


On Sat, Sep 27, 2008 at 1:06 AM, Mike Nichols <[EMAIL PROTECTED]> wrote:
>
> Hm...well, you maybe you could implement an after action filter and
> within the filter have an implementation of TransformFilter (just an
> HttpFilter) grab the string from the and clear the buffer. Here's an
> filter (not an monorail filter, an HttpFilter) that I use to modify
> the response in another filter I implement. I use this in my after
> render step of the Monorail filter:
>
> context.UnderlyingContext.Response.Filter =new
> ModifyResponseFilter(context.UnderlyingContext.Response.Filter,
> ResponseModifier);
>
> and HttpFilter is :
>
> /// <summary>
>        /// Delegate for modifying the contents of the response. Passes in
> the current response text for manipulation and
>        /// requires the final response to be write back into the stream.
>        /// </summary>
>        public delegate string ModifyResponse(string responseText);
>        /// <summary>
>        /// For intercepting the response and manipulating it with the <see
> cref="ModifyResponse"/> passed in.
>        /// </summary>
>        public class ModifyResponseFilter : TransformFilter
>        {
>                private readonly ModifyResponse responseModifier;
>
>                /// <summary>
>                /// Initializes a new instance of the <see
> cref="ModifyResponseFilter"/> class.
>                /// </summary>
>                /// <param name="baseStream">The base stream.</param>
>                /// <param name="responseModifier">The response 
> modifier.</param>
>                public ModifyResponseFilter( Stream baseStream, ModifyResponse
> responseModifier):base(baseStream)
>                {
>                        this.responseModifier = responseModifier;
>                }
>
>                /// <summary>
>                /// When overridden in a derived class, writes a sequence of 
> bytes
> to the current stream and advances the current position within this
> stream by the number of bytes written.
>                /// </summary>
>                /// <param name="buffer">An array of bytes. This method copies
> <paramref name="count"/> bytes from <paramref name="buffer"/> to the
> current stream.</param>
>                /// <param name="offset">The zero-based byte offset in 
> <paramref
> name="buffer"/> at which to begin copying bytes to the current
> stream.</param>
>                /// <param name="count">The number of bytes to be written to 
> the
> current stream.</param>
>                /// <exception cref="T:System.ArgumentException">The sum of
> <paramref name="offset"/> and <paramref name="count"/> is greater than
> the buffer length. </exception>
>                /// <exception cref="T:System.ArgumentNullException">
>                ///     <paramref name="buffer"/> is null. </exception>
>                /// <exception cref="T:System.ArgumentOutOfRangeException">
>                ///     <paramref name="offset"/> or <paramref name="count"/> 
> is
> negative. </exception>
>                /// <exception cref="T:System.IO.IOException">An I/O error 
> occurs. </
> exception>
>                /// <exception cref="T:System.NotSupportedException">The 
> stream does
> not support writing. </exception>
>                /// <exception cref="T:System.ObjectDisposedException">Methods 
> were
> called after the stream was closed. </exception>
>                public override void Write(byte[] buffer, int offset, int 
> count)
>                {
>                        if (Closed) throw new
> ObjectDisposedException("ModifyResponseFilter");
>                        if(responseModifier== null)
>                        {
>                                throw new 
> ArgumentNullException("responseModifier");
>                        }
>                        //Get a string version of the buffer
>                        string content =
> responseModifier(Encoding.Default.GetString(buffer, offset, count));
>
>                        byte[] newOutput = Encoding.Default.GetBytes(content);
>                        BaseStream.Write(newOutput, 0, newOutput.Length);
>                }
>        }
>
>
> >
>



-- 
Jan
___________________
[EMAIL PROTECTED]
www.limpens.com
+55 (11) 3082-1087
+55 (11) 3097-8339

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to