Windows Azure Guest Book – Refactored

 

Due to the namespace change of the Windows Azure SDK, a number of the Windows Azure Platform Training Kit projects were broken.  As a part of the Guelph Coffee and Code Windows Azure Technology Focus Panel, I have refactored this Project in order to launch it into the cloud as one of my Azure Deployments.  If you haven’t already, you may want to visit my previous blog post entitled Moving from the ‘ServiceHosting’ to ‘WindowsAzure’ Namespace.  In the previous post I reviewed some of the changes in the classes that were contained in the Windows.ServiceHosting.ServiceRuntime namespace.

Another change in the Azure SDK is in the RoleEntryPoint Class.  The Start method which originally had a void return type has been changed to OnStart and returns a boolean value.  A method called GetHealthStatus() which returned a RoleStatus enum value, was removed.

I am still looking for an alternative to one of the most useful debugging features of Windows Azure to date. RoleManager.WriteToLog() was not replaced in the RoleEnvironment class.  This was one of the only gateways into writing out some error information without the use of the Storage Services or a SQL Azure database.

All of the mentioned Changes to the SDK were the issues behind the Windows Azure Guest Book not functioning from the November Platform Training Kit. You can go and make these changes yourself if you would like, or you can download the refactored version.

Happy Coding!

Moving from the ‘ServiceHosting’ to ‘WindowsAzure’ Namespace

 

Being part of a Technology Focus Panel for Windows Azure was quite a rewarding experience for me. I rarely get to work with emerging technology, which is one of the main reasons why I started Guelph Coffee and Code.  We’re getting down to the wire of launching 20 applications up to the cloud, and I’ve been putting in some extra time ensuring that we reach our goal. I’m working on compiling an application as I write this post, but I thought I would share some of the knowledge I’ve gained while Debugging the ‘Windows Azure Guest Book using Tables’ application found in the November 2009 CTP Platform Kit part of the Windows Azure Get Started steps.

The solution has a reference to the Microsoft.ServiceHosting.ServiceRuntime namespace that has recently changed its name after the Microsoft PDC Conference. If you are having a hard time compiling some of the projects it will most likely have something to do with the name change. Please note that the Microsoft.ServiceHosting.ServiceRuntime has been changed to Microsoft.WindowsAzure.ServiceRuntime which is more suiting as the platform is called Windows Azure. Not only has the namespace been changed but there are a number of Classes that have been refactored as well.

The RoleManager class has been changed to RoleEnvironment along with some of the members of the class. Let’s take a look at them in Context.

RoleManager: [Note: These are Snippets from the StorageClient Project, File: StorageAccountInfo.cs]

 // settings in the csc file overload settings in Web.config
            if (RoleManager.IsRoleManagerRunning)
            {
                string cscRet = TryGetConfigurationSetting(configurationSetting);
                if (!string.IsNullOrEmpty(cscRet))
                {
                    ret = cscRet;
                }

 

RoleEnvironment:

 // settings in the csc file overload settings in Web.config
            if (RoleEnvironment.IsAvailable)
            {
                string cscRet = TryGetConfigurationSetting(configurationSetting);
                if (!string.IsNullOrEmpty(cscRet))
                {
                    ret = cscRet;
                }

 

As you can see from the snippet above (bolded text) that RoleManager.IsRoleManagerRunning as been replaced by RoleEnvironment.IsAvailable.

Another change was found when accessing the Role configuration file.  The method RoleManager.GetConfigurationSetting was replaced by RoleEnvironment.GetConfigurationSettingValue.

RoleManager:

 private static string TryGetConfigurationSetting(string configName)
        {
            string ret = null;
            try
            {
                ret = RoleManager.GetConfigurationSetting(configName);
            }
            catch (RoleManagerException)
            {
                return null;
            }
            return ret;
        }

 

RoleEnvironment:

 private static string TryGetConfigurationSetting(string configName)
        {
            string ret = null;
            try
            {
                ret = RoleEnvironment.GetConfigurationSettingValue(configName);
            }
            catch (RoleEnvironmentException)
            {
                return null;
            }
            return ret;
        }

 

Another thing to note from the snippets above is the RoleManagerException has been changed to RoleEnvironmentException, which shouldn’t come as too big of a surprise.

In order to find these code changes I used the RedGate .NET Reflector Tool, and compared the library Microsoft.ServiceHosting.ServiceRuntime.dll for similarities to the library Microsoft.WindowsAzure.ServiceRuntime.dll.