Sunday, March 08, 2009

Considering Windows Azure (TechDays presentation)

Here’s the first of the two breakout presentations I did at Microsoft TechDays here in Helsinki on the 5th and 6th of March 2009. This presentation was about Windows Azure, and what we at eCraft have learned from considering porting several applications to it. This was not a particularly technical session, I focused on the slightly more philosophical side, by looking at Azure and Cloud applications from a bit of a business perspective as well as an architectural one. I’ll try to put together a post or two later on about a couple of the specifics in the presentation, perhaps on how I see the business impact of the whole thing possibly playing out.

You can also find the presentation on Slideshare.net here.

Wednesday, November 12, 2008

Windows Azure: How I deployed an existing Silverlight application in 30 minutes

image Almost two weeks ago I posted about my first experiment with Amazon EC2, and how I was able to get an existing application (our Sproodle SaaS offering) up and running on EC2 in a couple of hours. That was the same day as Microsoft announced Windows Azure, and of course I wanted to try the same application to run on Azure as well. Two days later I finally got my Azure account, and to my delight I was able to get our application up and running on Azure in about 30 minutes. Which in my mind seriously rocked. In this post I will explain the steps I went through to deploy an existing application to Azure, and talk a bit about how Azure compares to EC2.

Oh, and I’m pretty sure this was the first real (real as in real application, not a Hello World sample) Windows Azure deployment from Finland (on the 29th of October) :).

Deploying an existing application to EC2

There are a bunch of Hello World-examples for how to create a small app and deploy it to Azure, but when I first did this deployment I couldn’t find a sample that showed how to take an existing application and deploy it. However, the mechanism behind deploying to Azure is pretty simple, and essentially what you need is a deployment project. In Visual Studio you can’t add just the deployment project to an existing solution, you always get a new web application as well. This may not seem that useful at first glance, but it’s actually not that hard to change it to deploy whatever project you want. Below you can find out how. I’m using a sample app for this article, since the project I actually used when I did this at PDC is a pretty large and complex beast.

Step 1. In your existing Silverlight application solution, add a new Cloud Service project

image

My sample application solution contains two projects. The first is the Silverlight application, which in this case just writes “I like clouds! on a blue background. The other project is a web application that shows the Silverlight app. No changes has been made to this project, it’s just straight out of the box.

Now, to add cloud goodness we have to cheat a bit. Currently (as far as I know) Visual Studio won’t let you add a Cloud Service project (which is needed for deploying to Azure) and have that deploy an existing web application. It always wants to create a new application for you. So what you can do is to add a new “Web Cloud Service” to your solution. Let’s call it “CloudService”.

 

 

 

Step 2. Get rid of the generated WebRole-project

imageWhen you add a new “Web Cloud Service”-project Visual Studio actually creates two projects for you. One is the deployment project (“CloudService” in this example), and the other is a web application (“CloudService_WebRole”). As far as I can tell the second one is just a regular web application.

The deployment project is set up to deploy the CloudService_WebRole-project, and I haven’t found a way to change which project it tries to deploy through the Visual Studio UI. So we need to wire it up to deploy our existing  “SilverlightCloudApplication.Web” instead.

 

 

 

Step 3. Use notepad to edit the project file.

This is the scary part. If you’ve poked around in the Visual Studio project files before you know that they are just XML files, and note even very complex ones at that. It turned out that all we need to do in order to make “CloudService” deploy any web project we want is just change which project its deployment point refer to.

So what we first need to figure out is the ID for our “SilverlightCloudApplication.Web”-project. First close Visual Studio. Then open the file “SilverlightCloudApplication.Web.csproj” in notepad (or your favorite text editor). Look for an XML element called “ProjectGuid”, and copy the contents of that element. In my sample project here it was “{61CADBB5-24ED-4F11-848B-7754877F7A06}”, but it will be something different for you project.

Next open the project file for the “CloudService”-project. Look for an XML element called “ItemGroup”, and another called “ProjectReference” below that. You need to edit three things in there. First, change the “Include”-attribute of the “ProjectReference”-element to be the path to the project of the web application you want to deploy. Next, change the contents of the “Name”-element to be the name of your web application. And finally, change the contents of the “Project”-element to be the guid you copied from the web application project file earlier.

Below you can see a screenshot that gives you an idea of what the results of your edits should look like.

image

image Save the file, and restart Visual Studio. When you open the solution you will see that the CloudService now refers to your web application (in this case “SilverlightCloudApplication.Web"). At this point you can safely delete the “CloudService_WebRole”-project, as it is no longer needed.

 

Now you should be able to build and publish your application to Azure. Happy cloud computing.

 

 

 

Comparing Azure to Amazon EC2

A lot of people have asked me which is better, Azure or Amazon EC2? First I want to point out that this is a bit of an apples to oranges-comparison. Sure, they both are part of that fuzzy bag of stuff called “cloud services”, but from a (service) perspective they are quite different. What Amazon does is give you virtual servers that you can use to run whatever you want on, and what Azure does is give you the ability to deploy web applications to the cloud. The difference is primarily that with Amazon you still have to operate and maintain the environment your application runs in, and with Azure Microsoft is taking care of all of that for you. And they seem to do it in a very impressive way. Their environment even takes care of staging for you, so that you can test your new deployment before you switch out the currently live one.

So which one do I prefer? I really like Windows Azure. I also like Amazon EC2. I think there’s room for them both. Currently I think Azure is the better choice if what you want to do is run a web application in the cloud. Most software developers do not want to have to operate the environment, for many reasons (cost being one of the most popular ones).

If you need full control over the environment your application runs in, you probably cant use Azure (at least not in its current state). For example, I have to admit that I ended up cheating a bit when I deployed Sproodle to Azure. Because it has a database and a bunch of WCF services on top of that database I couldn’t deploy those to Azure, since it doesn’t supply you with a SQL Server. I would have had to re-architect the services so that they can run in Azure on top of SQL Services (which is a completely different animal from SQL Server). My kung fu may be strong, but not strong enough to do that in half an hour. :) So what I did was keep the services in the EC2-environment I’d set up a couple of days earlier, and set up my Silverlight app to call them from there instead. So I ended up being double-clouded, the front end running on Azure and the back-end on EC2. Not ideal, but hey, it worked! :)

Monday, November 10, 2008

SqlCE and Entity Framework maybe broken on x64

I’ve been running on a 64 bit version of Windows for the first time the past week, and while most things have worked fine I had one problem that I had a hard time figuring out. An existing project, that worked fine before the upgrade, refused to compile. I also upgraded it to SP1 of Visual Studio 2008, so there were two possible sources for problems.

In my project I have a local SQL Compact (CE) 3.5 database

I’m using the Entity Framework in my application.

The application compiled fine, but when I tried to to run it I got the following error:

"The specified store provider cannot be found in the configuration, or is not valid."

I first thought this was related to my newly installed Vista and to moving to Visual Studio 2008 SP1. But then I stumbled across the following article, where someone else was having the same problem:

http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3422883&SiteID=1

While the post seemed to be dealing with the beta bits of SP1, it seems what it boils down to is that the provider for SQL CE is broken (missing) on x64. So what I need to do is to compile for x86 (32 bits) instead. “Runs natively in the 64-bit environment”, indeed! (borrowed from the SQL CE product page at microsoft.com)

Most of you probably know how to change this, but in case you don’t I’m including the instructions here. So in order to compile for x86 specifically (instead of “Any CPU” which is the default) you need to add a new configuration for that. The easiest way is to click on the dropdown in the VS menu:

image

and choose “Configuration Manager…”. In the next dialog click the dropdown in the Platform-column.

image

In the popup you can create a new platform (choose x86). That should be it.

Saturday, November 08, 2008

Going to TechEd EMEA 2008

Tomorrow I’m flying to Barcelona to take part in TechEd EMEA 2008 for some more technical insights and some networking. I just barely got my PDC-luggage emptied and did the laundry and almost got rid of the jetlag, so I can’t really say I’m too excited about the travelling part of this trip. But TechEd is always fun and interesting, so in the end I’m happy I’m going. Barcelona is a great city, and I’m happy to get some more sun before the Finnish winter sets in properly (ok, as properly as it does in Helsinki).

I’ve got a couple of blog posts brewing that I hope to get done during the week, and of course I’ll try to post about any new and interesting stuff I come across.

Curiosity killed the cat’s computer

image Ok, so installing the pre beta-version of Windows 7 that we got at PDC on my work computer maybe wasn’t the brightest idea ever. There were simply too many things that were half-baked, and prevented me from using the machine. From the past tense used in this paragraph you’ve probably by now deduced that I went back to Vista.

At least the following things happened during my brush with pre-beta Windows 7:

  • Random BSD:s
  • Hanging when resuming from standby or hibernation
  • Windows Explorer crashing every now and then
  • For the first time ever, a crash (ending in a bluescreen) that made it impossible to recover a Powerpoint document I was working on
  • Problems installing applications
  • Files becoming broken when copied over my home network (or copies failing for no obvious reason)

I’m not 100% sure all of these were just Windows 7-related, but the evidence is compelling.

Now, this doesn’t mean that I don’t like Windows 7. I do, and I can’t wait to get to use it.There were a lot of nice things in there. The improved Windows Explorer, for one (especially the library-feature). The presentation mode selector. The window docking. Better configuration experience (although there’s way too many icons in the Control Panel now that they’ve been relocated there). The non-polluted icon tray. Better network configuration tools. It improves the computing experience in several small ways, just like Vista did over XP.

Anyway, one should never give up, so I’ll be back when they release the first proper beta version of Windows 7. Which should be around Christmas this year.

Tuesday, November 04, 2008

First post from Windows 7

My Vista had gotten a serious case of bitrot, and since I got pretty hyped up at PDC 2008 I decided to take the plunge and install Windows 7 instead (the pre-beta build that was handed out at PDC).

I have to say that based on my first impressions everything seems to have gone smoothly. I haven’t installed all my applications yet, but everything I’ve tried so far seems to work. The computer in question is my HP 2701p Tablet PC, and I’ve not even had any driver trouble yet (despite this being an HP). When something goes wrong I’ll blog about it…

Thursday, October 30, 2008

My cloud experience during the Ray Ozzie PDC Keynote

image A lot of people have already blogged about the keynote and commented on the applications shown, so I won’t go into that, apart from saying that I really believe in the model, but I wish they’d found better examples to illustrate it. However, the technology looks fantastic and I’m a big believer in cloud computing. But that’s not the topic of this post. I’ll post more about that later.

Anyway, I was having my own pretty good cloud experience during the keynote, but not on Microsoft Azure. For a while now we’ve been trying to figure out how we want to host our new Sproodle SaaS offering. We’ve been looking into different options ranging from hosting it ourselves (not a good idea) to hosting it as an application somewhere (now we’re getting into Azure-territory, but more on that in another post). One option we’ve explored is using one of several hosting companies that offer you virtual machines in their own hardware, thus saving you from having to invest in that yourself. One such company is Amazon, with their Elastic Compute Cloud (EC2) service. They recently started offering Windows-based virtual machines, which certainly is very interesting.

Amazon Web ServicesOn Sunday we decided we’d try to deploy our Sproodle product into EC2. We were all fired up and ready to go, but unfortunately our plan was foiled because the hotel bar didn’t have a wireless network. It’s kind of hard to put something up in the cloud without a network connection…

So, on Monday, before and during the Ray Ozzie keynote, I set up an EC2 account, created a Windows Server 2003 virtual machine with SQL Server, and deployed our application to it. Creating this machine in the cloud and getting our software up and running on it took 2,5 hours. Getting the Windows Server 2003 virtual box up and running took about 30 minutes. The reason deploying the software took 2 hours had more to do with having to mess around with some nasty config file insanity than with Amazon. Although having to copy files over a remote desktop connection is not exactly the fastest thing in the world. I should have set up some other deployment method, but since this was more of a trial than a real world deployment I decided not to bother with it.

To summarize I think it’s pretty cool to be able to set up a hosted virtual machine complete with our application in less than three hours. EC2 is a pretty cool service, very much oriented around pay-as-you-go (they charge for how long you have your machine running and for how much data you transfer).

Later you’ll find out how long it took us to deploy Sproodle on Microsoft Azure. Yes, we did it already :).

Sunday, October 19, 2008

Silverlight navigation patterns – what do users expect?

image During my presentation at Microsoft DevDay a few days ago I promised to share the code I was showing there. Here’s the first set, with more to follow (maybe in a few days, depending on my schedule).

During the presentation I was talking about how users do not care about what technology was used for making the application (obviously), and instead they just expect the application to behave like other similar or related applications. So, to a user, a Silverlight application is just like any other web application because they use a browser to access it. If the technology itself has certain limitations that is of no interest to the user.

Because Silverlight is heavily sandboxed you can only get access to some of the things going on in the browser, and the back- and forward-buttons (and history management) is not among those. Still, being able to use the back- and forward-buttons is something users expect to be able to do. There’s different ways to solve this, but many of them end up being either browser-specific in one way or the other. However, a month or so ago I came across a post by Jordan Knight that shows an implementation based on features introduced in ASP.NET as part of .NET 3.5 SP1. The code I showed in my presentation was more or less directly influenced/copied from his approach, so all the credit for this approach belongs to him.

image For the DevDay-presentation I made a simple sample application, pictured on the right. There are three buttons, with which the user moves to different parts (modules) of the application.

When the user presses one of the navigation buttons the new position gets added to the browser history.When the user clicks the forward- or back-buttons (or uses the browser history to select a previous position) the application is notified of this and shows the appropriate module.

So how does this work? For a full explanation I really recommend that you read Jordan Knight’s original post, as the sample I made doesn’t really add anything new to it and his explanation is very detailed and easy to follow.

The principle behind the technique Jordan describes is that a bit of JScript is used as glue between the browser and the Silverlight application, and this enables the Silverlight to react to history-related events in the browser.

text_binary

Download the code here.

 

The interesting parts are in the following files:

  • SilverlightBrowserNavigationTestPage.aspx
    Here the History.js is loaded, and the OnPluginLoaded-event on the Silverlight plugin is wired up to an event handler in History.js.
  • HistoryManager.cs
    Used for interfacing between JScript (History.js) and the rest of the Silverlight application.
  • App.xaml.cs
    Here the HistoryManager is instantiated, and a new property is introduced (History) to expose it to the rest of the application.
  • Page.xaml.cs
    Events fired by the HistoryManager when the user uses Back/Forward are handled here, and the appropriate module is shown.

Enjoy the sample.

Saturday, October 18, 2008

Silverlight Experiences at Microsoft WebDay

I gave a presentation on Thursday (the 16th of October) at Microsoft WebDay here in Helsinki. The presentation was about what we've learned while developing our new product Sproodle using Microsoft Silverlight. The focus was not so much on the technical details but on what kind of experiences we've had with the technology and what we've learned from using it.

The recording from the presentation (in Finnish) will be up on Codezone in a few days or so, but if you just want to have a look at the slides you can find them below.

I think the presentation went well, based on the feedback I got (hey, it was even called "epic" in a comment on this blog).

During the presentation I promised to post (at least some of) the samples I showed, and I'll try to get them up during the weekend.

Anyway, here are the slides:

 

View SlideShare presentation or Upload your own. (tags: microsoft silverlight)

I noticed that Slideshare butchered a couple of the slides a bit (fontsizes and such), but it's close enough.

Monday, June 02, 2008

Using the Google Chart API in a WPF application

If you haven't had a look at the Google Chart API I definitely recommend you do so. It can be a good, light alternative to investing in a more complete charting package. And honestly, most of the extra stuff offered by the 3rd party charting components out there is just eye candy that detracts from the information you chart should communicate.

So, with the Google Chart API you can easily put charts like this in your web application or page:

All you need to do is put an img on your page, and set it's src to a url that contains some Google Chart magic. The url for the chart above looks like this:

Granted, the query arguments are quite complex. But Google has some nice documentation for it, and in the end it's not so bad. Here's a simple example:

The url for this puppy is:

The way you talk to Google Chart is through a series of parameters, separated with an ampersand (&). The url above contains three parameters, as follows:

cht=lc Set the chart type to line chart.
chs=150x100 Set the size of the chart to a width of 150 and a height of 100.
chd=t:10,70,50,40,80,5,25,95 The data points for the chart, as comma-separated values.

So, as you can see, pretty simple stuff.

But what about using this in desktop applications, and WPF applications in particular? Since all Google Chart does is generates an image based on parameters you pass to it in the URL, it can be used in XAML through the Image control. Like this:

<Image Width="150" Height="100" Source="http://chart.apis.google.com/chart?cht=lc&amp;chs=150x100&amp;chd=t:10,70,50,40,80,5,25,95"/>

Note that the ampersands (&) had to be encoded as "&amp;" in the XAML.

Here's a screenshot of the XAML above being used in a little application:

image

Ok, so that works nicely. But dealing with the url, and in particular passing the data point for the chart to the API that way is a little bit ugly, and certainly feels very crude compared to how you usually do things in WPF. So what can be done to improve this? One thing that comes to mind is using a value converter to convert a list of values to the url-format that Google Chart wants. Here's an example of that:

[ValueConversion(typeof(IList), typeof(string))]
    public class ListToTextEncodingConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            IList valueList = (IList)value;
            string baseUrl = (string)parameter;
            if (valueList == null || baseUrl == null)
                return string.Empty;
 
            string valueString = "";
            CultureInfo usCulture = new CultureInfo("en-us");
 
            foreach (object item in valueList)
            {
                double? val = item as double?;
                if (val.HasValue)
                {
                    if (valueString.Length > 0)
                        valueString += ",";
                    valueString += val.Value.ToString(usCulture.NumberFormat);
                }
            }
 
            return baseUrl + "&chd=t:" + valueString;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Binding.DoNothing;
        }
    }

It accepts something that implements IList, and tries to find doubles in it, and constructs the url string from that. In addition it accepts the rest of the parameters for Google Chart as a parameter.

And here's a snippet of XAML that uses that value converter to display a chart:

<Window x:Class="WpfSample.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfSample"
    xmlns:converters="clr-namespace:WpfSample.ValueConverters.ChartDataEncodingConverters"
    Title="Window1" Height="300" Width="300">
    <Window.Resources>
        <local:SampleData x:Key="SampleData"/>
        <converters:ListToTextEncodingConverter x:Key="ListToTextEncodingConverter"/>
    </Window.Resources>
    <Grid>
        <Image Width="250" Height="150"
               Source="{Binding Source={StaticResource SampleData}, 
                                Converter={StaticResource ListToTextEncodingConverter},
                                ConverterParameter='http://chart.apis.google.com/chart?cht=lc&amp;chs=250x150&amp;chds=0,30'}"/>
    </Grid>
</Window>

Oh, and please not that the ConverterParameter seems to screw up the WPF designer in Visual Studio 2008, I haven't looked into whether anything can be done about that. But it compiles and runs fine.

SampleData is just a set of values, you could of course use whatever you want for your data source, perhaps pull something from a database and use Linq to project it into a list of double values. Here's the class that creates the sample data:

public class SampleData : List<double>
{
    public SampleData()
    {
        Add(10);
        Add(20);
        Add(15.2);
        Add(12);
        Add(21);
        Add(17);
        Add(11);
        Add(8);
        Add(12);
        Add(18);
    }
}

Here's what the application looks like:

image

Simple, but I guess you get the idea.

And finally, is it bad to use a web-based API for charting in a desktop application? Not really, in my opinion. Most desktop apps need to talk to servers anyway, and grabbing a few charts over the web is not going to be a significant performance issue.

Oh, one more thing. Of course this works great in Silverlight 2.0 as well.