I penned my previous post on nopCommerce for Azure around 1 AM one morning, having just spent the last few hours playing with the code and deploying to Azure. In my sleepy stupor, I left off a few details about how it’s implemented and the changes required. So I thought I’d post a few more of the gory details for those interested. A zipped version of the nopCommerce 1.30 code, including the slightly altered Azure projects, is available here. You’ll need Windows Azure Tools and Windows Azure SDK installed on your PC, a Windows Azure CTP account, and a SQL Azure account (register and download here). To use, simply follow the steps below to set up your database, and then change ConnectionStrings.config to use the connection string to your database. You should then be able to run locally (choose AzureNopCommerceStore as the startup project) against the SQL Azure database. Once you’re happy with that, rt click AzureNopCommerceStore and choose publish to publish the project to Azure.
I used the SQL Azure Migration Wizard, but had to address some minor discrepencies between SQL 2008 and SQL Azure manually. One procedure, [dbo].[Nop_Maintenance_ReindexTables], contains code that cannot be modified to run on SQL Azure, so that functionality won’t work. A fixed up script is in the App_Data folder of the AzureNopCommerce_WebRole project. Simply run that script against your SQL Azure database and then copy data from a live database, or run the sample data script also included in that folder. Tip: Sql Management Studio will give you some errors, but if you follow these steps exactly, you can get a query window connected to SQL Azure to run these scripts.
The code for the most part worked as-is, except that any part that tries to write to disk will throw a FileIOPermissions exception. The main place I found this was happening was the image generation code in GetPictureUrl method inside PictureManager. This I changed to ‘hard code’ a path to a page that will be responsible for dynamically serving up the image, GenPicture.aspx (see the last line):
An overload for GetDefaultPictureUrl also had to be modified to, for now, not do any resizing.
GenPicture.aspx then reuses some of PictureManager’s logic to generate the image on the fly and render it to the client. To be clear, this of course is terribly inefficient and is just a proof-of-concept hack. If you use this in production, you’ll be laughed at and maybe worse. The better solution would be to change PictureManager to use a provider model. A FileSystemPictureProvider could then handle pictures for traditional web apps, while an AzurePictureProvider could use Azure Blob storage. But for demo purposes, this was the fastest route to a solution. All markup, except the @Page declaration is removed from the aspx, and the full listing for GenPicture.aspx.cs is here:
That is all the code changes that were required, I believe. As I said before, Azure is really not as scary as it sounds – for all the hype, you can really think of it as really cool hosting for .NET (and PHP) apps. With some notable exceptions, most code will ‘just work’ on Azure. Because of the well thought out separation of concerns in nopCommerce, it should be possible to migrate much of the functionality to Azure Table Storage, which is cheaper than SQL Azure, and unlimited in storage size. I may play with that in the days to come, but for now, hopefully this will wet people’s appetite for what’s possible on Azure.