Tuesday, November 27, 2012

Azure web-role with warmup

To avoid the spin-up time on an Azure role, I use the IIS Application Initialization (formally warm-up) module. The module is available by default for IIS8, so it's easier if you can run your azure role on Server 2012 (osFamily=3).

The step-by-step instructions describe how to configure the module for use. Using this along side an article on programmatic configuring azure app pool settings, I've got enough pieces to create a RoleEntryPoint for the task.

You will also need to (find) and include a reference to the Microsoft.Web.Administration assembly. Oh, and in addition to configuring the module, be sure to set the IIS IdleTimeout to 0 (zero).

Putting it all together:
Loading ....

Monday, November 12, 2012

Display summary for content item in Orchard.

Lately I've been building skills using Orchard CMS.
I ran into a problem trying to display a list of content items; in particular the in-built summary approach for Orchard didn't suite. The in-built approach takes the first 200 characters and displays them via the shape: Parts_Common_Body_Summary. This shape is created down inside the ~/Core/Common/Drivers/BodyPartDriver.cs, to be served up via the Parts.Common.Body.Summary.cshtml view template. Then; within the template; the body's html is used to create a excerpt of the first 200 chars, displayed as a p.

For me, I wanted to be able to specify the summary shape using html described in the content item itself. Initially I looked at just customizing the template view, I think this approach may have solved my immediate problem, but I would have had (yucky) logic inside my view template. Sounds like a great excuse for creating a Module :D

Since this was my first Orchard module, there was quite a learning curve to piece together how-to go about this problem. I can recommend the Pluralsight training video's to help you get started. Otherwise the Orchard Doco can help. Of course, nothing beats learning by tracing code and figuring it out yourself :D.

Normal content part driver's in Orchard create a shape, which is then served up via Orchard (don't forget placement) and displayed using a view template. Initially I was inclined to follow this pattern, and create my own "Parts_MySummary" shape for use. For better-or-worse, I opted to alter the existing Summary shape, I'm not 100% this is a good idea, but hey, if the fine folk over on the Orchard Project are going to make such a highly flexible and extensible CMS, then this is the kind of thing that'll happen :O.

To over-ride the in-built shape, I use my own IShapeTableProvider to hook into the display of the Parts_Common_Body_Summary, and with the magic that is IoC tada!

Since I was there, the module is built using 3 strategies for the summary:
  1. Default (fallback) to in-built
  2. First paragraph - extract the first p element from the body
  3. Explicit text - editor defines the summary text to use.
Ideally I would have made this more extensible; allowing for other strategies to also be used. But I couldn't work-out how to add shapes at run-time to represent different strategies. For now, if you want a different strategy: Add an ISummaryStrategy service and provide a better Part editor. I will have to re-visit when I learn more.

The final module is hosted on codeplex: http://kwdsummary.codeplex.com/

A short list of C# coding issues.

Injecting services into entities It been bugging me for a while now that to use services in a entity can be a bit of pain. It usually starts...