TOP

Getting Started with Live Framework

Abstract: Get a quick introduction on how you can start interacting with the Live Framework APIs using the SDK made available on the Microsoft Connect site.

Note: You need access to the Microsoft Connect program to download the Live Framework SDK that will allow you to interact with the Live Framework (and Live Mesh) APIs.

What is the Live Framework?

The Live Framework consists of three main components. They are as followed:

  1. The resource model: REST APIs that gives you access to Live Mesh and Windows Live information.
  2. API libraries: Libraries for .NET, JavaScript and Silverlight that makes it easier to communicate with the REST APIs.
  3. The Live Operating Environment: The local instance of the Live Mesh that runs on your computer and hosts the REST APIs.

To read more about the basics of Live Framework, check out the MSDN Documentation.

LiveFrameworkResources

Above diagram (taken from the MSDN documentation) shows the resource model. The following example will demonstrate how you can connect to the Mesh Operating Environment and iterate over all your Mesh devices and using the same codebase show how you can iterate over all your Live Contacts.

Create Your Project

The first thing you need to do is create a new Visual Studio project. For the purpose of this post we’ll create a new Console application. If you have followed the installation instructions for Live Framework SDK, you should have tree .NET assemblies in the following folder: C:\Program Files (x86)\Microsoft SDKs\Live Framework SDK\v0.9\Libraries\.Net Library

Add a reference to all the assemblies in that folder, Microsoft.LiveFX.Client.dll, Microsoft.LiveFX.ResourceModel.dll, Microsoft.Web.dll. Additionally you need to add a reference to the WindowsBase.dll, which you can find in the .NET tab in the Add Reference dialog.

Copy the following example code into your Program.cs and replace the existing Main method.

static void Main(string[] args)
{
    Console.WriteLine("Fill out Live ID:");
    string username = Console.ReadLine();
    
    Console.WriteLine("Fill out password:");
    string password = Console.ReadLine();

    Connect(username, password);

    Console.WriteLine("");
    Console.WriteLine("Your Mesh Devices:");

    foreach (var device in _environment.Mesh.Devices.Entries.ToArray())
    {
        Console.WriteLine("{0}: {1}", device.Resource.Type, device.ToString());
    }

    Console.WriteLine("Press any key to exit.");
    Console.ReadLine();
}

Secondly, you need a few using statements in the top of your file, some private fields and an utility method that will connect you to the Live Mesh.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.LiveFX;
using Microsoft.LiveFX.Client;
using Microsoft.LiveFX.ResourceModel;
using System.Net;
using Microsoft.Web;
using Microsoft.Web.Clients;
using System.IO;
using System.Collections.ObjectModel;
using System.Runtime.InteropServices;
using CommunicationsConsole.Properties;
using Communications.Common;

The Connect method that you should include in your Program.cs file.

private static LiveOperatingEnvironment _environment;
private static string _meshUrl = @"https://user-ctp.windows.net";

private static void Connect(string Username, string Password)
{
    Uri meshCloudUri = new Uri(_meshUrl);

    NetworkCredential credentials = new NetworkCredential(Username, Password);

    LiveItemAccessOptions accessOptions = new LiveItemAccessOptions(true);

    _environment = new LiveOperatingEnvironment();
    _environment.Connect(credentials);
} 

And that’s it, you can test your application by pressing F5 and see how your console application connects to the Live Mesh. Beware: The above example will display your password in clear text in the console application. In the source code for this post, there is code that will mask the password input.

LiveMeshConsole

What’s Next?

If you take another look at the resources diagram, you might come up with some ideas on what to do next. My next example shows you how simple it is to iterate over all your Windows Live Contacts once you’ve established the connection.

There is only one problem with my example here, the API call seems to only return 99 contacts. While debugging I found a possible clue that it’s doing paging, but I’m not sure how to actually query the Live Framework with the paging support. Maybe if I changed my code to use LINQ instead of a normal loop?

Edit: I found a solution to the problem with good help from Angus Logan at the Windows Live Team. You can use the .Take method to return more than the initial 99 contacts. The updated foreach is visible below.

This is how you can iterate over your contacts and display their names and Live IDs (e-mail address).

foreach (var contact in _environment.Contacts.Entries.Take(_environment.Contacts.Entries.Count()))
{
    Console.WriteLine("{0}: {1}", contact.Resource.DisplayName, 
contact.Resource.WindowsLiveId); }

There is a big lack of documentation, examples and walkthroughs for Live Framework SDK. It’s a very new technology so it’s not easy to find good resources yet. I hope this post was helpful for you and inspired you to take a look at the Live Framework SDK.

Live Framework Sample by Sondre Bjellås is licensed under a Creative Commons Attribution 3.0 Unported License.

Creative Commons License

Leave a Reply

Your email is never published nor shared.

You may use these HTML tags and attributes:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>