Windows Phone 7 Background File Transfer

Mobile applications by their nature need to be able to work disconnected from their central data source. If you force users to always have an internet connection to use your app, you’re doing it wrong. For Inspire this is especially true since our users do amazing things like help victims after earthquakes or clean up the mess hurricanes leave behind, and they can’t rely on the internet always being there.

The downside to working offline, is downloading all of a users information to their device can take a long time. There are many strategies to deal with this issue, and the one we chose to implement is supported natively on the Windows Mobile platform – Background File Transfer. Basically it’s an API for you to make asynchronous HTTP(S) GET and POST requests.

We’re using it to asynchronously fetch our users contact information, groups, tags, etc. This can be a lot of data but since we’re backgrounding the download, we can allow users to interact with their contacts, meanwhile updating information from the server in the background.

Microsoft has a helpful “getting started” article that we followed when initially spiking on this. It’ll give you the gist of what it takes to interact with the API.

The article can get a little complicated because it’s trying to do too much. To clear that up a bit you really only need to focus on the code that does this:

// This happens to be a .json file
string transferFileName = "";
Uri transferUri = new Uri(Uri.EscapeUriString(transferFileName), UriKind.RelativeOrAbsolute);
BackgroundTransferRequest request = new BackgroundTransferRequest(transferUri);
request.Method = "GET";

// Decide where you'll download the file to
string downloadFile = transferFileName.Substring(transferFileName.LastIndexOf("/") + 1);
Uri downloadUri = new Uri("shared/transfers/" + downloadFile, UriKind.RelativeOrAbsolute);
request.DownloadLocation = downloadUri;

// set preferences about when the transfer should perform the transfer
request.TransferPreferences = TransferPreferences.AllowCellularAndBattery;

     // This queues your background request.
} catch(Exception e) {
     // This could fail so you'll want to handle exceptions

After that you’ll have a request waiting to be processed.


DataTemplate and PhoneApplicationPage.Resources Gotcha

When building an interface for a windows phone 7 mobile app you may want to use what are called DataTemplates to build your UI in chunks. Something like a list of accounts, you might want to create a DataTemplate to represent the singular Account within in the UI and bind it to a single ‘Account’ Model. In most fo the examples I found online about this they all displayed the DataTemplate XAML but never in context. Well it turns out you can’t just add those anywhere.

DataTemplate is expected to live into a tag named PhoneApplicationPage.Resources. which lives inside your top level PhoneApplicationPage XAML tag.

So it should look like this:

Day 1 Bonus Video

Some fly-on-the-wall videos of the initial meeting, team planning, story mapping, and thoughts from the developers and designers.


Install git for Windows

If you need to install git for windows (which you will if you are a software developer building Windows Phone 7 apps) then you will want to download this:


Update: I was also looking for a GUI for Git to replace Gitx. There seems to be a few like TortoiseGIT, but I opted for GitExtensions:

Windows Mobile Developer Setup

Here are the things you will need to get started building a windows mobile app.

1. Windows 7 (Link)

For this I’ll be using VMWare Fusion since I’m on a mac.

2. Zune Software (Link)

This is like having iTunes. I’ll be installing version 4.8

3. Windows Phone Developer Tools (Link)

This is a custom version of Visual Studio as far as I can tell. According to Microsoft:

The Windows Phone Software Development Kit (SDK) 7.1 provides you with all of the tools that you need to develop applications and games for both Windows Phone 7.0 and Windows Phone 7.5 devices.

With this stuff installed you should be able to write a simple hello world app.