Since late 2008, I have been spending a lot of time focusing on Microsoft’s Live Framework and Mesh technologies. Towards this end, I have produced a Power Live Framework library that simplifies coding against the Live Framework. And, I have also put together some sample applications that leverage my library. Furthermore, I have set up a Yahoo news group in order to support people that wish to use my library and sample code. The files and news group can be found here: http://tech.groups.yahoo.com/group/PowerLiveFx/.
The purpose of this blog post is to help you get started with programming for the Live Framework using my class library. For more information on the Live Framework in general, what it offers, and the concepts that surround it, I encourage you to see some of the videos from Microsoft’s PDC. Also, I will be speaking about Live Framework programming at Wintellect’s own Devscovery conference.
To develop against the Live Framework, you must:
· Provision your account:
o Go to https://lx.azure.microsoft.com/Cloud/Provisioning/Default.aspx
o From “New Project” page, click "Activate Live Framework CTP“
· If you want to access the Live Framework locally (not via the Internet), then download & run the developer client Live Operating Environment:
o Go to https://developer.mesh-ctp.com/
o Sign In, select “Add Device” and then install the client Live Operating Environment.
o Then run “C:\Users\Jeffrey\AppData\Local\Microsoft\Live Framework Client\Bin\MeshAppMonitor.exe”.
o Sign in with the client (see tray icon), and add your computer to your developer mesh.
· Download Microsoft’s developer SDK (& Tools)
o Go to https://developer.mesh-ctp.com/Developers/Developers.aspx
o Then, in your Visual Studio projects, reference Microsoft.Web.dll and Microsoft.LiveFx.ResourceModel.dll. These DLLs can be found in “C:\Program Files (x86)\Microsoft SDKs\Live Framework\v0.91\API Toolkits\.Net Library”. Do NOT add a reference for Microsoft.LiveFx.Client.dll as my Wintellect.LiveFx.dll is a replacement for this library.
o For some projects, you will also need to add System.ServiceModel.Web.dll (included with the normal .NET Framework).
Some words about building you code with my Wintellect.LiveFx.dll library:
· I produced my library because I wanted a lightweight, simple, stateless, and RESTful API for programming against the Live Framework. Microsoft’s Microsoft.LiveFx.Client.dll is stateful, does not allow multiple asynchronous operations to execute concurrently and is not in keeping with the RESTful nature of the Live Framework itself. Microsoft and I have been communicating about this and they have plans to change their API and possibly adopt my API directly or something like it.
· My library can be used for all kinds of rich .NET applications including Console, Window Forms, Windows Presentation Foundation, ASP.NET, WCF, etc. At this time, my library will not work with Silverlight due to limitations of Silverlight’s HttpWebRequest class (for example, it only supports GET & POST methods and I need PUT & DELETE too). I am monitoring this closely and fully expect to bring my library to Silverlight in the future.
· Since my Wintellect.LiveFx.dll library offers and implements many asynchronous operations, it depends on Wintellect’s Power Threading library (Wintellect.Threading.dll). In fact, if you start accessing the Live Framework asynchronously, then you may also find your own code benefitting greatly from the classes contained inside my Power Threading library. The Power Threading library can be downloaded from http://www.wintellect.com/Resources/visit-the-power-threading-library and there is a separate Yahoo news group available that supports this library: http://tech.groups.yahoo.com/group/PowerThreading/.
An introduction to libraries and type for programming against the Live Framework:
· The Live Framework uses a RESTful model where applications make HTTP POST (create), GET (read), PUT (update), & DELETE (delete) operations against the Live Framework servers in the cloud or against a local (or client machine installed) Live Framework “server”. The information interchanged using the AtomPub protocol.
· The Microsoft.Web.dll (included with the Live Framework SDK) contains types for low-level AtomPub data processing, serialization, and deserialization. For most people, this is too painful a level to program at.
· The Microsoft.LiveFx.ResourceModel.dll (also included with the Live Framework SDK) contains types that mirror the Resources that the cloud/client Live Framework “servers” expose. You should think of the classes defined in this DLL as being data containers. That is, they mostly contain properties. There are some methods that deserialize the wire-protocol text to an instance of a .NET type and there are also methods that serialize an instance of a .NET type to the wire-protocol text required by AtomPub. Effectively, the .NET types provide developers with IntelliSense support while writing code and also compile-time type-safety when using the properties.
· The Wintellect.Net.HttpRestClient class (provided by my Wintellect.LiveFx.dll) is a class that simplifies communication with any REST server. This class is not specific to Microsoft’s Live Framework at all. In essence, each method on the class internally does the following:
o Creates an HttpWebRequest
o Initializes the HTTP method and headers (which can have some specified defaults)
o Initiates a Create/Read/Update/Delete request & sends a payload synchronously or asynchronously
o Returns the HttpWebResponse
· Note that the state of an HttpRestClient object can change immediately after a request has been initiated; there is no need to wait for a response. This allows a single HttpRestClient object to be used for multiple asynchronous operations that execute concurrently. However, a single HttpRestClient object should not be used by multiple threads at the same time without performing your own thread synchronization. If you want to have multiple threads concurrently accessing a REST server, then create multiple HttpRestClient objects (they are very lightweight in terms of resource consumption).
· The Wintellet.LiveFx.LiveFxClient class (also provided by my Wintellect.LiveFx.dll) is derived from HttpRestClient. The LiveFxClient class is specific to Microsoft’s Live Framework. This class knows about Base Uris and authorization tokens. This class also knows how to perform CRUD operations while converting the wire-protocol data to an instance of a resource class and vice versa.
· The Wintellet.LiveFx.LiveFxExtensions class (also provided by my Wintellect.LiveFx.dll) is a static class (and therefore has no state). This class defines a bunch of methods that extend the resource classes defined in the Microsoft.LiveFx.ResourceModel.dll. These methods add the behavior to the data, so to speak. In effect, the extension methods, offer IntelliSense thereby suggesting what actions can be performed on a resource and what additional arguments you must pass in order to perform the action. You must always pass a LiveFxClient object as this contains the default request information (like authorization). Most of the extension methods return a deserialized resource or resource collection. If you desire, you can call HttpRestClient’s SveNextRequestResponse method and/or its SetNextRequestQuery method before making a request to store the HTTP response code/headers in a HttpRestClientResponse object or to set query filter information.
The sample applications:
· The LiveFxPatterns project is a console application that demonstrates how to perform various synchronous and asynchronous operations against Microsoft’s Live Framework using my Power Live Framework library. The operations include:
o Creating mesh objects, data feeds, and data entries (with and without media resources),
o Creating a directory structure with folders & files visible via the Live desktop (running in a browser)
o How to update a data entry.
o How to use query operators when reading resource data.
o How to add your own custom links to a resource.
o How to add and read custom data associated with a resource.
o How to map a mesh object to a device.
o How to invite a member to a mesh object.
o How to create a custom news item.
o How to subscribe to a resource and process change notifications for it.
· The LiveFxBrowser project is a Windows Presentation Foundation application that shows you the contents of a user’s Mesh using a tree hierarchy which allows for easy navigation. When you select a node in the tree, you get a window showing you the contents of the selected resource. The view is “cooked” to show you the data in a human readable format: simple data is shown first, followed by collections, followed by link Uris. If you prefer, you can see the same information in raw wire-protocol format (XML, RSS, Atom, or JSON). I've included a screen shot showing the “cooked” view of the data as an attachment.
· I am working with Wintellect’s own Andy Hopper to produce a real Live Framework application called “Wintellect Cloudboard.” This application allows you to copy and paste clipboard items to your mesh effectively putting them in the cloud (see how we got the name?). You can then invite others to your Cloudboard and share each other’s clipboard items. You will also receive notifications when new items appear in the Cloudboard. We have set up yet another Yahoo news group for this application (http://tech.groups.yahoo.com/group/Cloudboard/) and I encourage you to subscribe to it if you’d like to be notified when the application becomes available. Our goal is to eventually share the code for Cloudboard and discuss our programming efforts it in articles.On May 26 2009 3:19 PMBy jeffreyr