Lync 2010 SDK Development Models

Learn about the Microsoft Lync 2010 Controls and Microsoft Lync 2010 API development models in the Microsoft Lync 2010 SDK. You also learn about the unmanaged Microsoft Office Communicator Object Model (OCOM) API that is used to add contact and presence features to an application.

Use one of the Lync SDK development models to add communications and collaboration functionality to your application. By using the Lync SDK, you can add Microsoft Lync 2010 features to an existing business application, or create a custom client that includes Microsoft Lync 2010 features. In either case, Lync 2010 must be a running process on the client computer that hosts a Lync 2010 API application.

To add Lync 2010 features to an application, you drag XAML Lync 2010 Controls from the Lync SDK into a Microsoft Windows Presentation Foundation (WPF) or Microsoft Silverlight application. For more advanced scenarios, use a .NET Framework language to incorporate Lync 2010 API features into your application.

Lync 2010 API is generally used to start a new conversation within your custom application, after which you will participate in that conversation by using the Lync 2010 conversation window. You can also start and participate in a conversation within your custom application without displaying the Lync 2010 conversation window. Lync 2010 API can also be used to generate a contact list within your custom application by using data obtained from Lync 2010.

Lync 2010 Controls

You can drag Microsoft Lync 2010 Controls into existing business applications to add Lync 2010 functions and UI. Each Lync Control provides a specific feature like search, presence, IM calls, and audio calls. The appearance of each control replicates the Lync 2010 UI for that feature. Use a single control or multiple controls. The programming style is primarily XAML text. But you can also use C# in the code-behind file to access the Lync 2010 API and the .NET Framework. For more information, see Lync 2010 Controls.

Lync 2010 Controls Application Scenarios

  • Drag the PresenceIndicator control into each application, and then set property values to configure how the control displays presence and contact information.

  • Add Lync 2010 functionality to Silverlight 4 browser applications.

  • Add Lync 2010 capabilities to .NET Framework applications by using WPF.

Lync 2010 Controls Code Example

The following XAML text displays a PresenceIndicator control in a Lync Controls application. For more information, see Walkthrough: Presence Hello World.

<Window x:Class="myWpfApplication.UCWindow1"
    xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:Microsoft.Lync.Controls;assembly=Microsoft.Lync.Controls"
    Title="UCWindow1" Height="Auto" Width="Auto">
    <Grid>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
            
            <controls:PresenceIndicator 
                x:Name="Presence" 
                Source="sip:john@contoso.com" 
                PhotoDisplayMode="Large" 
                />

            <TextBlock 
                Text="{Binding DisplayName, ElementName=Presence}" 
                Margin="4,0,0,0" 
                VerticalAlignment="Center"
                />
        </StackPanel>
    </Grid>

</Window>

Lync 2010 API

Use the Microsoft Lync 2010 API to start and automate the Lync 2010 UI in your business application. Use Lync 2010 Controls to integrate specific features such as presence, contact cards, or search, in a business application. For more information, see Lync 2010 API Concepts.

Lync 2010 API Application Scenarios

  • Start an IM or audio conversation from a custom application.

  • Join or start a conference.

  • Add a new contact to your contact list.

Start Conversation Code Example

The following example starts an IM conversation by using the Lync 2010 API in the Lync SDK. For more information, see Walkthrough: Start an Instant Message Conversation (Lync 2010 SDK).

public Form1()
{
  InitializeComponent();
  // Create the major API automation object.
  Automation myUIAuto = LyncClient.GetAutomation();

  // Create a generic List object to contain a contact URI.
  // Ensure that a valid URI is added.
  List<string> inviteeList = new List<string>();
  inviteeList.Add("elise@contoso.com");


  // Create a generic Dictionary object to contain context objects.
  Dictionary<AutomationModalitySettings, object> myContextObjects = new Dictionary<AutomationModalitySettings, object>();
  myContextObjects.Add(AutomationModalitySettings.FirstInstantMessage, "hello");
  myContextObjects.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true);

  // Start the conversation.
  IAsyncResult ar = myUIAuto.BeginStartConversation(AutomationModalities.InstantMessage, inviteeList, myContextObjects,   null, null);
  myUIAuto.EndStartConversation(ar);
}

Advanced Application Scenarios

Use the Lync 2010 API to add Lync 2010 functionality to new or existing .NET Framework applications and to suppress the Lync 2010 UI. Lync SDK UI Automation automates the Lync 2010 interface, and Lync 2010 Controls add separate pieces of Lync 2010 functionality and UI as XAML controls. For more information, see Lync 2010 API Concepts.

The only UI element that Lync 2010 API exposes is the Microsoft.Lync.Model.Conversation.AudioVideo.VideoWindow class. All other classes expose methods that you call or properties that you can read to update your own application UI. By using the advanced API features, you are responsible for writing more complex application logic around the API calls. This approach gives you a degree of flexibility to customize the appearance and behavior of a client collaboration application.

Before you develop applications by using the Lync 2010 API, you should be familiar with the .NET Framework asynchronous programming pattern. You will write event handling methods and asynchronous callback methods to catch the results of operations and notifications of new and changed information from Lync Server 2010.

Lync 2010 API Application Scenarios

  • Contact management, availability publication and contact information, fill group and contact lists, search for groups and contacts, and query contact availability and contact information.

  • Start or join IM, audio, and video conversations, add conversation participants, park and reactivate conversations, or schedule and join conferences.

Lync 2010 API Code Example

The following example collects contact information. For more information, see Walkthrough: Display a Contact Card (Lync 2010 SDK).

private void ContactCardForm_Load(object sender, EventArgs e)
{
    Contact myContact = sender as Contact;
    if (myContact != null)
    {
        this.Text = "Contact: " + myContact.GetContactInformation(ContactInformationType.Name).ToString();
        lbl_EmailValue.Text = myContact.GetContactInformation(ContactInformationType.PrimaryEmail).ToString();
        List<object> contactPhones = null;
        contactPhones = (List<object>) myContact.GetContactInformation(ContactInformationType.CollaborationEndpoints);

        foreach (object o in contactPhones)
        {
            CollaborationEndpoint collabEndpoint = o as CollaborationEndpoint;
            switch (collabEndpoint.Type)
            { 
                case CollaborationEndpointType.Home:
                    lbl_HomeValue.Text = collabEndpoint.DisplayString;
                    break;
                case CollaborationEndpointType.Mobile:
                    lbl_MobileValue.Text = collabEndpoint.DisplayString;
                    break;
                case CollaborationEndpointType.Work:
                    lbl_WorkValue.Text = collabEndpoint.DisplayString;
                    break;
            }
        }

        lbl_TitleValue.Text = myContact.GetContactInformation(ContactInformationType.Title).ToString();
        lbl_OfficeValue.Text = myContact.GetContactInformation(ContactInformationType.Office).ToString();

    }
}

The following example signs in to Lync Server 2010 and handles the asynchronous results of a sign-in request. For more information, see Walkthrough: Sign In to Lync (Lync 2010 SDK).

        /// <summary>
        /// Method to sign in to Lync
        /// </summary>
        /// <param name="UserUri">string. Uri of user.</param>
        /// <param name="Domain">string. User name and Domain of user.</param>
        /// <param name="Password">string. Password of user</param>
        public void SignIn(string UserUri, string UserNameDomain, string Password)
        {

           LyncClient.GetClient().ClientStateChanged += myClient_ClientStateChanged;

            try
            {

                IAsyncResult ar = LyncClient.GetClient().BeginSignIn(
                    UserUri,
                    UserNameDomain,
                    Password,
                    null,
                    null);

                LyncClient.GetClient().EndSignIn(ar);
            }
            catch (NotInitializedException)
            {
               MessageBox.Show("Lync is not initialized");
            }
        }



        /// <summary>
        /// Handles LyncClient state change events. 
        /// </summary>
        /// <param name="source">LyncClient.  Client source of events.</param>
        /// <param name="data">ClientStateChangedEventArgs. State change data.</param>
        void myClient_ClientStateChanged(object source, ClientStateChangedEventArgs data)
        {
            if (data.NewState == ClientState.SignedIn)
            {
                MessageBox.Show("Signed in");
            }
            if (data.NewState == ClientState.SignedOut)
            {
                MessageBox.Show("Signed out");
            }

            if (data.NewState == ClientState.ShuttingDown )
            {
                MessageBox.Show("Client is shutting down");
            }
        }

OCOM Unmanaged COM API

Use the Lync 2010 API Reference to learn about the unmanaged Microsoft Office Communicator Object Model (OCOM). The OCOM API contains a subset of the types that are in the Lync 2010 API. You cannot start or participate in conversations with OCOM, but you can access a contact list and get contact presence.

See Also

Concepts

Lync 2010 General Reference