Ph: 49990698
skip to main | skip to sidebar

Uprooting the entrenched

Wednesday, August 20, 2008

Flexible page design using Sitecore and Reflection

I wanted to share some code I developed to enable a very flexible page design system using Sitecore and Reflection.

What this class does is associate a WebControl with a specific item template. I use this object heavily within columns which allow a variety of items to be rendered. If I have a new design element which I need to add to Sitecore, I first design and configure the element within Sitecore.

To render this new item all I need to do is implement a new version of my abstract class within the class ContentRenderHelper and publish a new version on my application DLL.

A few caveats with this system. First all exceptions during an item's rendering will be thrown at the line "thisType.InvokeMember" This can make it difficult to troubleshoot problems, so be sure to utilize Sitecore's logging and/or tracing functionality. However you can add stop points and step through all this code, so debugging in a development environment is easy. Second this code does not limit what items can be rendered where. There are two possible solutions for this. Either keep a list of items in Sitecore than be rendered where and reference this data within the parent class and/or use a TreeList and configure which items can be add to each list.


public class ContentRenderHelper : Sitecore.Web.UI.WebControl
{
/// <summary>
/// Stores the item to render
/// </summary>
private Sitecore.Data.Items.Item itemToRender;

/// <summary>
/// Creates a new content render helper
/// </summary>
/// <param name="itemToRender">Item that needs to be rendered</param>
public ContentRenderHelper(Sitecore.Data.Items.Item itemToRender)
{
this.itemToRender = itemToRender;
}

/// <summary>
/// Gets or sets Item that needs to be rendered
/// </summary>
public Sitecore.Data.Items.Item ItemToRender
{
get { return this.itemToRender; }
set { this.itemToRender = value; }
}

/// <summary>
/// Converts a string guid to a template id
/// </summary>
/// <param name="guid">string value of guid</param>
/// <returns>Template ID from guid</returns>
protected static Sitecore.Data.TemplateID GetTemplateID(string guid)
{
return new Sitecore.Data.TemplateID(new Sitecore.Data.ID(guid));
}

/// <summary>
/// Render the correct control for this item
/// </summary>
/// <param name="output">Current HtmlTextWriter object</param>
protected override void DoRender(HtmlTextWriter output)
{
// Go get all of the nested types of this object
Type[] typeArray = this.GetType().GetNestedTypes(BindingFlags.NonPublic | BindingFlags.Public);

foreach (Type thisType in typeArray)
{
// Make sure this type isn't null, is a class, and implements ContentWebControl
if (thisType != null && thisType.IsClass && thisType.BaseType.Name == "ContentWebControl")
{
// Invoke the object
object targetObject = Activator.CreateInstance(thisType, new object[] { this.itemToRender });

// Get its template ID
Sitecore.Data.TemplateID thisTemplateId = (Sitecore.Data.TemplateID)thisType.InvokeMember("TemplateId", BindingFlags.GetProperty, null, targetObject, null);

if (thisTemplateId == this.itemToRender.TemplateID)
{
// If this templateID matches render the control
thisType.InvokeMember("RenderControl", BindingFlags.Default | BindingFlags.InvokeMethod, null, targetObject, new object[] { output });
}
}
}
}

/// <summary>
/// This abstract class is to be implemented to be rendered by the parent class
/// </summary>
protected abstract class ContentWebControl : Sitecore.Web.UI.WebControl
{
/// <summary>
/// This is the item a base control will use to render
/// </summary>
private Sitecore.Data.Items.Item itemToRender;

/// <summary>
/// Creates new ContentWebControl
/// </summary>
/// <param name="itemToRender">The sitecore item to render</param>
protected ContentWebControl(Sitecore.Data.Items.Item itemToRender)
{
this.itemToRender = itemToRender;
}

/// <summary>
/// Gets or sets Sitcore item to render
/// </summary>
public Sitecore.Data.Items.Item ItemToRender
{
get { return this.itemToRender; }
set { this.itemToRender = value; }
}

/// <summary>
/// Gets the TemplateId this WebControl Renders
/// </summary>
public abstract Sitecore.Data.TemplateID TemplateId
{
get;
}

/// <summary>
/// Overrides this function to return itemToRender passed during constructor
/// </summary>
/// <returns>The item control needs to render</returns>
protected override Sitecore.Data.Items.Item GetItem()
{
return this.itemToRender;
}
}

/// <summary>
/// Renders rich text
/// </summary>
protected class RichText : ContentWebControl
{
/// <summary>
/// Implemented as required by abstract class
/// </summary>
/// <param name="itemToRender">The sitecore item to render</param>
public RichText(Sitecore.Data.Items.Item itemToRender) : base(itemToRender)
{
}

/// <summary>
/// Gets the template associated this control
/// </summary>
public sealed override Sitecore.Data.TemplateID TemplateId
{

}

/// <summary>
/// Render this control
/// </summary>
/// <param name="output">Current HtmlTextWriter object</param>
protected override void DoRender(HtmlTextWriter output)
{
output.Write(GetItem()["Copy"]);
}
}
}

get { return GetTemplateID("{49990698-20E5-4948-913A-4E643D4583B9}"); }

Wednesday, August 13, 2008

My strange HTML addiction

I've been officially on the job hunt now for about a month, but nothing too exciting to report. So far only one "thanks, but no thanks" and a few recruiter opportunities I've passed on. Strangely I've adopted a new method for evaluating job prospects, html of a hiring company's or its client's websites. What I've seen so far it has been fairly disappointing (of course I'm going to recommend not reviewing our html until our production launch) but I do believe so far it has been a good indicator whether to pursue an opportunity further or pass for greener pastures. The most excting opportunity I've applied for is a position on the Microsoft Exchange team (do note the xhtml strict and user interface, yummy).

Speaking of product launches we have finalized a launch date of September 9th for the new University of Idaho website. It feels good to have a final date set and a laundry list of to-do items that must be completed by then. The next few weeks until then will fly by especially with some vacation time snuck in there for good measure... crazy I am taking time off so close to a launch!

Wednesday, July 16, 2008

Out of chaos rose structure

Last week we spent time sitting down with several of the major stakeholders of the CMS project and discussed content. Some groups went better than others, but overall we made leaps and bounds of progress. As I blog, our amazing content writers and editors are busy reworking content scattered across the web and print to create copy worthy of a print publication. Perhaps not so strangely I find this very exciting.

This idea of creating highly polished copy and wrapping it in a well designed template is exactly the vision for the last 18 months has lead us towards. Currently the templates available to use for this content is limited but our design group is hard at work creating more and hopefully with continue to feed our writer's desire to create more content. My microcontrol of the CMS I once had is quickly disapearing and I can't help but want to scream "It's alive! It's alive!!! Muahahaha!" It is exciting to watch a project you were so closely involved with take a life of its own and have its ownership move to the institution.

Saturday, June 21, 2008

Corporate income tax

Most economists favor the elimination of corporate income tax, and I too find double taxation of investors troubling. Being an election year, policy is always on mind and today I was pondering the likelihood of eliminating corporate income tax. Given the popularity of certain extremely liberal filmmakers in the country (Roger I'm thinking of you) I don't really see complete elimination of the corporate incoming tax happening anytime soon. So what could possibly be a good alternative?

Recently a few friends and I were discussing an article someone had read about how several oil companies, even thought they are making money hands over fists, are investing well above and beyond their net income in research and development (R&D). I have to admit I love R&D and feel that it is one of the most important parts of capitalism benefiting humanity. What if we could capture this idea and use it to effectively eliminate corporate income tax?

My morning shower brought to mind an idea. What if we were to give tax credits to companies for R&D? If were to allow companies to invest their corporate taxes into themselves rather than waste it on the inefficiencies of government spending, how much further would we become technologically? If companies were not able to invest their corporate taxes in R&D (I doubt few would) then let the government take over and invest it for them. This simple idea would effectively eliminate corporate taxes and double taxation while increasing R&D for the entire country by 35% of the market's collective net income.

Saturday, April 26, 2008

Managing Institutional Change

Chris Cooney, our Web Communications Director, made a comment about how our CMS project isn't so much about implementing a new technology, but more about managing institutional change. The comment has been echoing in my head for a few days now and I just can't help but feel part of something so much bigger than a CMS.

As I have been chewing on that comment I can't help but try to define precisely what we are doing. My best description so far is developing a "marketing engine" to enable individual institutional groups to fortify and extend marketing of their key business strengths within their organizational units and at a institutional level without expending extraneous resources.

If you venture into the University of Idaho's website you will quickly see as you leaving the core website, branding quickly falls apart and the quality of content varies greatly between subsites. The new CMS will enable these groups to create quality content (with the assistance of professional writers) in a consistent brand across the entire site. Not only this, but since we are standardizing content it makes it trivial to develop marketing campaigns that reuse this professionally written content. The technology we have chosen to create the CMS makes developing this system almost seem trivial. The most difficult part of this system is shifting peoples paradigms away from being web developers to content managers.

I am been very lucky to work with Chris and his group on this project. It is very rewarding seeing institutional change take place before you and with out Chris's ability to catalyze change this wouldn't have happened. I can only hope that I can have an experience close to what I am getting now with my alma mater when I move to Seattle.

Tuesday, April 15, 2008

Golden Web Developer and a Box of Nails

It is always important to keep the magical term "ROI" in the back of your mind when working on projects. The web is a fantastic place that allows for standardization of work flows, 24x7 presence, and it is just damn cool.

However it isn't always the "right" solution for every business problem. One of the first steps of developing a business plan for a web app (or any business plan for that matter) is coming up with a list of all possible solutions you can think of and determining the "right" solution. The "right" solution is going to be the one that has a high ROI and minimizes risk. The formulas for determining these are all different depending on your core competencies, but let me give you a big clue... technology is not always the answer.

There will be many times when offline processes will be quicker, cheaper, and meet your requirements better. You would be surprised how often it would just be cheaper to pay some temporary help to follow some precise instructions and just brute force the problem. The best clue to when this will be the case is when you are dealing with a very specialized problem and will only need a solution for a very short period.

Now don't get me wrong, most your decent coders could whip up a hack to get the job done efficiently, but they will probably be leaving out 90% of the software development life cycle. Often these hacks are not easily maintainable, not reusable, and not well tested. So while the solution may work, the resources spent creating a software solution (your developers time supporting their hack) would cause ROI actually be lower than just hiring some cheap labor and using them as a good training tool for some up and coming employees you are eying for management (again more ROI work to be done).

The difference between a good manager and a well seasoned great manager is being able to recognize these opportunities to maximize ROI and minimize risk.

Sunday, April 6, 2008

Big project this summer

As April continues to march on, I focus on the summer. When it really come down to it I am pretty sure I won't really have much of one. At work Sitecore will be my main focus until at least July, but likely well in to October. This weekend I just found that my parents decided not to hire a contractor to build the shell of the cabin they are building this summer. Which means as soon as the ground dries out and they can get a foundation poured, I'll be spending almost all of my free time with a hammer in hand. Given the snow levels this year I'll get to put this project off until mid-June at the earliest.

On top of all of this I keep rolling around an idea for a web application I've been pondering for some time. It keeps developing further in my mind and it is getting far enough I should probably start developing a functional specification. If I do get that started it'll be a fun project requiring the consumption of many bottles of wine.

 


You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser