Archive for January, 2008

Eleutian Vim Screencast Episode #1

After Aaron’s teaser on vim, I have been waiting for him to start the series. Episode #1 of Aaron’s Vim screencast series is up. Its a basic intro for opening and saving documents as well as learning to use some simple navigation. The use of keyboard jedi is very nice for seeing everything that is going on. Nice work Aaron! If you are unfamiliar with vim I highly recommend subscribing to Eleutian’s blog and following the series. The productivity boost you will gain down the road is priceless.

Ms MVC at CNUG

Yesterday at the Chicago .Net User Group meeting Nermin Dibek presented on the new ms mvc framework.  Several people were interested in a follow up session.  If you are one of those people and have stumbled onto this blog, or if you are local to Chicago and want to see some more stuff, feel free to ping me or email me and we can try and set something up.

Here is a list of links to get you started with Ms MVC.

MS MVC: Blocks Refactored

In my last post I talked about adding blocks to ms mvc to capture output.  Our solution used an ugly hack with reflection, type caching, and lwg.  Thanks to Jeremy Skinner and Phil who both pointed out you can use a response output filter to do the same thing.  So here is an update to our capturing class.

/// <summary>Renders the action and returns a string.</summary>
/// <param name="viewRenderer">The delegate to render.</param>
/// <returns>The rendered text.</returns>
public string Capture(Action viewRenderer)
{
  IHttpResponse resp = _httpContext.Response;
  Stream originalFilter = null;
  CapturingResponseFilter innerFilter;
  string capturedHtml = "";

  if (viewRenderer != null)
  {
    try
    {
      resp.Flush();
      originalFilter = resp.Filter;
      innerFilter = new CapturingResponseFilter(resp.Filter);
      resp.Filter = innerFilter;
      viewRenderer();
      resp.Flush();
      capturedHtml = innerFilter.GetContents(resp.ContentEncoding);
    }
    finally
    {
      if (originalFilter != null)
      {
        resp.Filter = originalFilter;
      }
    }
  }
  return capturedHtml;
}

The only thing to remember is to flush current response before and after you capture the text.  The CapturingResponseFilter just inherits from Stream and is using a MemoryStream internally.  The call to GetContents just dumps the memory stream to a string using the current encoding of the response.

What do you think… much simpler :)

Thanks Jeremy and Phil.