Export (0) Print
Expand All

DataContext Class

Ff749151.note(en-us,MSDN.10).gifNote:
Current information about Live Connect is now available in the Windows Live Developer Center. The information in the following sections is provided for legacy purposes only.

A class that represents the main entry point to access user data in Windows Live.

Script:  http://js.live.net/4.1/loader.js
Feature:  Microsoft.Live.Services
Namespace:  Microsoft.Live.Services
 
Ff749151.alert_note(en-us,MSDN.10).gifNote

The JavaScript Library for Windows Live Messenger Connect is built by using the Microsoft Ajax Library. Microsoft Ajax exposes a type system that enables you to add object-oriented capabilities to your JavaScript code. To learn more about creating, instantiating, and deriving from classes, see Creating Custom Client Script by Using the Microsoft Ajax Library.

Microsoft.Live.Services.DataContext = function();

Type.registerClass(
    'Microsoft.Live.Services.DataContext',
    null,
    Microsoft.Live.IDataContext);

An instance of DataContext is available from the dataContext property of the App class.

The following example demonstrates how to get an instance of DataContext from the App class dataContext property and how to load contacts. After the application has loaded, a sign-in function is called. When the sign in is completed, a data context is available.

var sb = "", outputElem, dataContext;
function appLoaded(applicationLoadCompletedEventArgs) {
    Microsoft.Live.Core.Namespace.using("wl:Microsoft.Live");
    wl.App.signIn(signInComplete);
    outputElem = $get("Output");
}

function signInComplete(signInCompletedEventArgs) {
    if (signInCompletedEventArgs.get_resultCode() !== Microsoft.Live.AsyncResultCode.success) {
        alert("Sign in failed.");
        return;
    }
    else {
        dataContext = Microsoft.Live.App.get_dataContext();
        dataContext.loadAll(Microsoft.Live.DataType.contacts, contactsLoaded);
    }
}
function contactsLoaded(dataLoadCompletedEventArgs) {
    if (dataLoadCompletedEventArgs.get_resultCode() !== Microsoft.Live.AsyncResultCode.success) {
        alert("Contacts failed to load.");
        return;
    }
    contactsCollection = dataLoadCompletedEventArgs.get_data();
    var contact;
    for (var i = 0; i < contactsCollection.get_length(); i++) {
        contact = contactsCollection.get_item(i);
        sb += contact.get_firstName() + ", " + contact.get_lastName() + "<br/>";
    }
    outputElem.innerHTML += sb;
}

Object
  Microsoft.Live.Services..::.DataContext

Windows Live Messenger Connect

Supported in: 4.1

Internet Explorer 8.0, Internet Explorer 7.0, Internet Explorer 6.0, Firefox 3.6, Firefox 3.5, Firefox 3.0, Firefox 2.0, Firefox 1.5, Chrome 4.0, Chrome 3.0, Chrome 2.0, Chrome 1.0, Safari 4.0, Safari 3.0

Show:
© 2014 Microsoft