Welcome to EMC Consulting Blogs Sign in | Join | Help

SSIS Junkie

Recursing hierarchical DataEntries : Live Framework

When you add a folder to Live Mesh it is represented programmatically in the Live Operating Environment (LOE) as a MeshObject. When I first started prodding and poking at the Live Framework (aka LiveFX) I assumed that the Mesh was represented as a hierarchy of these MeshObjects i.e. Every subfolder was also represented as a MeshObject. Take the following folder structure:

image

I would have assumed that the objects:

  • “Top level folder”
  • “subfolder1”
  • “subfolder2”
  • “file in subfolder2.txt”

would all be MeshObjects, they would be represented in the LOE hierarchically and that I would be able to traverse that hierarchy using LiveFX just as we do with any hierarchical structure such as an XML DOM. How wrong could I be!

Here we can see within Visual Studio’s Intellisense that that is not actually the case.

image

[N.B. This screenshot was taken whilst using an earlier version of the Live Framework than that released at PDC 2008 so not everything you see here may exist today but is still relevant for this blog entry]

There’s a lot going on in this screenshot so let me try and break it down a bit.

  • We are examining a DataFeed, called dataFeed, within our MeshObject called meshObject (which, you’ll have to trust me, is “Top level folder” that you see in the screenshot at the top of this blog entry)
  • dataFeed contains a list of every item in meshObject regardless of hierarchical position. The hierarchy has been flattened into a list of 3 MeshItems: {“file in subfolder2.txt”, “subfolder2”, “subfolder1”}. Again, you can see each of these in the screenshot above.
  • Each item has a Resource which has a ParentId property which links to the immutable Id property of its parent item

Phew, quite a mouthful. The main point of all of this is that the contents of a MeshObject are not represented hierarchically, instead they are represented as an adjacency list which is a method of storing hierarchical relationships that is commonly used within relational databases. Adjacency lists are well known to database pros, further proof that the answer to my question Are database pros relevant on the RESTful web? is a resounding YES!.

 

 

 

Its worth knowing about this structure before you start out developing with LOE and LiveFX. I initially assumed that everything would be represented hierarchically and started out trying to write a function that would recursively print out the contents of my Mesh by iterating over it as a if it were stored hierarchically – I lost a good few hours doing that. My assumption was based on the fact the Mesh user experience thus far has been all about folders and files within those folders; that is a structure which is naturally hierarchical. Realise though that the Mesh experience is simply one application on the LOE, most applications will not require a hierarchical data store therefore it would be inappropriate to organise the dataentries as such; instead hierarchical structures are provided for using a Rescource’s ParentId property.

In order to demonstrate this let me show you the code for the simplest Mesh app you will ever see. Its a .Net console app that recurses over every DataEntry in every DataFeed in every MeshObject and outputs its Title to the command-line.

using System; using System.Linq; using System.Net; using Microsoft.LiveFX.Client; class Program { static void Main(string[] args) { NetworkCredential creds = new NetworkCredential("username", "password", "https://user-ctp.windows.net/"); LiveOperatingEnvironment livefx = new LiveOperatingEnvironment(); livefx.ConnectLocal(); Mesh mesh = livefx.Mesh; foreach (MeshObject mo in mesh.MeshObjects.Entries) { foreach (DataFeed feed in mo.DataFeeds.Entries) { //Recurse from ParentID of root level DataEntry RecurseFeed(feed, "urn:uuid:00000000-0000-0000-0000-000000000000"); } } } private static void RecurseFeed(DataFeed feed, string parentID) { var query = from entry in feed.DataEntries.Entries where entry.Resource.ParentId == parentID select entry; foreach (DataEntry entry in query) { Console.WriteLine(entry.Resource.Title); RecurseFeed(feed, entry.Resource.Id); } } }

Admittedly this won’t do very much right now because in the current release of the client file syncing is not enabled:

image

but the code is fine and should produce meaningful results in the future. An earlier release of the developer client DID support file sync and hence produced much more meaningful results when this code was ran; I’ll talk about that in my next blog entry.

Hope this proves useful.

-Jamie

If you want to read more about what I have to say about Live Framework head to http://blogs.conchango.com/jamiethomson/archive/tags/Live+Framework/default.aspx

Comments

 

Dew Drop - November 4, 2008 | Alvin Ashcraft's Morning Dew said:

November 4, 2008 13:08
 

Jason Haley said:

November 4, 2008 14:08
 

SSIS Junkie said:

When we talk about Live Mesh as being something that be connected to programmatically we talk about the

November 24, 2008 19:57
 

Live Framework CTP #4 - .NET: LOE and data basics - .NET ... out of the dark said:

December 14, 2008 19:11
New Comments to this post are disabled

This Blog

Syndication

Powered by Community Server (Personal Edition), by Telligent Systems