Dutton's blog

Developer! Developer! Developer! (DDD) North 2013 Review

This weekend, with understanding wife and baby in tow, I took the loooong trip up north to Sunderland to attend DDD North 2013. After having such a good time at DDD East Anglia earlier this year I was keen to sign up for more DDD events and this one didn't disappoint. Slightly bigger than DDDEA, this event had five streams of talks across a broad spread of .Net and related topics.

[caption id="" align="alignnone" width="1024"]20131014-135631.jpg The wrap up final session at DDD North, bring on the swag![/caption]

The venue was the University of Sunderland's "Prospect Building and David Goldman Informatics Centre", a modern building with views of the River Wear. It was difficult to pick which talks to attend as they all sounded so good, but in the end I opted for:

F# Eye for the C# Guy (Phil Trelford, @ptrelford)

I was looking forward to this as so far have found F# a bit of a struggle, not helped by the fact that I've never found any examples relevant to the kind of stuff I tend to do.

Phil opened with a background of F#, discussed some of the applications he's been involved in, such as the multiplayer skill matching on Halo 3 - a machine learning algorithm which then went on to be used across the whole of XBox Live, written in F#, before introducing some of the basics, static typing, syntax, and converted a simple POCO C# class into F#. This significantly reduced the amount of code in the process, meaning less code to maintain, and ultimately less bugs. The way you define classes (or "types" and "modules" in F# lingo) make it really useful for mapping out domains, and he explained how his current projects tend to go down this route; F# for domain modelling and business logic and C# at the front end.

Just as the talk's title promised, Phil approached a subject that I've found tricky to "get" up to now from a C# perspective with some real world examples that I can relate to. I've bought a book and I'm determined to get up to speed.

Cross-Platform Mobile Development in Visual Studio (Bart Read, @bart_read)

Anyone who opens a talk with the question "who likes beer?" has immediately got my attention, and my initial brief disappointment that this wasn't followed by the arrival of samples was soon overcome by a demonstration of the mobile app Untappd, a beer-discovery social networking application which is available in Windows Phone, Android, Apple iOS and Blackberry versions thanks to the open source cross mobile development tool PhoneGap.

Bart explained the different types of mobile application; native code, hybrid (calling custom native binaries which project the device's API into some other language like Javascript) and mobile web, with the relative pros and cons of each, before focusing on the development tools with Visual Studio support, RedGate's Nomad, Telerik's Icenium, both of which are hybrid solutions and Xamarin which takes a different approach of producing native code for each platform.

Bart works for RedGate and so his talk soon focused on Nomad, but as both this and Icenium are based on PhoneGap (which just to be even more confusing has now been released as Apache Cordova), he explained that they are broadly compatible.

Nomad comes in two or three parts depending on which version you go for; a Visual Studio Extension and access to the build service in the cloud (which lets you build iOS apps without a Mac but will also build for Android) comes in at around $25 a month, with a UI designer thrown in for an extra $10.

The demo-gods must have been happy as his live demos; submitting a dummy CRM application from Visual Studio on his laptop to Nomad's cloud build service, before installing the built application from a DropBox folder on his Android tablet, went without a hitch. He then followed this up with a further demo integrating Azure mobile services for data storage.

A slide on the future direction of Nomad; on device debugging, utilizing the Visual Studio debugger rather than Chrome Dev Tools, a (limited) free version of the cloud build service, Cordova plugin support and Windows 8 Phone support, wrapped up a very informative talk.

You've got your Compiler in my Service (Matthew Steeples)

Matthew introduced Microsoft's Roslyn; their awesome new language object model which supports code generation, analysis and refactoring by opening up the Visual Basic and C# compilers as APIs.

He demonstrated some of this awesomeness with the longest C# "Hello World" example I've ever seen, 78 lines of code! This used Roslyn to build up the source code in code; writing the Hello World application with SyntaxNodes, then programatically building, then running it. He explained how Roslyn can also parse existing code from strings, which is good for loading code dynamically e.g. you could store business logic code written in a database and load, build and apply this in your application at run-time.

It also provides the ability to extend Visual Studio for code analysis, creating custom Refactoring and Code Issues. Sample templates are provided in the Sept 2012 CTP of Roslyn but both involve implementing a defined interface and then exporting the class using MEF for Visual Studio to pick it up. Debugging results in a new instance of Visual Studio being launched with the new functionality loaded as an extension.

This is an incredibly powerful feature for devs and the possibilities for VS productivity improvements and dynamic code analysis in applications that this will allow is very exciting.

The current CTP was launched back in September 2012, so a new release is due any time soon. With over 12 months of development, a lot might have changed so Matthew recommends holding out for the new version to anyone wanting to take a look at this.

Tyrannosaurus Rx (John Stovin, @johnstovin)

I've been a regular user of Rx for some time now, mainly Throttle and Buffer due to the nature of the data that I deal with, but I must confess that it has been a bit of a "magic black box" for me. A colleague introduced it to me a while back (cheers Jarek) to help with some performance issues I was experiencing, it helped me out at the time but actually looking under the hood to see what it does has been on my todo list for ages.

This was an Rx for beginners talk, so John started from the beginning. He explained how just as IEnumerable<T> and IEnumerator<T> allow you to work on sequences of "things", the inversion of that concept; IObservable<T> and IObserver<T>, allow you to publish sequences instead. I felt quite guilty as a holder of a Software Engineering degree that I had never come across Marble Diagrams before but they make some quite complicated Rx scenarios very easy to represent.

From here he showed increasingly complicated scenarios working towards a UI example, with multiple mouse move and button events being combined to provide click and click and drag functionality, the sort of task which would lead to some serious spaghetti code with event handlers and local state without Rx.

A great talk, which filled in a lot of gaps in my Rx knowledge.

EventStore - an Introduction to DSD for Event Sourcing and Notifications (Liam Westley, @westleyl)

The demo gods finally struck! A last minute room change caused by a broken projector (which Liam blamed on a rogue "fruit based" laptop) followed by further shenanigans in the sourcing of a lectern power socket to eliminate a health and safety trip-hazard nightmare didn't phase Liam one bit as he launched into his "101" talk on EventStore, the open-source functional database.

He covered some of the basic concepts of EventStore; how the data is Create and Read-Only, with no updates and deletes (to the initial unease of developers, only to realise that source control systems such as Git do this quite happily). This eliminates the complications which arise in traditional relational databases with performance and backup as the files are never locked, only incrementally added to. Data versioning is automatic, and reconciliation is handled by the user (EventStore will tell you if it already has the "new" version you are trying to add, so it's up to you what to do next). Traditional database indicies are replaced by JavaScript and run on the JavaScript v8 engine.

He then ran though how to run a single node of EventStore, covering some of the common pitfalls that catch people out (not having sufficient security to host an http server for example) and then created a database containing the DDD North talks agenda and demonstrated how to query this from C# or through the web interface. He showed us projections, which are used to filter streams, can be administered through the web interface and can either create new copies of the events or link to the original events.

A very informative talk on something which I have wanted to try for quite some time, I will certainly be having a look at EventStore in the near future.


This was my second DDD, first DDD North and I had a great time. The venue was very well laid out (first time I've sat in a lecture theater since university, which felt a bit strange), talks were extremely informative and I have come away with lots of new ideas and things I want to try.

For those of you who have never heard of Developer! Developer! Developer! they are a series of free developer community events that have been running since May 2005. They were started on the following five principles:

  • For the community and by the community
  • Free to attend
  • Held on a Saturday or non-work day
  • No Microsoft speakers (with some exceptions)
  • Grow the local speaker community

The session proposals are submitted and then voted for by the attendees to decide the agenda. They regularly attract hundreds of attendees and often sell out in minutes. If you're interested in any aspect of .Net development then you will definitely find something of interest so please check them out, I intend to visit as many as I can, so feel free to say Hi if you spot me.

Thanks to the organisers for creating yet another awesome DDD! These free events can't happen without sponsorship, so thanks also go out to the following for their support:

How to delete a TFS Project from TFS Online

Microsoft have pulled an absolute blinder giving us Team Foundation Service, their TFS in the Cloud solution, but once you've fired off a few test projects to play with it and want to get on with some proper codeage, how do you delete them?

There's currently no way of doing that through their web interface, so you have to rely on the command prompt and either at least Visual Studio 2012 or the free Team Explorer 2012 to give you the tfsdeleteproject.exe command.

Here's how:

  1. Fire up a command prompt (Start -> Run "cmd.exe")
  2. Navigate to where you've installed one of the above tools (cd "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE")
  3. Run tfsdeleteproject.exe /force /collection:https://<your tfs online collection name>.visualstudio.com/DefaultCollection "your project name"

The key thing to remember here is the "/DefaultCollection". Even with the /force argument you'll be prompted before deleting.

Custom format string for a .Net 3.5 TimeSpan object

Hmm, turns out TimeSpan only supports custom ToString formatting from .Net 4 onwards....

So here's a noddy extension method. Supports h for hours, m for minutes, s for seconds (along with hh for zero padding, and so on) and passes any other characters through to the output. It's all I needed but could be easily extended.

        /// <summary>
        /// Returns the TimeSpan object as a string using the provided format string.
        /// Currently supports:
        /// h  - Hours
        /// m  - Minutes
        /// s  - Seconds
        /// hh - Zero padded hours
        /// mm - Zero padded minutes
        /// ss - Zero padded seconds
        /// </summary>
        ///<param name="ts">The TimeSpan object</param>
        ///<param name="formatString">The format string</param>
        ///<returns>Formatted string representation of the TimeSpan</returns>
        public static string ToString(this TimeSpan ts, string formatString)
            var sb = new StringBuilder();

            for (var i = 0; i < formatString.Length; i++)
                switch (formatString[i])
                    case 'h':
                        if (i < formatString.Length - 1 && formatString[i + 1] == 'h')
                            if (ts.Hours < 10) sb.AppendFormat("0{0}", ts.Hours);
                            else sb.Append(ts.Hours);
                        else sb.Append(ts.Hours);
                    case 'm':
                        if (i < formatString.Length - 1 && formatString[i + 1] == 'm')
                            if (ts.Minutes < 10) sb.AppendFormat("0{0}", ts.Minutes);
                            else sb.Append(ts.Minutes);
                        else sb.Append(ts.Minutes);
                    case 's':
                        if (i < formatString.Length - 1 && formatString[i + 1] == 's')
                            if (ts.Seconds < 10) sb.AppendFormat("0{0}", ts.Seconds);
                            else sb.Append(ts.Seconds);
                        else sb.Append(ts.Seconds);
                    default: // Pass through any non recognised characters
            return sb.ToString();
Excluding projects from the Visual Studio Code Coverage tool

I recently started playing with Visual Studio's code coverage analysis tool to show me where my unit testing is insufficient. I keep tests in their own projects, named after the assembly they are testing, but with ".Tests" bunged on the end.

The only problem I've discovered with this is by default the Code Coverage tool will analyse all projects in the solution including the test projects themselves, which score 0% coverage and skews your solution stats.

You can apply the [ExcludeFromCodeCoverage] attribute to every test class, and that works fine, but is a right faff with lots of tests.

The alternative is to exclude the whole assembly. Following the guide over at the MSDN suggests that you can do the following in a .runsettings file:

    <!-- Include all loaded .dll assemblies (but not .exe assemblies): -->
    <!-- But exclude some assemblies: -->
    <!-- Exclude all file paths that contain "Temp": -->

So full of enthusiasm I tried this:


But instead of basking in the glory of a 100% code coverage score, I get the following error:

Empty results generated: No binaries were instrumented. Make sure the tests ran, required binaries were loaded, had matching symbol files, and were not excluded through custom settings. For more information see http://go.microsoft.com/fwlink/?LinkID=253731

It turns out the regular expression parser is being confused by the non-escaped dots (cheers Grin), so I need to do this instead.


This had me stumped for a while, but I'm glad it's fixed. I think the MSDN page needs updating. Anyway, back to writing unit tests :)

How to put a line break in a XAML StringFormat

One of the new features introduced way back in .Net 3.5SP1 was StringFormat. This allows you to define the format of the output if the bound value is a string.

It turns out that this is a lot more efficient than using multiple Runs in TextBlocks to concatenate strings and bound values, so in my quest for "ultimate WPF performance" (TM) this was my latest victim. My old code in a pop-up looked something like this:

    <Run Text="{Binding FieldNumber}"/>
    <Run Text="{Binding FieldValue}"/>

But how do you implement the line break using a StringFormat I hear you ask? It turns out you can use the hexadecimal encoded value for a new line


as follows:

    <MultiBinding StringFormat="{}{0}&#x0a;{1}">
      <Binding Path="FieldNumber"/>
      <Binding Path="FieldPath"/>

And there you go... hope this helps.