So one thing I’ve been wanting to do since moving from the Windows Azure team to the Pivot team, is build a Pivot Dynamic Server in Windows Azure.
Well, tonight I decided to do just that, allow me to expatiate! ;0
Let’s start with a basic overview of what Pivot requires to load a collection.
First it needs a collection file, affectionately referred to as “the cxml”. This lays out the details of your collection, things like the facet categories that provide the faceted exploration capabilities, and the details about the item in your collection. Within the cxml, there is a reference to another file, known as “the dzc”, or the DeepZoom Collection. This file describes all the smaller “dzi” files, or DeepZoom Images, that make up the whole collections set of images.
Now, this is all pretty high level, and to get a real sense of what this all means, a little time spent reading through our site is time well spent. For those that have, and are simply asking the question, “How do I create a collection on the fly, and serve it up from Windows Azure?”, then I hope this blog post satisfies.
So given the basics above, that Pivot requires a cxml that points to a dzc of dzi’s, we’re ready to move to the Windows Azure part.
So Windows Azure has some awesome capabilities, that makes it possible to build something as powerful as a Pivot Dynamic Server in no more than a night.
To start with, I set some goals.
1. Be able to serve a completely dynamic collection from Windows Azure that would load in Pivot.
2. To not use Windows Azure Storage (yet!). For my demo, I’m assuming a single web role instance, with all files being served from the role itself, old skool style. I’ll rev this sample/demo to use blobs in Windows Azure Storage in a follow up post.
3. To generate the collection from a web source, that is, use something like Flickr or Twitter as the source of my collection and transform it on the fly (I picked Flickr).
4. Auto-generate my facets. This way, there is no need for “authoring” per se, you just point and click.
Now on to the code.
I started with a standard Windows Azure web role.
I then added a Generic Handler (.ashx) to the project, to handle the requests coming from Pivot. Because Pivot expects a file that has a CXML extension and contains XML, and because goal 1 requires that we are able to handle dynamic requests, we need some way to map a virtual request like http://foo/bar.cxml?id=n to something that will return the dynamically generated cxml.
The second thing I needed to do was setup a URL rewrite rule so that all request to my web role are directed to my handler, where it can make the appropriate changes to the request.context.
Now the basics of my service are ready.
Next I need to serve up some basic cxml. To do this, I created a simple class that supports XmlSerialization that provides the basic infrastructure to create a collection. This way, I can build my collection in code, then simply return the serialized version of the collection through my handler.
OK, next I needed to populate my items. For this I simply load a public Flickr RSS URI, use a LINQ to convert the Flickr RSS format to my new collection format, preserving key information such as the href’s of the images, as we’ll need that later.
Now, onto the facets. One of the most powerful attributes of Pivot is the ability to search and discover information from your collection using facets. For my Flickr collection, the most meaningful facets are those that exist in the names of the photos I’ve uploaded, so I created a very simple keyword extractor, to build my facets.
Now finally, I need to convert the images to a set of DeepZoom Images, and all of the DeepZoom Images into a DeepZoom Collection. To this, I need to get a hold of the DeepZoomTools.dll that comes with the Deep Zoom Composer. Once I have that, I simply iterate through my collection, and build the DZI’s and DZC from the details I have about my images.
And I’m done!
Now, the last thing to discuss is the way I serve up the files that I’ve built in my Windows Azure web role, under the LocalResource. To do this, I have a simple function in my handler which says:
Voila! Give it a shot for yourself:
Simply put your FlickRss ID in place of mine, and plug the URL into Pivot like I have below, and you’re Windows Azure Dynamic Flickr Collection is served up!
Sample code is here, usual disclaimers apply in terms of lack of error handling, general crud’iness, terrible camel casing! ;)