Pages

Monday, December 2, 2013

Learning Reactive Extensions(Rx) with the help of LinqPad

I am currently attempting to become proficient in using ReactiveUI (https://github.com/reactiveui/ReactiveUI) for WPF and cross-platform mobile development.  In order to understand the paradigm I am first trying to understand the core concepts of reactive programming in general using Reactive Extensions (Rx).  

I am using the online book http://www.introtorx.com by Lee Campbell, which so far is excellent.

My method is to use LinqPad (http://www.linqpad.net) to run the examples and play around with different Rx queries.  If you do not have LinqPad, go get it now...I will wait. 

Why LinqPad you ask?  Why not just use Visual Studio?  Well, because Visual Studio is mind numbingly slow.  LinqPad is extremely fast and doesn’t get in the way of your cognitive flow.  Trust me, in the time it takes VS to compile and run a simple Rx query you will be off reading Reddit or Facebook.

Now that you have LinqPad, you may find it tedious to run Reactive based code.  This is because you need to add references and namespaces.  You can, and I suggest that you do use LinqPad to download built in Rx samples, which work out of the box, since all of the references are built in.  You could just overwrite one of these templates and piggyback on the references, but I will show you how to setup your own.

1) Open the LinqPad installation folder and create a References sub-folder
     Default location is C:\Program Files (x86)\LINQPad4\References

2) Add the following dll’s to the reference folder.
       The way I obtained the dll’s was to create a project in Visual Studio and then use nuget/Package Manage Console to add Reactive Extensions (install-package Rx-Main). I then went to the download directory and copied the dll’s. If you purchase the full version of LinqPad you can use nuget directly.

System.Reactive.Core.dll
System.Reactive.Interfaces.dll
System.Reactive.Linq.dll
System.Reactive.PlatformServices.dll
System.Reactive.Windows.Threading.dll


3) Create a new query (File->New Query). And add the following code:

If you attempt to run it now it will not work due to missing references.


4) Hit F4. That will open the Query properties screen and allow you to add references. Use the Browse button
to locate the dll’s in the References folder created in step 1.


5) Select the “Additional Namespace Imports” tab and add the following namespace.


6) Hit OK. You should now be able to run you Reactive Extension queries in LinqPad.

One thing to note is that you may need to add more namespace imports based on what
reactive objects you use.  A few that I needed right away were:
System.Reactive.Disposables
System.Reactive.Linq
System.Reactive.Subjects

Happy Coding

Tuesday, October 29, 2013

How to get dynamic versioning using WiX and TFS continuous integration

First and foremost, I owe this post to Chris Painter(@chrpai).  He, on his own time, walked me through the steps on how to get this dynamic versioning setup in TFS and WiX.  He saved me tons of time and I really appreciate his generosity.

As a professional software developer I believe that having a continuous integration setup is par for the course.  I used to live in a world where I would come into work on a Monday morning and find "the build" broken.  Mind you this was right before someone wanted to demo the software.  I have vowed that I will not work without the CI safety net.

Today I needed to get my latest application installer versioned.  I want it to version each time I check in and my CI build runs.  I want it to be as simple as possible.  In particular I am not yet ready to go the custom activity route.  I spent a considerable amount of time on Stack Overflow and the WiX forums looking for an answer, but with no avail.  Without further ado here is the solution

1.     From TFS open your build process template in the xaml designer.  You can find the path hyperlinked from the Build Process page


2.     While you are here go ahead and setup the format of your versioning.  You can do that like this. 


You can choose your own versioning method, but let me explain this one.  First the _ after $(BuildDefinitionName) is important because we are going to use it to parse later.  Everything after the _ will be the version.  You can see that mine is  3.0.YearDayOfYear.Rev.  This will give me a version like this 3.0.13302.1 if the build is the first build on Oct 29th, 2013.

3.     Back to the xaml workflow. Navigate to the “Run MSBuild for Project” step in the tree.  It is pretty deep in the hierarchy.  See the picture below.

4.     Open the Properties of this build step and modify the CommandLineArguments property to something like this. Notice I am splitting on that _ I talked about earlier.

String.Format("/p:SkipInvalidConfigurations=true {0} /p:MSIProductVersion={1}", MSBuildArguments, BuildDetail.BuildNumber.Split(New Char() {"_"c}).Last())

5.     Save your workflow template and check it into TFS under the BuildProcessTemplates folder.

6.     Make sure your build definition references the modified build workflow you just checked in and save your build definition.

7.     Queue your build and install your product.  You should now have a dynamically generated version number for your product that you can trace back to the date and version of source code you build.



This solves a small part of the whole equation of installer creation.  It’s a huge topic with a lot of available customization.  Chris Painter helped me get this far and has also showed me a great tool he created at https://iswix.codeplex.com/, which opens up a great number of possibilities without having to know all the low level details of WiX itself.