4MK Mobile Dev Blog

Adventures in Mobile (and Startup) Development

Creating certificates on Azure

For a recent project project we were working on (Open Data Installer), there was the requirement to connect to the Azure Management API on behalf of the user in order to actually deploy the selected projects for them.  In order to do this, you need to have the user add a certificate to the management certificates for their account (Why this functionality can’t be done with OAuth and their Live account is something that I will never understand).

The decision to create the certificates on the server came up when we were discussing security around the application.  It all came down to the fact that we wanted the user to be able to use the certificate once and then throw it away knowing that we there was no way we could access their account after the install process (done by them removing it from their Management Certificates).  I guess we could have just used one certificate that they all could use, but having individual certificates used just gives that added piece of mind.

Enough of the use case, here comes the code:

From the command line, certificates are easy enough to generate, simply issue the command:

makecert.exe -r -pe -a sha1 -n \"CN=ODI Certificate\" 
-ss My -len 2048 -sp \"Microsoft Enhanced RSA and AES Cryptographic Provider\" 
-sy 24 {0}\\oidcertificate.cer"; 

Creating the same certificate on the server can be done using the ProcessStartInfo class.

Once you’ve copied makecert.exe to your instance (look for exactly how to do this in a future blog post), simply use the following code:

   1:  string command = "-r -pe -a sha1 -n \"CN=ODI Certificate\" 
-ss My -len 2048 -sp \"Microsoft Enhanced RSA and AES Cryptographic Provider\" 
-sy 24 {0}\\oidcertificate.cer"; 
   3:  ProcessStartInfo start = new ProcessStartInfo(); 
   4:  start.FileName = [Location of makecert] + "\\makecert.exe"; 
   5:  start.Arguments = string.Format(command, [Output dir] ); 
   6:  start.WorkingDirectory = [Output dir]; 
   7:  start.UseShellExecute = false; 
   8:  start.RedirectStandardOutput = true; 
   9:  start.RedirectStandardError = true; 
  10:  // Start the process with the info we specified. 
  11:  // Call WaitForExit and then the using statement will close. 
  12:  using (Process process = Process.Start(start)) 
  13:  { 
  14:      process.WaitForExit();
  16:       var output = process.StandardOutput.ReadToEnd(); 
  17:       var error = process.StandardError.ReadToEnd(); 
  18:  }

At this point you should deal with both the output and error variables to make sure that everything went well.

And that’s it, the beauty of Azure compute instances is that for the most part there is very little in terms of coding that you could do on a dedicated server, that you can’t do on Azure".

Getting started with WP7Dev

Earlier this week, I had the pleasure and privileged of being asked to be  a guest on Microsoft Canada’s Developers, Developers, Developers show talking about my experiences developing for the platform (the video of the show should be available soon).  Those who know me well can attest to the fact that I absolutely love the platform and how easy it is to develop for (Market share not withstanding), so when they asked, I jumped at the opportunity.

The topic of the conversation was around how to start developing for the platform, so I thought I’d take a quick minute to jot down my thoughts on the matter.  Without further ado, here’s my list of three steps to getting started:

1. Pick an app

This one isn’t platform specific, but rather what you should do no matter what platform your developing for.  Far too often I see people getting into mobile development with aspirations they are going to retire on the income from their first app. Inevitably they fail and stop building anything.

Start small.  Pick something that will help you out in your everyday life.  The hardest thing to do in mobile development is figuring out what exactly your users are going to want, if your the client, this part becomes much, much easier.

Personally, I drink about 6 liters of Tim Horton’s a day (just over a gallon and a half of Coffee for our American readers) and often found myself asking random strangers: “Where’s Timmy”. [Note: how this app got me a career building WP7 apps is a story for another day]

2. Read/Watch tutorials specific to what your trying to build.

While many people will shudder at this suggestion, your goal is to get your first app up and running as soon as possible.  Forget reducing how much code is in your code behind, using IoC or any of the “cool” new technologies/methodologies, figure out what you need next and build just it.  Once you’ve built the first version of your app and have that great feeling of using an app you’ve built on your own phone, you can go back and refactor that code you’d be embarrassed if anyone else saw.

In terms of where to look for tutorials, it really depends on how you learn best. For some people, video is king, and those people should check Channel 9 for your needs.  Others learn better the written, you should check the official developer site as well as Jeff Blankenburg’s fantastic series 31 Days of Mango

Above all else, just remember to get your app working and have some fun doing it!

3. Iterate

When initially looking at what features you are going to add to your application, cut out anything and everything that isn’t absolutely vital to solving your problem.

Once you’ve gotten the bare minimum version of your app up and running, you’ll often find that features that you thought you would need are no longer relevant. There will however be some new features that you hadn’t even thought of that you now realize is absolutely imperative. That is how it goes with the iteration process.

Another great help when iterating on your app is to try and find users to help beta test it with you. Twitter is a great place to find people (make sure to use the #WP7Dev hash tag), as is the Canadian Developer Connection LinkedIn group, or you can send me a message (either through this site or on Twitter) and I’ll see if I can help

Once again I’d like to thank the fine folks at Microsoft Canada!! Now get out there and build your apps.

Why Nokia coming to Windows phone is a huge deal


Canmore_ComparissonShots taken with the X7 (left), Samsung Focus (center) and the N8 (right)

A little while ago Nokia was kind enough to invite about a dozen of us out to Canmore, Alberta for an event called #NokiaUnfenced; a weekend of fun while showing off a couple of their current phones. Being a big fan of the Windows Phone platform (both as a Developer and a Consumer) I was thrilled to get the chance to see what all the excitement was around the recent decision of Nokia’s to go with the new platform.  As such this won’t be so much of a review of the software currently running on their phones, but rather a review of the hardware . Unfortunately, I wasn’t able to get my hands on a device running WP (code named Sea Ray) what I did see paints an extremely attractive picture of what’s on the horizon. If you’d like a review of the software and hardware together, a few of the other fantastic people who were on the trip have you covered here, here, and here.

History of the decision

In early February of this year, Stephen Elop, the newly appointed CEO of Nokia, send his now famous memo to employees where he likens Nokia’s then strategy to a burning platform (the full text of the memo can be seen here.).  Not long after that, Nokia announced that they would be phasing out Symbian as their OS of choice for smartphones and replacing it with Microsoft’s Windows Phone Offering.  In the landmark deal between the two behemoths, Nokia would bring an expanded range of phones, the Ovi maps technology, and their Carrier billing agreements, while MS would be bringing the OS as well as the various Bing technologies.

So without further ado, here’s why I’m excited…

Great Camera

If you’re like me then a lot of your discussions around any smartphone tend to focus on apps. What’s the latest and greatest app for a platform, how many tens of thousands of apps are available, or which twitter client is currently my favourite are popular topics to argue at length about. But if you are like me, a very large portion of your actual usage is taking and showing off pictures.

For the most part, even though I’ve had a smartphone for the last 3-4 years and I’ve never been more than about 10 feet from it. Having said this, whenever I’m going to an event, be it my son’s hockey game or out to the park with my daughter, I’ll also bring a separate camera. While testing around with the X7 (or the N8) I’ve left the standalone camera at home. Almost all smartphone cameras these days are good enough for those spur of the moment, wow nobody’s going to believe this, shots, Nokia’s camera takes it from good enough to perfect for the job.

Going from the 5 megapixels on my Samsung Focus to the 8 megapixel in the X7 (or a ridiculous 12 megapixel for the N8) doesn’t quite tell you the whole story. What seems to be the biggest improvement is the lens they are using. The Carl Ziess really delivers a crisp picture with fantastic colours that will make even the shots from sub amateur photographers (the category I find myself in) looking great.

One other quick thing to note is that the time difference between when you press the button and when the picture is actually taken (I’m sure there is a technical term for this) is much better on the X7 than on the Focus. While for landscape shots this isn’t going to mean much, for action shots it’s nice to be able to actually catch the action rather than a half second afterwards.

Mapping Features

Up until that weekend, when I thought of mobile mapping solutions, I really only thought of two different offerings, Bing maps and Google maps. While I’m not entirely sure that I’m sold on the overall visual aspects, there are quite a few things that have me extremely excited about the possibilities of Ovi Maps coming to Windows Phone. The first thing I noticed was that there were a couple of places that Bing Maps couldn’t find that Ovi could (I’m wondering if the ranch was selected based on this, j/k ). The best feature Ovi has though is the ability to download the tiles for a given region, not having to download the tiles certainly helped in regions with spotty reception.

General Hardware feel

One of the biggest features that phone manufactures like to pull out is how light they have made their phones. While greatly reducing the weight of phones more than 10 years ago (think Zach Morris era ) was a great thing, it’s my belief that it’s gotten to the point that phones have gotten too light (apply ridiculous size of cell phones in Zoolander, to the weight of phones now). By reducing the weight as far as they have and by replacing parts of the case with flimsy plastic, many manufacturers have gone too far. The Nokia phones don’t have this problem. This isn’t to say that they are heavy bricks, but rather they have a weight that just feels right. One of the other guests at #NokiaUnfenced (who will remain nameless to protect them from the enevitable PETA backlash) summed it up with the line “A phone should have enough weight so that you could kill a small animal with it). While I certainly don’t agree with killing small animals, I completely agree with the statement.

No more “This is how it should have been at launch”

Another thing that Nokia will have going for it when they finally do release their Window Phone offerings, is that they have bypassed the, at times, incomplete initial release of the WP operating system. While I understand that Microsoft had to start from scratch when building WP, I can’t help but agree to a point with the crowd of people who are vocal about saying that the upcoming Mango release has the feature set that should have launched with the phone. Nokia won’t ever have to hear these complaints as they’ll be launching with the fully featured Mango OS.

Final thoughts

All in all, I’ve got to say that going in to the weekend I really didn’t know why everyone in the Windows Phone community was so excited about the Nokia deal.  After the weekend I completely understand it.  Now don’t get me wrong, I don’t think that when Sea Ray is release your going to start seeing landfills full of iPhones and Android devices, but it’s certainly a large step in the right direction for the platform that could sorely use it.  Personally I’ll be picking one of them up as soon as I can get my hands on one.

Quick tip: Getting your JSON out of a WebException

When prototyping out a recent project, I ran into a new issue that I hadn’t seen before, a web service that sent back both a non 200 error code, but also returned relevant JSON data.

The problem happens when trying to get the JSON data about the error.  Since a non-200 Response has been returned you can no longer use the following code:

   1:  void wc_DownloadStringCompleted(object sender, 
   2:      DownloadStringCompletedEventArgs e)
   3:  {
   4:       var jsonContent = e.Result;
   5:       //Do Stuff Here
   6:  }

So the first thing you have to do is check for the Error property and deal with it appropriately.  Luckily for us the Error property has a reference to the actual Response which we can use to get the information we want like so:

   1:  void wc_DownloadStringCompleted(object sender, 
   2:      DownloadStringCompletedEventArgs e)
   3:  {
   4:      string content = string.Empty;
   6:      if (e.Error != null)
   7:      {
   8:          var we = e.Error as WebException;
   9:          var stream = we.Response.GetResponseStream();
  10:          content = new StreamReader(stream).ReadToEnd();
  11:      }
  12:      else
  13:          content = e.Result;
  15:      //Do Stuff Here
  16:  }

Of course you’ll need to do more error checking that this and make sure that the response code that you want is actually the one you are receiving, but this shows the just of what our solution was.

SysTray + Panorama: mostly still a no-go in Mango

One of the most prevalent comments that I’ve gotten whenever we’ve built a WP7 application using a Panorama, is “What happened to the time thingie?”  For those who don’t know, the time thingie is called the System Tray as shown here:


As a developer, the last thing I want to do is take functionality away from users, but in this case, if you’re using a Panorama background image, you have to.  The reason I say you have to is that the System Tray won’t overlay over any of your controls, but rather it will take up the top small amount of space at the top of your page pushing everything else down.  So here’s the XAML and what it will look like using the sample panorama project installed by default when you install the Windows Phone Developer Tools:



Not exactly the most appealing look of all time now is it?

When first reading through the help files online for the beta of the Mango release, I noticed that you could now set both the background and foreground colors, problem solved right?

Well… not really. 

The first issue is that pops up is that the pattern on the background that the starter project uses has some designs that run off of the screen (not sure I like this fact since for the rest of the phone when something runs off screen it means you can scroll to it), since we can’t set a background image for the system tray, it looks kind of funny.



That’s alright for me though, as I rarely use background image that has funky circles in it anyways.  However, scrolling over one panorama item shows the next issue: tall letters in your panorama title:


That’s right, it’s not just the design that gets clipped by the new System Tray, but also taller letters also have this problem as well.

So if the new System Tray has all these issues with design, what good is it then?  For some of the applications we’ve built, we use a panorama that uses the logo of the company for the panorama title. 

In that small use case, then we can finally get what our users are asking for.  So as the title says:

SysTray + Panorama: mostly still a no-go in Mango

Older Posts »