28 December 2010

Enum values can be characters too

Almost everyone who has programmed something in C# has created an enum at one point or another:

public enum Whatever
{
  Zero,
  One,
  Two,
  Three
}
You can cast an enum value to an int - you then get a value assigned by the compiler based upon the order in the enum, so Zero will be 0, One will be 1, etc. If you have a particular sick mind you can add a new chapter to How to write unmaintainable code by creating something like
public enum Whatever
{
  One = 5,
  Two = 3,
  Three = 2
}
But you can also assign values to it using characters. This way, I have created an enumeration that can be used to retrieve tiles from Google servers based upon their enum value without the switch I wrote in my infamous "Google Maps for Windows Phone 7" article. So now you can define the server on which Google stores a particular tile type like this:
public enum GoogleType
{
  Street         ='m',
  Hybrid         ='y',
  Satellite      ='s',
  Physical       ='t',
  PhysicalHybrid ='p',
  StreetOverlay  ='h',
  WaterOverlay   ='r'
}
and then determine the server like this:
var server = string.Format("http://mt{0}.google.com", (char)GoogleType.Street);

This makes far cleaner code.

09 December 2010

WiX- A Developer's Guide to Windows Installer XML

And now for something completely different – a review of someone else’s examples. I have been reading “WiX- A Developer's Guide to Windows Installer XML“ by Nick Ramirez. I would not dare call myself a WiX expert – in fact I wrote one three-component setup in the cause of a few weeks, but I was asked to review this book by its publisher, Packt Publisher and well, here’s my verdict.

Examples examples examples

What I like about the book: it takes you by the hand using what I think is the most powerful tool in teaching: examples. Which is what I so painfully missed when I myself was struggling with WiX. Lots of concepts and half-*ssed postings on forums, but no complete examples. In the first chapter the author starts a small example which gets more and more elaborate. After reading that first chapter you have a good idea of the most important concepts of installing. The second chapter follows the same recipe and gives you more of the fine details on creating files and directories. If you have read the first two chapters, you can write a basic installer.

Pick and choose

The rest of the book is more of the pick-and-choose type. It still follows the same recipe, but whereas the first two chapters are mandatory, the rest is optional – use what you need, although I would recommend not skipping chapter 5, “Understanding the Installation Sequence”

What do I miss?

I was puzzled by the absence of  a description of the util:XmlFile task, which can be utilized for modifying config files during install. Apart from that, the sub titles says “Create a hassle-free installer for your Windows software using WiX”. That’s exactly what it delivers. I would very much have liked something on how you create and install web sites, handle the intricacies of creating applications pools, set the ASP.NET version, permissions, create CGI support settings and stuff like that – taking into account people can install on different operating systems and different versions of IIS. Maybe something for a second print? ;-)

Conclusion

First part learns you the basics pretty well, the rest is a solid reference. A book I should have bought and read before I started mucking around with WiX.