Contact information such as availability is constantly being published by Microsoft Lync 2010 on behalf of users as they sign in, update their contact card, join meetings, take calls, step away from their desks, and sign out of Lync 2010. In order to display current contact information for a local user's contacts, your application subscribes for updates to a contact's information.

With a subscription, you simply handle the appropriate event and update your UI with fresh contact information as it is published. As long as you have registered for the ContactInformationChanged , timely updates are pushed to your application without further action on the part of your application. The refreshed information can also be obtained from the contact by calling into GetContactInformation . This returns the same values you obtain from the most recent ContactInformationChanged event.

Handle Subscription-Driven Contact Information Change Events

This topic demonstrates how to handle the event related to subscription-driven contact information refresh.

  1. Create an event handler for the ContactInformationChanged event.

  2. If the contact is not on the Lync 2010 contact list, you add the contact to a ContactSubscription that you create by calling into CreateSubscription . For information about creating a contact subscription, see Walkthrough: Search For a Contact

  3. Register for the ContactInformationChanged event. You must do this even when the contact is on the Lync 2010 contact list.

  4. When the event is raised, your event handler does the following:

    1. Examine the ChangedContactInformation property to see if the enumerator, ContactInformationType . Availability, is in the collection of enumerators for changed information types.

    2. Call GetContactInformation , passing the ContactInformationType . Availabilityenumerator.

      Tip Tip

      If you want to get all information changes regardless of type, iterate on the collection of ChangedContactInformation . With each iteration, pass the collection item into GetContactInformation and append each successive return value to an array of changed values.

Querying for Contact Availability

This topic demonstrates how to query for the availability of a Contact instance, using the GetContactInformation method to read current availability.

  1. Get a Contact instance. For information about searching for contacts, see Walkthrough: Search For a Contact .

  2. Get the availability contact information item for the contact by calling the GetContactInformation method, passing the ContactInformationType . Availabilityenumerator.

  3. Cast the returned object to ContactAvailability .

  4. Get a string representing current availability by calling ToStringon the enumerator.

    Tip Tip

    Return the string obtained by getting the ContactInformationType . Activityvalue if you intend to display the same activity level that Lync 2010 displays for a given contact availability. If a localized version of Lync 2010 is running on the local computer, the activity string is returned in the appropriate language.

Examples

The following examples demonstrate how you get contact information from a query for contact information or a subscription to the contact information change event

Handle ContactInformationChanged Event

The following example gets the current availability of a contact. The availability value returned is an integer that falls into a specific range of availability as defined by the ContactAvailability enumeration. The example then identifies the availability range the current contact availability falls into and returns the corresponding US-English string representing the availability of the contact to the calling code. This method could be called by your event handler for the ContactInformationChanged event raised by the contact.

C#  Copy imageCopy Code
		/// <summary>
		/// Handles event raised when contactModel presence item
collection has been updated.
		/// </summary>
		/// <param name="source">object. Contact whose
information has been updated.</param>
		/// <param
name="data">ContactInformationChangedEventArgs. The contact
information that changed.</param>
		/// <remarks>This callback is used to update the
public contactModel card string class property
ContactCardInformation.
		/// The event data parameter exposes a member property,
ChangedPresenceItems. This property is a list of
ContactInformationType. The types in 
		/// the list are the presence item types whose change
resulted in this state change event.
		/// </remarks>
		void _Contact_OnInformationChanged(Object source,
ContactInformationChangedEventArgs data)
		{
			string returnValue = string.Empty;
			StringBuilder sb = new StringBuilder();
			Boolean raiseUpdate = false;
			if
(data.ChangedContactInformation.Contains(ContactInformationType.Availability))
			{
				//get actual contactModel availability (Will be int
value within OCOM availaiblity ranges)
				ContactAvailability availEnum =
(ContactAvailability)((Contact)source).GetContactInformation(ContactInformationType.Availability);
				string activityString =
(string)((Contact)source).GetContactInformation(ContactInformationType.Activity);
				sb.Append(availEnum.ToString() + " " +
activityString);
				raiseUpdate = true;
		}

			if (raiseUpdate)
			{
				returnValue = "Updated availability for "
				+
((Contact)source).GetContactInformation(ContactInformationType.DisplayName).ToString()
				+ System.Environment.NewLine
				+ sb.ToString();
		}
			MessageBox.Show(returnValue);
	}

Query for Contact Information

A query for contact information is simply a call into a method on the contact, passing an enumerator for the type of contact information you want to get.

Important note Important

The contact must be subscribed before this method call returns a result. Lync 2010 maintains a subscription for all contacts displayed in it's contact list. You create and maintain a contact subscription for any contact instance that is not in the contact list.

  Copy imageCopy Code
MessageBox.Show("Contact Display Name: " +
_Contact.GetContactInformation(ContactInformationType.DisplayName).ToString());

See Also