In the post on Data Storage in the Live Framework I suggested that syndication links stored in the Resource.Links property could be useful for linking data entries and data feeds together in interesting ways. There remains the task of using the syndication link URLs stored in the Links property for something useful.
A syndication link is nothing more than a URL so the issue is how to use the Live Framework API to retrieve the resource at that URI and turn it into something useful. Oran Dennison provides code on a forum thread demonstrating how to do this.
There appears to be different solutions depending on whether a feed or an entry is being retrieved. The AtomPubClient class shipped with the Live Framework API can be used to retrieve an entry in the form of a SyndicationItem which can then be converted into an instance of the appropriate Resource-derived class. The ResourceQuery<TEntry> class shipped with the Live Framework API can be used to retrieve a feed in the form of an IEnumerable<TEntry> where TEntry is derived from Resource.
A sample of code demonstrating both of these techniques is:
// Setup the authentication context
NetworkCredential networkCredential = new NetworkCredential(Constants.UserName, Constants.Password);
SyndicationOperationContext syndicationOperationContext = new SyndicationOperationContext(typeof(SyndicationItem));
syndicationOperationContext.Authorization = networkCredential.GetWindowsLiveAuthenticationToken();
// Retrieve a specific mesh object as an Atom <entry>
Uri syndicationItemUri = new
SyndicationItem syndicationItem = AtomPubClient.ReadEntryResource(syndicationItemUri, syndicationOperationContext);
MeshObjectResource meshObjectResource = new MeshObjectResource(syndicationItem);
// Query MeshObjects and retrieve those with title of "Perec" as an Atom <feed>
Uri meshObjectResourceUri = new Uri("https://user-ctp.windows.net/V0.1/Mesh/MeshObjects/?$filter=(Title eq ‘Perec’)");
ResourceQuery<MeshObjectResource> meshObjectQuery =
new ResourceQuery<MeshObjectResource>(networkCredential, meshObjectResourceUri);
IEnumerable<MeshObjectResource> meshObjectResources = meshObjectQuery.Execute();
This provides access to a MeshObjectResource or an enumerable collection of them. A similar technique can be used to access the other types of resource stored in the live operating environment. Note that the order of the network credential and the resource URL is swapped between AtomPubClient.ReadEntryResource() and ResourceQuery<MeshObjectResource>(). Note that query modifiers like filters, as in this example, can be used with ResourceQuery<TResource>() but NOT with AtomPubClient.ReadEntryResource().
Unfortunately, these resources are not hooked into the Mesh hierarchy of MeshObject, DataFeed and DataEntry all connected to the live operating environment via the Live Framework .Net API. For example, you can create a MeshObject from the MeshObjectResource retrieved as above but you cannot update it because it is not directly associated with the live operating environment and there is no way to associate it with the live operating environment.
This means that while storing syndication links in Resource.Links looks promising as a means of associating mesh objects, data feeds and data entries, the practical reality is that it involves creating a parallel world of Resources unconnected to a Mesh/MeshObject/DataFeed/DataEntry hierarchy provided by the Live Framework .Net API.
Ideally, there would be a method on Mesh similar to:
public TEntry LoadLiveItemFrom<TEntry>(Uri url) where TEntry : new(), LiveItem;
However, I suspect the constraint of a RESTful interface retrieving a single resource would probably make this a bit gruesome internally.