“How we built Rover” – Cross post

19 Feb
Over at my employer's website I've blogged about the system I've been spending the past few months working on. I talk a little bit about Xamarin, SQLite, Swagger and GraphViz DSLs
No Comments

Posted in .Net


My TypeScript presentation for the North Shore DNUG

23 Aug
Last night I had the pleasure of talking about TypeScript at the North Shore .NET User Group here in Auckland. I got some great questions, and enjoyed myself. As promised, here are my slides:   And here is the technical walkthrough that I went through:  

Creating tiled backgrounds in Metro style XAML apps

20 Jul
TL;DR version: This class will let you tile an image in a Metro-style XAML app. Use an image that's at least 128x128 for best memory efficiency Textures can make your application beautiful. Here's an example from, which is full of classy textures: [caption id="attachment_285" align="aligncenter" width="600"] A nice tile texture[/caption] These textures can make great backgrounds, but because the texture is usually smaller than your application (especially tiny textures like  ), you need to repeat (tile) the image vertically and horizontally. Images that "match up" on opposite sides are ideal. All the images on  http://subtlepatterns.com and are tileable. So how do you program your application to repeat this image across a surface? In HTML, you can use the css style "background-repeat: repeat" to tile an image across your webpage. In WPF, you can set up the TileBrush properties on an ImageBrush to tile an image across your application. But in Silverlight, Silverlight for Windows Phone, or Metro style XAML applications, you're out of luck.

Fake it

The easiest solution is to use Photoshop (or cheaper equivalent) to create a huge image that you can set as a background. Just use the pattern tool to tile your texture onto an image that's bigger than your application's surface will ever be. The question is: can you guarantee a maximum size? With Metro style XAML applications,  there is no maximum resolution. The other problem is that these massive image files tend to use up a LOT of memory. In my case, it was so much memory that I was likely to fail Microsoft's Win8 certification.

Make it

There was no way I was going to convert my application into a JavaScript & HTML app, so I set out to create a control that would look just like a WPF tiled brush. The easiest way to do this is to manually arrange a set of images in a control. I'm very familiar with WPF, and I just knew there'd be some weird inconsistencies in the new WinRT APIs that made this harder than it should be, so I decided to spike this in WPF first. I inherited from Canvas, gave it an ImageSource property, and slapped my code into the OnRenderSizeChanged method. It worked perfectly, here's the code: [gist id=3077863 file=TileCanvas.cs]

I broke a convention :(

If I was a WPF Purist I would have never extended a Panel class in order to provide a visual control. I'd have built a templated control (Inheriting from Control), and declared the canvas as a template part, and provided a default template that just contained that canvas in my Generic.xaml file. But my whole aim was to keep memory usage low, and in WPF every visual costs you memory, so I decided to pre-optimise. It's also simpler this was as I only have to show you one file :).

Optimising Memory

A tilebrush in WPF on a 1000x800 surface will happily repeat a 4 pixel image for you, thousands of times (200,000 to be exact), without breaking a sweat. However, with my TileCanvas, we're creating an Image visual every time we want to repeat the tile, so you don't want an ImageSource that's too small. You have to find a happy balance between a huge image (which uses up a lot of memory by itself) and a lot of small images (where you don't keep paying for the image data, but you do pay for the visual tree explosion). I have found that by repeating your pattern, Photoshop style, onto an image that's a sized with a nice round number like 128x128 pixels is a good compromise. This applies to the WPF spike as well as the following Metro solution.

Make it - Metro Style

If you want to build a Metro Style application, you need to program against the WinRT API. This provides .NET developers with new challenges. Microsoft say that WinRT allows .NET developers to use their existing skills, which is fair. What they don't mention is that you're going to need a lot of new knowedge. WinRT is like a parallel universe - a lot of the things you expect to find are there, but they are a bit different, or they're in a different place. A lot of operations are now done asyncronously, which should be make apps snappier. Truly a "parallel" universe (sorry). When I tried to port my WPF TileCanvas over to use the WinRT version of XAML controls, I ran into two differences that changed the way I had to do things:
  • There's no longer a RenderSizeChanged method - after a bit of experimenting, I decided on the LayoutUpdated event (although adding images causes this event to be raised, so I had to track the old size in order to avoid stack overflow)
  • ImageSources now start with a width and height of 0. It's not until the ImageOpened event is raised that you can find out the width and height of an image. And you don't get an ImageOpened event until your image is loaded into the Visual Tree. To get around this chicken-and-egg situation, I add a single image to the canvas, and then once it's opened and I have the width & height I do a proper layout of the whole screen. I also attach to the ImageFailed event to help you debug, and clean up my event subscriptions once they've fired.
Here is my working Metro-style TileCanvas: [gist id=3006848 file=TileCanvas.cs]

Almost perfect?

One thing that I would add in future would be to not throw away the entire canvas of images every time it was built. It would be better to determine just how many images need to be added and removed. At the moment, this isn't a big issue because metro apps are always fullscreen so they don't change size unless you snap/rotate them.

Shameless plug

I needed this class because I wanted a background texture in my new Windows 8 game, Chromazone. It's just been accepted my Microsoft to the store, check it out:

Building on-the-fly images for WP7 live tiles

28 Feb
Windows Phone 7.5 (Mango) lets your app create multiple live tiles on the phone's start screen (with the ShellTile api). This is a very cool way to provide deep links into your application. It's used brilliantly by the the native apps for contacts (you can pin people and see their individual updates), office (you can pin documents), and music & videos (you can pin albums and playlists). When you create a new ShellTile, you get to specify one or two image URIs (for the front and back). If you use a relative URI, then the shell will look for the image inside your XAP - just like any other image URI in your app. But that means you only get to use images that you ship with your app - how does the music & video app render the album art for each tile? What if you want to take a screenshot of the current game and use that? One answer is to use or generate images on the internet and use an http-schemed URI, but that approach can cause the tile to unpin when you turn off your phone (I don't know if that's a bug or a feature), and you'll also be relying on an internet connection. The best option is to save the image to your application's isolated storage, because you are free to save whatever file you like there (with full control of the content and format), and the image will always be available (so your tile won't unpin). If you've already sourced your image from the internet, then you can just save it to iso storage, but what if you want to generate an image on the fly? Have a look at the mail app, and how it tells you how many emails you've got in big letters. If you've got no unread email, it adjusts the position of the email icon too. This image is probably built on the fly by a background process. But what's a good way of rendering text and images to an image file? In my opinion, the best way to render custom, dynamic content in a Silverlight app is to leverage the platform: just render some XAML. If you create a 173 by 173 control, you've got full control of how those pixels will look. You can even use databinding. You can use the WriteableBitmap. It's got a constructor that takes in a UIElement (which will immediately render that element into the bitmap) and a SaveJpeg extension method that will write the bitmap to a file. In my Bus Alert London WP7 app, I used this technique to render custom tile icons with maps in the background: [caption id="attachment_237" align="alignnone" width="480" caption="Bus Alert Tiles"]Bus Alert London - Tiles[/caption] In the process, I discovered a few very important gotchas:
  • The UIElement that you render has to be in the application's visual tree when you call the WriteableBitmap constructor. Otherwise, it may not render at all, may lay out incorrectly, may not have access to the correct StaticResources, or databinding may not occur. You can put it in the visual tree, render it and immediately hide it so that the user never sees it if you like. Unfortunately, this rules out the use of XAML to produce live tiles from background agents.
  • The image must be stored under the special directory \Shared\ShellContent in your isolated storage folder or it will not be accessible by the operating system.
  • If you don't close the image's filestream before creating the live tile you will see a weird bug where the live tile's image is only visible when you are moving it around the start screen
  • If you want transparency, you'll need to save a PNG. For this you will need to use the .NET image tools library as documented on stackoverflow.
I've also put together a sample project that builds a custom live tile out of XAML and avoids all of these gotchas. It's available on the MSDN code gallery at  

Slides from my Apps World talk: Beginning Windows Phone 7 Development

02 Dec
I recently gave an entry level talk on Windows Phone 7 development at the Apps World conference in London. If you're interested, you can download my slides from here. Some other links that are useful for people who are getting started with WP7 development are:  

Raising the right PropertyChanged with C# 5’s Caller Info Attributes

21 Sep
Implementing INotifyPropertyChanged typically requires the use of magic strings, and I've never been happy with the various workarounds available. They either affect performance or require a lot of extra developer ceremony (which is no good in big teams). I'd always been hoping that C# would introduce something similar to the "typeof" operator that would help you get the name of the current property (or method) without having to use any slow reflection. Before the "//BUILD/" conference, I had given up on C# 5 bringing in anything useful here. But then I was reading Colin Jack's summary of the //BUILD/ talk on Future directions for C# and Visual Basic, and was particularly interested by the new Caller Info Attributes feature of C# 5. This feature is not in the CTP of VS11 yet, so I can't test it, but I expect you'll be able to write the following RaisePropertyChanged method:
protected void RaisePropertyChanged([CallerMemberName] string member = "")
    var copy = PropertyChanged;
    if(copy != null)
        copy(new PropertyChangedEventArgs(this, member));
and now when you call this method from a property setter, leaving out the optional parameter:
public string UserName
        return _userName;
the compiler will fill out the parameter for you, passing "UserName" to the RaisePropertyChanged method. What I like about this is that the compiler is creating the magic string for you on every compile - so when you rename your property, the string is automatically kept in sync. This is the best of both worlds, we get the performance benefits of a hardcoded string literal, while keeping everything DRY (and therefore hard to inadvertently break).  

Posted in .Net, WPF


Design time data nirvana in Blend 4

07 Feb
Quite a few of my posts have been about how to hack design time data into Blend. With Blend 4, you no longer have to hack! The new "Create Sample Data from Class..." option is perfect. Kirupa from the blend team has posted a great writeup on this technique. It works in WPF, Silverlight and WP7. Highly recommended.

There’s a maximum of 255 local messaging channels in Silverlight 4

31 Jan
Don't ask me how I got into this situation, but I found this out the hard way. A quick search will tell you that with Silverlight Local Messaging each message has to be under forty thousand characters, but I haven't found anything on the internet yet that tells you that you can have a maximum of 255 channels open at a time. So I'm taking responsibility and putting it out there. Going over the limit will give you a cryptic COM exception, and channels can be "leaked" if one browser process crashes while another is open (for example iexplore.exe and chrome.exe, or just two instances of chrome.exe). Often closing all browsers will clean up the phantom channels, but not always. Remember that other Silverlight applications might be using some of these channels too, so you should always design your application such that it uses a minimum number of channels.

Buy Seroquel From Trusted Pharmacy

12 Nov

I've just released a new open source project on codeplex:

Power Assert .NET is a .NET port of Groovy's PowerAssert Buy seroquel from trusted pharmacy, , which replaces your normal unit test assertions.

Unlike the standard assertions built into nunit, seroquel paypal, Seroquel in us, MSTest, and xunit etc; Power Assert gives you a breakdown of all the values within your assertion expression, buy seroquel without prescription, Where can i buy cheapest seroquel online, making it quicker for you to hunt down the cause of the test failure:

System.Exception : IsTrue failed, expression was:
x + 5 == d.Month * y
| | | | | | |
| | | | | | 6
| | | | | 18
| | | | 3
| | | 01/03/2010 00:00:00
| | False
| 16

It's quite a simple little thing, fast shipping seroquel, Buy seroquel from mexico, but it's already saved me lots of debugging time. Give it a go :), buy seroquel without a prescription. Order seroquel from mexican pharmacy. Buy seroquel from canada. Saturday delivery seroquel. Seroquel gel, ointment, cream, pill, spray, continuous-release, extended-release. Seroquel tablets. Purchase seroquel online no prescription. Seroquel medication. Buy no prescription seroquel online. Order seroquel online c.o.d. Where can i order seroquel without prescription. Seroquel prescriptions. Seroquel to buy. Online buy seroquel without a prescription. Seroquel over the counter. Seroquel prices. Real brand seroquel online. Purchase seroquel online. Seroquel in uk. Where to buy seroquel. Seroquel in mexico. Seroquel craiglist. Order seroquel from United States pharmacy. Seroquel san diego. Rx free seroquel. Purchase seroquel. Seroquel from international pharmacy. Ordering seroquel online. Buy cheap seroquel no rx. Seroquel pills. Where to buy seroquel. Buying seroquel online over the counter. Buy seroquel online without a prescription. Where can i find seroquel online. Buy seroquel no prescription. Sale seroquel. Seroquel trusted pharmacy reviews. Where can i buy seroquel online. Order seroquel online overnight delivery no prescription. Free seroquel samples. Sale seroquel. Where can i buy cheapest seroquel online. Seroquel discount. Seroquel in australia. Purchase seroquel online no prescription. Seroquel prices. Seroquel in usa. Seroquel buy online. Seroquel in canada. Over the counter seroquel. Seroquel pills. Buy seroquel online with no prescription. Seroquel to buy. Buy seroquel without a prescription. Purchase seroquel online. Online buying seroquel hcl. Buy seroquel without prescription. Buy seroquel online without a prescription. Order seroquel online c.o.d.

Similar posts: Buy tramadol from trusted pharmacy. Where can i order ultram without prescription.
Trackbacks from: Buy seroquel from trusted pharmacy. Buy seroquel from trusted pharmacy. Buy seroquel from trusted pharmacy. Buy seroquel from trusted pharmacy. Buy seroquel from trusted pharmacy. Buy seroquel from trusted pharmacy. Buy seroquel from trusted pharmacy. Buy seroquel from trusted pharmacy. Buy seroquel from trusted pharmacy. Buy seroquel from trusted pharmacy. Online buy seroquel without a prescription. Buy seroquel online cod. Buy seroquel online cod. Real brand seroquel online. Real brand seroquel online.

1 Comment

Posted in .Net, Testing


Buy Soma From Trusted Pharmacy

12 Nov

One of the new .NET technologies that is really exciting to me these days is the Reactive Extensions to .NET (RX) Buy soma from trusted pharmacy, . Sometimes it's called LINQ to Events, soma craiglist, Buy soma no prescription, because you can write LINQ queries against future values (events, nicely wrapped up into the IObservable<T> interface), buy no prescription soma online, Buy soma online no prescription, instead of against existing collections (IEnumerable<T>). This technology is especially useful in stateful programming models, where can i order soma without prescription, Order soma no prescription, such as when you're building ViewModels for WPF or Silverlight. Once you start programming with RX (although it's got a steep learning curve!), where can i find soma online, Soma in india, you start to see lots of places where it would really help make your code simpler. I saw one such place: whenever you need to programatically respond to an INotifyPropertyChanged notification, soma from canadian pharmacy.


INotifyPropertyChanged is an interface that most viewmodels need to implement, buy soma from trusted pharmacy. Next day soma, It's used implicitly by the Silverlight and WPF data binding system to register a databinding's interest in the fact that a property has changed, thus keeping all bindings to the same property up to date, soma in japan. Soma paypal, When you implement it, you're responsible for firing a PropertyChangedEvent event every time a property changes, buy soma online without prescription, Fast shipping soma, with the name of the property as a parameter to the event.

Sometimes, soma tablets, Soma for sale, you might want to programatically watch changes to a property too. Imagine a screen where users can add rows of data that represent orders, soma san diego. Buy soma from trusted pharmacy, If there needs to be a "grand total" on the screen, then one viewmodel (possibly the root VM for the whole screen) will want to subscribe to the PropertyChanged event of each of the order's Viewmodels. Order soma from United States pharmacy, However, there's a nicer programming model for listening to updates (events etc) than the INotifyPropertyChanged event.., buy soma from canada. Order soma online overnight delivery no prescription,


IObservable is the core of all RX programming (like IEnumerable is to LINQ). If you want to expose a source of data, soma medication, Ordering soma online, you need to expose an IObservable. There's already a utility method to turn an event into an IObservable, soma over the counter. But this Observable will publish IEvents, which isn't quite what I was after, buy soma from trusted pharmacy. Buy soma online cod, What I wanted was to create an IObservable of the new values of the viewmodel's property. Just like LINQ, delivered overnight soma, Soma from international pharmacy, we can use the "Select" method to acheive this.

Funcy Expressions

An Expression is a C#3 construct that allows you to pass expression trees around, buy generic soma. Real brand soma online, This is a very popular way for you to strongly type property names, because you can reflect over an Expressionwhere to buy soma, Soma to buy online, PropertyType>> to get the name of the Property. Buy soma from trusted pharmacy, You can also Compile() the expression to be able to execute it. My method uses both of these: It needs to know which PropertyChangedEvents it should react to (the Where() clause), buy cheap soma no rx, Where can i buy soma online, and it needs to read the new value out (the Select() clause).

The tests

Here are the unit tests for this extension method, where to buy soma. Soma in mexico, I had to create a dummy view model class to test, named "PropertyChanger", online buy soma without a prescription. Soma in us, Note how you can supply "true" to the startWithCurrent parameter to make sure your subscription will instantly start with the current value of the property, as well as receiving new values whenever a PropertyChangedEvent is fired, soma trusted pharmacy reviews. Soma in uk,

Enjoy. Buying soma online over the counter. Buy soma from mexico. Soma overseas. Saturday delivery soma. Soma gel, ointment, cream, pill, spray, continuous-release, extended-release. Order soma from mexican pharmacy. Soma price, coupon. Soma prescriptions. Rx free soma. Purchase soma. Cod online soma. Buy cheap soma. Soma for sale. Buy soma no prescription. Purchase soma online. Soma medication. Buy soma online without a prescription. Purchase soma. Order soma no prescription. Order soma from mexican pharmacy. Buying soma online over the counter. Where to buy soma. Ordering soma online. Buy soma online without prescription. Soma craiglist. Rx free soma. Where to buy soma.

Similar posts: Buy yaz from trusted pharmacy. Tramadol in usa.
Trackbacks from: Buy soma from trusted pharmacy. Buy soma from trusted pharmacy. Buy soma from trusted pharmacy. Buy soma from trusted pharmacy. Buy soma from trusted pharmacy. Buy soma from trusted pharmacy. Buy soma from trusted pharmacy. Buy soma from trusted pharmacy. Buy soma from trusted pharmacy. Buy soma from trusted pharmacy. Soma in canada. Buy soma without prescription. Soma in japan. Soma discount. Online buy soma without a prescription.