Sitecore Azure: “To The Cloud” Series

For those that follow my blog closely, you probably noticed that frequency of my posts has slightly decreased. Despite the workload, Azure has been a hot topic and has been bugging me for attention for quite a bit now.

I don’t think my workload will free up anytime soon, but I’m going to commit to another Sitecore series of blogs called Sitecore Azure: To The Cloud. It might take some extra spare time, but I plan on documenting everything in detail in multiple posts, even if it takes a while.

Without further ado, the first step is going to be getting an account. You can get a trial account at http://windowsazurepass.com with this promotion code – TBBLIF . If you are reading this after the code expires, try searching for another one unless the program has been discontinued, at which point you will have to provide a credit card.

Account activation will take 2-3 business days. I’ve just submitted mine. We’ll see what happens…

[UPDATE] Found my account activated this morning.  Stay tuned…

Sitecore’s CustomCache – A simple implementation

Sitecore comes stocked with a custom caching mechanism in its Sitecore.Caching namespace. Unfortunately, there is not much documentation on it, but this post will hopefully shed some light on this mysterious, yet useful object known as CustomCache.

To implement, you will need 3 things:

  1. Your own CustomCache class
  2. A CacheManager class
  3. The code that will be using the cache

Your own Custom Cache class

Because Sitecore.Caching.CustomCache is an abstract class, you cannot directly instantiate it, but you can inherit from it.

namespace Sitecore.Custom
{
    public class MyCustomCache : Caching.CustomCache
    {
        public MyCustomCache(string name, long maxSize) : base(name, maxSize)
        {

        }

        new public void SetString(string key, string value)
        {
            base.SetString(key, value);
        }

        new public string GetString(string key)
        {
            return base.GetString(key);
        }
    }
}

Cache Manager

You will need a static Cache Manager to “manage” your CustomCache. This manager will instantiate the CustomCache object in the constructor. This is where you will give it the name and the size – both of which will show up in under /sitecore/admin/cache.aspx which you will be able to clear.

namespace Sitecore.Custom
{
    public static class CacheManager
    {
        private static readonly MyCustomCache Cache;

        static CacheManager()
        {
            Cache = new MyCustomCache("MyCustomCache",
                     StringUtil.ParseSizeString("10KB"));
        }

        public static string GetCache(string key)
        {
            return Cache.GetString(key);
        }

        public static void SetCache(string key,string value)
        {
            Cache.SetString(key, value);
        }
    }
}

Your code that calls it

You can use the code below to set and get your cached values.

CacheManager.SetCache("myData","myDataValue");
string myData = CacheManager.GetCache("myData");

So why use this as opposed to the .NET cache out of the box? For me, it’s the simple convenience of having it clear anytime I do a Sitecore publish operation.

That’s all there is to it.

Inside Look at a Real World Web Project – Planning, Strategy, Design, and Implementation

My team and I just deployed a high-profile, albeit small website for one of our brands. This article will give you an inside look at each step of this real world project, which you may not necessarily be able to find in a WROX publishing book. I will cover the project framework, overall design strategy, and working with Sitecore. In a cross-post, one of my teammates, @kaidez [http://www.kaidez.com], go into the detail of front-end code and some of the invaluable tools that simplified the general development of this project.

Project Framework

For our framework, we chose SCRUM. In a 4-person web team, all sitting within reach of each other, we have found that over the years, this works best for us. The designers know what the developers are doing and vice versa. Like SCRUM, we are fast and efficient. In fact, I am very proud of my team. As a 4-person standalone web design shop, I think we’d do rather well, assuming we wouldn’t have to pay for our own healthcare.

In the role of ScrumMaster, the first thing I did was set up a storyboard in scrumy.com (pronounced scruh-mee, not screw-me, which is a completely different NSFW site). If you haven’t used this tool before, give it a try. Its drag-and-drop interface lets you create stories, associate tasks with a user, and drag-and-drop them from column to column (to-do, in progress, verify, complete). Maintaining a storyboard like this, not only puts your project manager at ease, who may be in a remote location, but also keeps the team sane when you need to get out of the coding zone and get a perspective on the project progress.

Design Strategy

If you only get one takeaway from this, it’s that no matter how small the project, proper design and planning will always serve a benefit.

Since we adopted Sitecore as the official CMS tool, our design was already partially established. With this being a small product informational site, our Sitecore template design was not unlike the Sitecore demo project. The difference between our solution and the demo project is the level of OOP design.

What I have seen with novice Sitecore developers is as soon as they start developing a site, they completely abandon n-tier architecture and OOP best practices. Sitecore does not and should not replace a good OOP design.

Take the Product entity as an example. A Product may have a name, image, link, and a description. In a 3-tier (DAL/BLL/UI) architecture, you would create a class for it in the Business Logic Layer. In our case, we display products in a category page and in a product page. If you care about your code, there should be an alarm that goes off that detects duplicate functionality and tells you to extract it to one common place; hence, the need for our BLL assembly.

If you are still not seeing the benefit, consider the readability and general elegance of binding an asp:repeater to a List of products with dot notation and intellisense, as opposed the ugly DataBinder.Eval() function.

<asp:Repeater ID="rptProducts" runat="server">
	<ItemTemplate>
		<a href="<%#((Product)Container.DataItem).Link)" %>
			<%#((Product)Container.DataItem).Image) %><br/>
			<%#((Product)Container.DataItem).Name) %>
		</a>
	</ItemTemplate>
</asp:Repeater>

As another best practice, you will want a Core assembly to keep track of static constants and variables. In our case, it holds the URL to our CDN which is different from environment to environment.

Team Development Environment

After the design is knocked out, I have to make sure everyone’s development environment is properly set up and wired up to TFS. I’ve seen developers skip this step until the project is complete, but I cannot stress this enough – these shortcuts will only make your life more difficult. Set up TFS before you start development and don’t forget to check in changes to avoid having other developers overwrite your changes or hearing the never-old “well… it works on my machine” phrase.

The Sitecore templates were done during the design phase in a true Agile environment – in a locked conference room with the entire team, so at this point, it was safe for everyone’s environment to be pointed at the same Sitecore database environment since the templates weren’t really changing.  I created the solution with by including the Sitecore files and assemblies, created BLL/Core projects, and checked everything into TFS, after which everyone did a GLV (get latest version).

Sitecore Deployment

We build this site using Sitecore v6.4. With this version, there is no staging module that you have install like with v6.1, so I thought that after I take care of the checklist in Sitecore’s Configuring Production Environments handbook, I’d be home free, but not so. If you want the cache to automagically clear after publish, you will have to set the EnableEventQueues property to “true” in your web.config

Takeaways

A little planning and preparation before will save you a lot of fan cleaning later. No matter how small the project, if you are in a real world environment, chances are it will at some point grow or will probably need maintenance. Following best practices in the beginning, you will avoid cursing yourself and/or your team when it’s time to do that maintenance or expansion.

  • Remember to use a project framework that will fit your team and organization, whether it’s SCRUM or something else. If it’s something else, you will still find scrumy.com to be useful for simple task management.
  • Use TFS, or something else if you don’t have TFS, for source control early on before development kicks off.
  • Do not disregard a good n-tier design just because you are working in a CMS.

Check out @kaidez’s cross-blog on this topic here: www.kaidez.com.

The Power of LINQ – Sorting Lists with a single line of code

This post, just like the code example, is short and to the point, because that’s how LINQ is – short, to the point, and powerful.

Let’s say you have an object called Country.  There will be a List<> populated with it that is going to be used in a drop-down box.  It has the following properties:

  • CountryName (string)
  • DropDownValue (string)
  • SortOrder (int)

The business logic for the list is to order it by SortOrder, and then by CountryName.  You ready for the code?

var destinationList = sourceList.OrderBy(c => c.SortOrder).ThenBy(c=> c.CountryName).ToList();

That’s it. You should note that the difference between OrderBy() and Sort() is that Sort() will actually resort the list you are running it on. OrderBy() on the other hand just returns the result set, but doesn’t actually commit the order to the list; hence, the ToList() assignment to destinationList.

Liveblog from Microsoft Mix 11 – Keynote

[10:29] New in Windows Azure – Access Control Service, Caching, CDN, Traffic Manager.
We saw Facebook & Twitter icons around ACS. Hopefully, it wasn’t just clipart and they are supported.

[10:26] Umbraco CMS demo. Another .NET based open source project. The twist – running on Windows Azure cloud. Currently used by mainstream sites like vogue.co.uk.
Allows you to scale the instances and looks like it gives you a lot of control on the cloud.

[10:12] Orchard CMS Demo. Open Source project that Microsoft is contributing to.  It’s no Sitecore, but still worth taking a look at.

[10:10] WebMatrix helpers

[9:58] Microsoft WebMatrix Demo. It’s your basic website in a box. TemplateMonster sells WebMatrix templates. You set up your site by choosing the packages you want. Packages are like WordPress plugins.

[9:51] Looking at a demo with MVC3.  Awesome integration with HTML5.  Didn’t see the need during MVC v1 or v2, but this may be worth taking a look at.

[9:45] ASP.NET MVC3 Tools Update

[9:43] Scott Gurthrie. Starting off with a bang?? Charlie Sheen #WINNING/tigerblood joke. really? Talking about the Microsoft Web Platform

[9:41]IE10 Recap Slide

[9:39] Looking at SVG canvas video performance on IE10 vs. Chrome. IE10 does it faster.

[9:37] Microsoft PDC announced – Anaheim, CA – Sep 13-16, 2011.

[9:31] CSS3 columns, “Strict”, CSS gradients – all looks great on IE10.  What happened to IE9? More markup needed to do the same on Chrome than IE10, even though Chrome can do it.

[9:27] Looking at IE10 demo.  I need to call my QA team ASAP and get them to start cross-browser testing.  Another jab at Chrome not being able to support video hardware acceleration.

[9:26] It’s not about how many releases there are. It’s about how much progress is made.

[9:23] Wow. Xtranormal animation mocking Chrome and Websockets. Yes. This is really happening.

[9:21] Native experiences are better.  IE9 delivers that. Browsers that optimize for the operating system are better. IE9 with Windows 7 is better.  Browsers that spread themselves over multiple OS’s can’t concentrate on optimization (really? This guy is telling Chrome to go eff itself)

[9:18] IE9 vs. Chrome – IE9 has hardware graphics acceleration.  Painball demo is much faster.

[9:13] Looking at some great HTML5 sites.

[9:07]  Dean Hachamovitch, Corporate VP, Internet Explorer. Fan and Evangelist of HTML5.

  • Native Experiences – best experiences
  • Web experiences – most important experiences.
  • Best web experience – IE9 with HTML5