Using the Mesh With Synchronization When Offline

By now you’ve probably at least heard of Microsoft’s “Live Mesh” – a virtual network of your platform-agnostic devices (computers, phones, PDAs, etc) that all sync with the same data via the internet.  Live Mesh is part of Microsoft’s larger “Azure Services Platform” which is their version of “the cloud”, providing internet-scale services hosted at MS data centers.

At PDC this past year, Microsoft released the first tech preview of the Live Framework (one of 4 pieces of the larger Azure Services platform) which allows you to write code against the Live Mesh, enabling you to read and write data to the mesh itself, and write apps that are aware of the mesh data, and take advantage of its inherent synchronization, making data available to all the devices in your mesh, without you writing a single line of synchronization code!

There are a couple different approaches to writing an app that talks to the mesh, the most compelling of which I think is the “Live Framework Silverlight Mesh-enabled Web Application“.  Whew – that’s a long winded way to say the following:  Write a Silverlight control that would normally be hosted in a normal browser, but that is instead registered as a “Mesh application”, that can then be run via the Live Mesh Apps portal (part of the Live Mesh Desktop)

Here is a screenshot of my browser sitting on the Apps page, showing me the Silverlight Mesh-enabled web apps that I have installed. 


These “applications” have been installed in my Mesh and are ready to run.  (The Collaborative Crossword is one that is published by MS for anyone to use.  The other 2 are apps that I have published when playing with the Live Framework SDK.)

So now hopefully you can see the power of these Mesh apps that can run on any device that can show Silverlight content.  Create apps that store their data in the Mesh and you automatically have a network/synchronization aware app.  When you create one of these Silverlight Mesh-enabled web apps, the project is already setup to communicate directly with the mesh.

public Page(){    InitializeComponent();

    // Extension method to get a hold of the MeshApplicationService    _meshApp = Application.Current.GetMeshApplicationService();

    // once mesh contents are loaded we get callback and we're ready to party    _meshApp.LoadCompleted += new EventHandler( meshAppLoaded );    _meshApp.Load();}

// Called when mesh application loadsvoid meshAppLoaded( object sender, EventArgs e ){    // Mesh application service object is now loaded and usable.    Mesh mesh = LiveOperatingEnvironment endpoint = meshApp.LiveOperatingEnvironment;

    // do something with the data objects you've stored in the mesh for this app    foreach (MeshObject mo in mesh.MeshObjects.Entries)    {        string title = mo.Resource.Title;        // ...    }}

In the code above, you are given the MeshApplicationService, from which you can get the Mesh object, and iterate over objects stored in there, add new objects, etc.  (Someday I’ll write more about exactly how you read/write objects).

OK – so now the super powerful part:  When you register/install the application in your Live Mesh Apps workspace, you also get an icon on your Windows Desktop that represents the same app, only it runs the Silverlight control in a local shell application and communicates with a local instance of the mesh running on your machine!


So this icon on your Windows desktop runs the Silverlight content in a shell app running in Windows called “MeshAppHost.exe”  with a parameter to tell it what app to run (the apps themselves are stored in the mesh as well, so this shell just retrieves the Silverlight bits and runs them).

The coolest thing about this local running shell app, is that it is communicating ONLY with the local instance of the Mesh running on your machine, and is therefore fully functional while YOU ARE OFFLINE!   Since your app presumably updates data in the mesh, those are done locally, and then whenever you are back online, the mesh runtime will sync the changes up to the internet mesh and over to whatever devices are registered.

So there you have it!  Not only Silverlight running outside of a browser on the local machine, but reading/writing data via the mesh while offline that gets sync’d whenever you are back online.

A couple notes about when you’re running offline:

  • At some point before you try to run offline, you must have successfully logged into the Mesh (via the system tray / login tool) and be sure to select “Remember me”  and “Remember my password”.  Your credentials are then cached in the locally running mesh to authenticate when you’re offline.
  • So far, I have only found one difference in the way you have to access objects in the mesh when offline.  Instead of loading objects “on demand” when you ask for them, you need to explicitly load them:
// if offline, the for-loop below will not work unless you // explicitly Load() them firstmesh.MeshObjects.Load();

foreach (MeshObject mo in mesh.MeshObjects.Entries){    // ...}

If you need to know in the code if you are connected locally or online, you can use this:


Have fun writing multi-device, multi-platform synchronization aware, offline capable apps — as simple as writing a Silverlight control.

p.s.  To get started writing these Mesh-enabled apps, you need to download the Live Framework SDK.  MS is slowly allowing more and more devs access to the SDK.  Start here and request a token which they’ll send you in email.  (When registering, be sure to specify the “Live Framework” API in the ComboBox about what you’re interested in.)

Leave a Reply

Your email address will not be published. Required fields are marked *