Nick's .NET Travels

Continually looking for the yellow brick road so I can catch me a wizard....

My First Hour with the Smart Device Framework v2.1

Normally I wait until I can get a copy off the back of a truck before I both playing with a new piece of software but in this case I've been so eager I figure I'd bite the bullet and purchase a license to the new [OpenNETCF] Smart Device Framework v2.1 (with [VS2005] Extensions).  The other reason I felt I should make this purchase is that it is only $50 (single license) and that I figure it would help these guys continue their great work.

Although I haven't really got down to playing with the various controls and classes I am suitably impressed with the level of integration and the setup process they have.  Here are just a few shots of me "opening the box".

Installer package even has the correct icon

The installation process

Integration into Splash Screen

New Project types

New Controls, already added to the Toolbox

Integrated Help

Check out the list of contributors

Impressive Documentation

Appropriate listing in the Start Menu

OpenNETCF SDF v2.1

Neil has just announced that version 2.1 of the [OpenNETCF] Smart Device Framework has just been released. Although they now charge for this framework it is no longer just a class library that gives you missing desktop functionality.  With tight integration into Visual Studio 2005 this framework is essential for all windows mobile developers. 

Once I start playing with the new version I will endeavour to post about some of the new features I come across.

About time - Free Wireless

On Friday I heard an unconfirmed rumor that wireless was soon to be made free in the Qantas Club.  This morning I thought I'd put it to the test and sure enough: It's Free. You still need to connect via the Telstra redirect site, but that's as simple as clicking the button.

All I can say is - About Time!  Now all we need to do is convince the hotels that charging $20+ a day is just extortion. 

Now Why Didn't I think of That

I was just reading a post by Steve Lasker in which he describes how you can create a SQL Server Compact Edition database and how you can detect if the database already exists.  One of my complaints about the introduced "|DataDirectory|" substitution is that it isn't understood by System.IO.  Luckily it doesn't need to as the .Database property on the SqlCEConnection object returns the path to the database with the appropriate substitution made:

My.Settings.LocalConnectionString:= Data Source ="|DataDirectory|\Another.sdf"; Password ="SomePassword";

Dim localConnection As New SqlCeConnection(My.Settings.LocalConnectionString)

If Not System.IO.File.Exists(localConnection.Database) ...

WM6 ROM for K-Jam

Having unsuccessfully attempted to image my device to WM6 I thought I'd check with i-mate to see if they had plans to release a WM6 ROM for this device:

Jose> Welcome to club i-mate support. My name is Jose, how can I help you today?
Nick> Hey Jose - quick question regarding the k-jam
Nick> given this device is a little over a year old I was wondering whether there is going to be a WM6 ROM made available for this device?
Jose> yes there is going to be upgrade
Jose> but there is no date of release

Looks like there will be a ROM out for the K-Jam (aka Wizard) but no idea on the timings.

Code Camp Oz and the Waterpolo

This weekend has been full of lots of action and adventure.  After negotiating the Melbourne traffic on Friday afternoon I managed to pick up Phil and make the drive out to Wagga Wagga (only got slightly lost around Albury). One of the best parts of Code Camp is the first evening when everyone has just arrived and ends up at the same restaurant.  Although it took about an hours to get any food it is the perfect opportunity to catch up with what everyone has been doing.

I came to the conclusion that the world is all too small. Two members of the French team that won the 2004 Imagine Cup, Aymeric Gaurat Apelli and Francois Beaussier, now work for Readify.  I remember these guys as their level of innovation set them apart in a competition where every single entry would put most commercial organisations to shame.  It's great to see that an Australian company is recruiting some of the best up and coming international talent!

Unfortunately I wasn't able to stay for the entire camp but I was their long enough to see Damian and Paul give their Ajax session, to give my session on Synchronisation (hopefully audio (from the Perth user group) and the slides will be available later this week) and to see Grant's (who is now an MVP) session on TFS.

Here are just a few shots of Code Camp 2007 (taken with my K-Jam before I flashed it to WM6 WM5 - turns out the image was only WM5 - Doh!):

Fellow Perthite, Stephen Price (I think that's me in that photo!), made the journey too!

Damian looks on while Paul shows how to use an Updater Panel.

Mitch gets a shot with his JasJar while his Tablet PC sits idle.  

Following another 4.5 hour drive back to Melbourne on Saturday afternoon Meg and I went out to watch the George Coleman, Jr Quartet at Bennett's Lane Jazz Club.  Truly awesome and I'm so looking forward to the Herbie Hancock concert in Perth later this month.

Yesterday afternoon Meg and I went to the final session of the FINA World Championships to watch the Waterpolo. This was held at the Melbourne Aquatic centre and they had setup more security than most international airports.  We thought they were going to confiscate the coffee we were taking in, but it became apparent that they were looking for more dangerous articles. When the bronze game got started we knew we were in for an entertaining afternoon as Serbia were playing Spain.  While I have a lot of respect for all nations competing, the Serbian fans are nothing short of thugs.  They are the only nation that frequently booed the opposition - talk about poor sportsmanship!

The other interesting thing was that they had setup these flamethrowers (careful Sandi, don't get too excited) at either end of the pool that would go off whenever a goal was scored.  Even back in the stands you could feel the heat that these things gave off. 

Code Camp {where}

For some reason this week seemed to disappear.  After getting back from my trip around the globe last weekend I was excited to launch back into work.  Dave and I are now working out of the Perth Annex - the Perth extension to the R & D Centre for [Intilecta] based in Wellington.  Part of my time while I was in NZ was to help with the transition from SourceSafe to Subversion.  This was only one part of a much larger initiative to upgrade our internal infrastructure.  Already we have noticed a massive improvement in our ability to work remotely.

This leads me to my next point which is that I'm again on the road, this time at the Qantas Club in Melbourne on the way to Code Camp Oz.  This is definitely one of the developer highlights of the year, although being in Wagga Wagga it is a pain to get to for people who don't live on the East Coast - not only do we have to fly to the East (Sydney, Canberra or Melbourne), we then need to organise transport to Wagga, not to mention the additional days leave in order to get to and from the event.  For future, guys (Mitch and Greg) I think it is time to rethink this decision and move it to a more hospitable location.  This would also encourage international developers, such as Alex, to come across.

. " , ' ; ! - ? _ Are all examples of ...... Often Misused Punctuation

Rod has an interesting post about where and when you should use apostrophes (arguably the most misused punctuation).  If you were ever curious, and want a good laugh while being educated, you should read "Eats, Shoots and Leaves".  This book contains hundreds of illustrations of where you should and shouldn't use a range of punctuation and IMHO should be a core teaching requirement for all high schools!

Hosted Exchange 2007 for SoftTeq

Yesterday morning didn't start out particularly well for me.  If you have ever played around with adding/removing mail accounts from Outlook you will probably know that if you remove your Exchange mail account it removes your primary mailbox (ie the OST file).  Normally this isn't a problem because you can setup your mail accounts, reconnect to the exchange server and sync your mailbox.  Unfortunately the reason I was playing around was because the SoftTeq mail server had died so I couldn't reconnect.  Luckily I was able to download a OST to PST application that did the trick.

The real reason for this post is that I then went looking for an alternative to us managing our own server (basically we were only using the exchange portion of SBS anyhow as SoftTeq is no longer a commercial venture). This is when I came across ExchangeMailHosting, which is actually run by IT Solutions Now.  I was looking for a hosted exchange solution that was relatively cheap, that used Exchange 2007 and supported RPC over HTTP (so I could sync on the run and from my mobile device).  For $9.95 per mailbox per month this service is quite good value.

It gets better - if you want a baseline to compare service against then these guys are quite high up there.  I filled in their online application form and within an hour I had an email saying that the service was up and running.  Within 2 hours I had setup Outlook (as per instructions in the welcome email), I had accessed their web access site and I had sync'd to my mobile device.  When their application form said that someone would contact us within 24 hours I'd assumed I'd get a phone call at 3am to complete the process - but instead "It All Just Works"!

Lastly I want to point out a great new feature in Exchange 2007:  After Windows Mobile 5 was released there was a service pack for Exchange 2003 which allowed an administrator to remote wipe a device that was syncing with the Exchange server.  Clearly this was a little inefficient since it requires an admin to get involved at 3am when a drunk employee realises they left their phone in the Taxi.  The new and improved Outlook Web Access in Exchange 2007 has the ability for the user to Self-Serve through the Options -> Mobile Devices screen, as shown in the following image.

Synchronisation Strategies

The author of sync-mobile has added another post that discusses scheduling strategies for synchronisation of data.  In this post they outline three strategies for scheduling or kicking off a sync:

  1. SMS - There is definitely a risk that messages can be delayed or might never reach the target but on most networks this latency/risk is pretty low.  In fact in NZ they use SMS as a mechanism for paying for parking - the latency is 5-10 seconds which is usually adequate for most scenarios.  Don't forget that Windows Mobile 5+ now has the notification engine means that you can write managed code using the .NST Compacty Framework to intercept SMS messages, even if you application isn't running!
  2. HTTP/TCPIP - Their main point with this strategy is that battery life is a premium which I would have to agree with.  There is also the additional cost of network traffic (for those countries like Australia/NZ where data is still expensive).  This said, since the release of the Security and Messaging Feature Pack for Windows Mobile 5 we have had Direct Push email - this basically establishes a connection to the Exchange server that remains open even when the device goes into standby.  There is a great article on MSDN that discusses how you can use this technique in your application.  In my experience the drain on battery power is actually not that bad using this technique.
  3. Scheduled Sync - Ok, now we are talking - this is a technique I have used a couple of times.  The biggest issue here is that in managed code any sort of timer you use has the issue that it won't be triggered if your device has gone into standby (which it is likely to do in order to extend battery life).  This is where you really need the power of the Smart Device Framework from the guys at OpenNETCF so you can use the Large Interval Timer in order to wake your application up.

It would be great to hear what other techniques people use in order to trigger synchronisations - do you monitor network availability, sync on application startup/usage or do you have other business rules that drive when you synchronise.  Do you detect what type of network you are connected to and determine whether you should sync based on the cost of the network (see the Mobile Client Software Factory - Disconnected Service Agent and Connection Monitor blocks for quite a nice implementation of this)

Why having a Database Engine in ROM is a good idea

Yesterday I came across an interesting site dedicated to Mobile Synchronisation and noticed they had a post regarding Symbian and the fact that in the next version of their OS (v9.5) they will follow Microsoft's path of including a database engine (SQLLite fo Symbian, SQL Server CE for Windows Mobile) in ROM.

The author attempts to make the point that he doesn't understand why you would want to include a database engine in ROM, or a runtime such as .NET CF for that matter. They point out that you "still need to install your mobile application so what is the big deal of reducing your install size by a few 100KB?".  IMHO there are a couple of compelling reasons to include both the runtime and database engine in ROM:

  • Firstly it means that you don't need to package it with your application - although the size saving isn't that great, it is just another thing that you have to include in your installer (better that someone else deals with this). 
  • It also means that the database engine is only deployed once (since SQL Server CE can be deployed as a set of dlls, in theory you could have multiple applications all with their own instance of the database engine).
  • I think the most significant reason for including the runtime and database engine in ROM is to make the OS more appealing to developers.  If I know that all WM6 devices are going to be able to run my application because it has the runtime and db engine included then I am likely to target that device for any new applications.  This is similar to the decision to include the .NET Framework v3 in Windows Vista (in contrast to previous versions of Windows where the .NET Framework is an optional install).

I was also intrigued by the author's comment regarding the inclusion of SQL Server Express in [VS2005] a marketing ploy.  Perhaps it was but developers still have the choice as to whether it gets installed (as with other components of VS) and it does mean that developers don't need to worry about downloading/purchasing a database engine in order to build database applications.

Get your WCF on the run

Mark Prentice of the .NET Compact Framework team has just posted an introduction on how you will be able to work with the WCF-over-email solution that will come out as part of v3.5 of the .NET CF.  At the MVP Summit we saw this in action and enough to say it is way cool.  Although I can't see Steve getting all enthusiastic about using Sync Services across this binding, I think there is a huge potential here for organisations to start leaveraging their investment in Outlook/Exchange by building peer-to-peer messaging based applications.


BIG NEWS for TFS users - Microsoft Acquires DevBiz

Anyone working with TFS will be over the moon to know (as per Brian Harry's post) that Microsoft has just acquired DevBiz.  This is a significant gap stop in a fundamentally v1 product where simple web accessibility was not readily available.  Team Plain was almost a no brainer, despite the additional per seat cost.  Now with the Microsoft acquisition you have no excuse.  Of course, don't forget the per seat CALs you need to access TFS!

Must have coffee....

I'm glad to hear from various sources that the weekly coffee gathering we started a month or so ago is still going strong in my absence.  I just want everyone to know that I'm back in town and keen to catch up with everyone. 

Don't forget:

    Every Tuesday, 1:30pm @ Tiger Tiger

Visual Studio Refresher: Tools -> Options (2)

This post continues the discussion around the Tool -> Options screen in [VS2005].

[Goto to root post]

Environment - Add-in/Macro Security

Allow macros to run: Toggles whether macros are able to be created, edited or executed.  Disabling this option will immediately disable all macro menu items in the IDE (both under the Macros item in the Tools menu and the Macro Explorer under the View->Other Windows menu item).  Note that if the Macro Explorer is already open it will remain visible, at least until you restart the IDE

Allow Add-in components to load: This option toggles whether Add-ins can load or not.  Unfortunately it really depends on how well the Add-in is written as to whether they are visible or not.  For example the AnkhSVN component still appears in the Tools menu on my machine, however clicking any of the items does nothing. Note that this option also disable the Add-in Manager item in the Tools menu.

Allow Add-in components to load from a URL: Well as you can guess this allows add-ins to be loaded from a url - well duh!  I guess this option is there if you really want to shoot yourself in the foot ;-)

Add-in File Paths: This is a series of locations from which add-ins will be loaded (assuming Add-in components is enabled).  By default there are a series of predefined locations:

%ALLUSERSPROFILE% - C:\Documents and Settings\All Users\Application Data\Microsoft\MSEnvShared\Addins

%APPDATA% - C:\Documents and Settings\<username>\Application Data\Microsoft\MSEnvShared\Addins

%USERPROFILE% - C:\Documents and Settings\<username>\My Documents\Visual Studio 2005\Addins

%VSAPPDATA% - C:\Documents and Settings\<username>\Addins

%VSCOMMONAPPDATA% - C:\Documents and Settings\All Users\Addins

You can of course add your own or remove these at will to control where add-ins are loaded.

OpenNETCF - Quiet but not stagnant

Anyone working in the .NET CF space will know that the team at OpenNETCF have been leading the way with their Smart Device Framework.  In v1 of the .NET CF the SDF was essential to have any reasonably functioning application.  Now with v2 the SDF is less essential, but you still quickly hit the limitations of the .NET CF. 

Recently Chris has posted about the new LargeIntervalTimer class that is coming in v2.1 of the SDF. A challenge faced by device developers is periodically waking the device up to say synchronise, poll for changes or do some other task.  When a device is in standby mode your managed code doesn't get an opportunity to execute so you can't rely on normal timers.  You actually need to hook the OS and to do that gracefully you really need the elegance of the SDF - check out the post for the code!

Personally I can't wait for them to release v2.1 so I can start working with the new additions.

VB9 Features

I've just noticed, care of Bill and Beth, that the VB9 features article has been updated as of February this year.  After a quick scan there are some clear changes that look great (and some that don't)!

Object Initializers

Dim c as New Country With { .Name = "Palau", .Area = 458, .Population = 16952 }

What I like about this notation is that it follows the VB tradition of using the With statement.  Previously you would have written:

Dim c as New Country()
With c
End With

The new notation is particular efficient if you want to initialise a collection of Country objects as each object can be instantiated and properties set in a single statement. For example:

Dim countries = { _
   New Country With { .Name = "Palau", .Area = 458, .Population = 16952 }, _
   New Country With { .Name = "Monaco", .Area = 1.9, .Population = 31719 }, _
   New Country With { .Name = "Belize", .Area = 22960, .Population = 219296 }, _
   New Country With { .Name = "Madagascar", .Area = 587040, .Population = 13670507} _

Implicity typing

In the last section you will have noticed that I didn't specify the type of the countries collection.  This is NOT because I haven't allowed VB.NET to run riot, it is because we have implicit typing.  This defines countries to be of type Country(). Why, because the right hand side defines an array of Country objects - we can see that, and now the compiler can too.

WARNING: To all those developers (including C# developers using the new var keyword) out there who are going to start using this feature throughout their code you are as bad as those VB6- developers who used Variant objects, or for that matter .NET developers who use object objects cause they can't be bothered getting it right.  The reason for this is that it makes your code harder to read and understand - you can't just read the variable declaration and know what type it is, instead you have to dissect the right hand side.  The ONLY time IMHO that implicit typing should (and in fact sometimes has to) be used is in a Linq statement.


Yeh, yeh, yeh - by now I'm hoping we have all heard, if not seen, Linq.  So just for clarrification we are talking about:

Dim smallCountries = From country In countries _
                                  Where country.Population < 1000000 _ 
                                  Select country

Of course it goes without saying that this is fundamentally cool! Before we go further though, it is worth noting that smallCountries is an IEnumerable(of Country) - if you aren't comfortable with Interfaces, now would be great time to begin using them!

Lambda Expressions


Function(Country As Country) country.Name
Function (Country As Country) country.Population < 1000000

These can be written as inline (like mini-anonymous methods) such as:

Dim smallCountries = _
   Enumerable.Select( _
      Enumerable.Where(countries, _
         Function (country As Country) country.Population < 1000000), _ 
      Function(country As Country) country.Name

IMHO this is probably one of the weakest of the new features available in VB9.  The VB.NET community has long been asking for both anonymous methods and interators.  Instead of giving us C#2.0 feature parity the team has leap frogged into Linq giving us only minimal lambda expressions.  Luckily this will only affect the hardcore developers out there who are building collections and doing fancy framework development (damn, looks like I might have to go back to C# afterall).

Nullable Types

Ok, so we have seen this before but this time we have the ? syntax, just like C#v2:

Partial Class Country
   Public Property Independence As Date?
End Class


There are a bunch of other features such as XML support and Relaxed delegates that didn't make this blog post.  I'd encourage you to read the full article and be prepared.  These features, especially IMHO Linq, are going to have more impact than Generics did!

Snippets and Stored Procedures

Mitch has posted a simple snippet that shows how you can work with stored procedures in C#.  I figured that I'd firstly translate this to VB.NET: 

' Execute a stored proc to read data
Using conn As New SqlConnection(connectionString), _
          cmd As SqlCommand = conn.CreateCommand()

   cmd.CommandText = "ProcName"
cmd.CommandType = CommandType.StoredProcedure

   ' Add any input Params...
cmd.Parameters.AddWithValue("@SomeIDParam", myID)

   ' Assuming Stored Proc returns a set of records...
   Using rdr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
      While rdr.Read()
' do something with each rdr row ...
End Using

Now that we have this snippet it would be great if we could add this to the [VS2005] snippets.  The best way to do this is to grab the Snippet Editor from GotDotNet (not sure where this link will go when they close it down later this year, but oh well). 

Running the Snippet Editor will display a tree on the left which shows all the snippets which are currently in VS2005.  If you right-click one of the nodes you can "Add New Snippet".  You then have to give the snippet a name; in this case we use "Simple Stored Proc".  After creating the snippet you need to double-click it on the tree to open it in the edit window, as shown below (I've filled in some of the information textboxes on this screen).

At the moment the snippet is a great way to reduce the amount of code you need to write but doesn't really highlight the parts of the snippet that you need to replace.  For example it is unlikely when you use this snippet that you will be calling a stored proc with the name "ProcName".  To improve this snippet we can add replacements which will identify areas of the snippet that need to be replaced when the snippet is used. 

Using the Replacements tab of the editor is relatively easy.  You simply select the text in the edit window that you want to make a replacement (eg "ProcName") and select the + (Add new) button on the navigation bar.  This will allow you to spectify a name, default replacement and much more.  Once you are done your snippet editor window might look like the following:

For my snippet I've also added System.Data.SqlClient to the Imports tab and System.Data to the References tab.  This will ensure that appropriate imports and references are added to the project when this snippet is used.

Don't forget to click "Save" when you are done!

Lastly if you want to share this snippet with others in your team (or on your blog) you can click Export which will create a Visual Studio installer.

Test Your Knowledge of Visual Studio 2005

In case you haven't already guessed from the fact that this is my fourth post today I'm currently sitting in Heathrow airport on my way back to Perth. I must quickly add that this is the first time I have travelled around the world on the "One World" alliance and have been pleasantly surprised.  The two reasons I switched was because there is no local Star Alliance partner flying internally in Australia, and I now have Qantas Club membership.  The latter is probably more significant at the moment as it meant I was able to jump the 1 hour check-in line and the 30 minute security line - today was crazy in departures according to the staff. This said, I would avoid both American Airlines and Chicargo airport like the plague!

Ok, so now to the point of this post - One of the issues I'm seeing as more and more designers are added to [VS2005] is that there are an increasing number of "options" in the Tools->Options screen.  Thankfully the options screen is fairly accommodating and each new feature can have its own node, or sub-node, in the tree.  The question is whether you as a developer a) know these options are there and b) can find them.  So, I thought I would put my knowledge of VS to the test and go through each "option" and see if I can describe what it does. Note that each parent node simply displays the contents of it's first child, so for the purposes of this exercise they have been ignored....[This may span multiple posts, so hang in there]

Environment - General

Window layout: [Tabbed documents | Multiple documents] This controls how documents are rendered within the document (or main) area.  In the Tabbed case all documents reside in the same area; the user can switch between documents using the tabs along the top (and the dropdown at the end of the top bar). On the other hand the Multiple document layout is your traditional MDI child layout; each document appears as a separate window within the document area; windows can be tiled or arranged. In most cases the Tabbed case is preferred as you can achieve a similar effect to the Multiple layout by spliting the screen (horizontal, vertical or both). Note that even in Tabbed layout mode documents are treated as windows for the purposes of selecting the active Window using the Window menu.

Recent files - [1-24] items shown in Window menu: The number of documents shown at the bottom of the Window menu (above the "Windows..." option that opens a window selection dialog showing all open documents).

Recent files - [1-24] items shown in the recently used lists: The number of documents/projects that will appear in the recently used lists, namely the File->Recent Files and File->Recent Projects lists.

Show status bar: This usually appears in the View menu but since that menu is too busy with the numerous design windows (eg Solution Explorer, Toolbox) available in VS this option has been relegated to the options screen.  It toggles the status bar at the bottom of the VS window.

Close button affects active tool window only: For example the standard configuration is for the Solution Explorer, Class View and Properties Window to be grouped together on the edge of VS.  If this option is checked clicking the close button will only close the currently visible window.  Unchecked, all three windows would be closed.

Auto Hide button affects active tool window only: Similar to the previous option this controls the behaviour when you click the "pin" to hold an expanding window in place.  If this is checked then only the active window will be pinned/released when the pin is clicked.

Animate environment tools: This controls whether, and the speed if enabled, the tool windows are animated when they appear/disappear.  If VS is taking a while to open/close tool windows it is advisable to turn this off (in fact in 99.999% of times animation is just a PITA, so just turn it off anyhow).

Restore File Associations: In case you have assigned file types such as .cs or .vb (and a heap of others) to some other application this button allows VS to reassign them back to the defaults.  Unfortunately, unlike other applications that lets you know which file types it will affect, or even present you with an option as to which file associations you want, VS assumes it knows best and just goes ahead and does it.

Well, that was the General node of Environment; there are only like 100 or so more to do.... plenty of stuff to do on the plane.  For now I'm going to enjoy a glass of wine, some dinner and read a book before my flight.


     Environment - Add-in/Macro Security

Are Device Developers Second Class Citizens?

Some of you may remember that when [VS2005] shipped I had a few words to say about the fact that the Windows Mobile 5 SDK(s) weren't in the box.  Of course these decisions come down to what will/won't fit in the box (well on the ISO as in this case). With the release of the Windows Mobile 6 SDKs and VS Orcas just around the corner, will device developers have to download 2 SDKs if they want to work with both platforms?  The irony here is that at the core they are the same version of Windows CE, so IMHO there should be a single project type that handles both OS types!

Another interesting (but almost useless) bit of trivia is regarding the Remote Tools that are available for device developers.  I've often wondered why these are in the Start menu (Start->Programs->Microsoft Visual Studio 2005->Visual Studio Remote Tools) and not in the External Tools section under Tools within Visual Studio. Turns out this is another packaging decision: In order to ship within Visual Studio the tool must be available in all 9 languages that Visual Studio ships in.