There are three kinds of state change events that are raised on an individual contact. These events can only be raised when the contact has been added to a ContactSubscription and your application has registered for events on a Contact . In the case where a given contact appears in the Lync 2010 contact list, you do not need to add the contact to a contact subscription because Lync 2010 itself maintains a subscription. In contrast, a contact that you obtain using the search feature of the API must be added to a contact subscription that your application maintains.

Unknown List Class

Contact Events

The following sections provide examples that handle the three kinds of contact events.

Contact Information Changed

The following example handles the event raised when contact information is updated. It is important to note that this example queries the dataparameter property, ChangedContactInformation for only the Availablilitytype. If the collection of ContactInformationType enumerators contains this type, then the corresponding value has been updated. To get the updated value, the example queries the sourceparameter as an instance of Contact for the updated value itself.

C#  Copy imageCopy Code
		/// <summary>
		/// Handles event raised when contact contact information
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)
		{
			try
			{
				string newCard = string.Empty;
				StringBuilder sb = new StringBuilder();
				if
(data.ChangedContactInformation.Contains(ContactInformationType.Availability))
				{
					object availability =
((Contact)source).GetContactInformation(ContactInformationType.Availability);
					object activityString =
((Contact)source).GetContactInformation(ContactInformationType.Activity);
					if (availability != null)
					{
						sb.Append(availability.ToString() + " " +
activityString.ToString());
						newCard = "Updated availability for "
						+
((Contact)source).GetContactInformation(ContactInformationType.DisplayName).ToString()
						+ System.Environment.NewLine
						+ sb.ToString();
				}
			}
			
		}
			catch (System.IO.InvalidDataException x)
			{
				WinForm.MessageBox.Show("Invalid Data Exception,
Contact.ContactInformationChanged " + x.Message);
		}
	}

Contact Setting Changed

The following example handles a contact property changed event by getting the type of property that changed and the new value. The result is displayed to a user in a MessageBox .

C#  Copy imageCopy Code
		/// <summary>
		/// Event handler for ContactModel event raised when a
setting on a contactModel has changed.
		/// </summary>
		/// <param name="source">Contact. The ContactModel
instance whose inner Contact setting has changed.</param>
		/// <param
name="data">ContactSettingChangedEventArgs. Event
data.</param>
		private void ContactModel_ContactSettingChanged(object
source, ContactSettingChangedEventArgs data)
		{

			string ChangedProperty = string.Empty;
			switch (data.Setting)
			{
				case ContactSetting.AccessLevel:
					ChangedProperty =
((Contact)source).GetContactInformation(ContactInformationType.DisplayName).ToString()
+ " access level changed " + data.Value.ToString();
					break;
				case ContactSetting.DefaultContactEndpoint:
					ChangedProperty =
((Contact)source).GetContactInformation(ContactInformationType.DisplayName).ToString()
+ " default endpoint changed " + data.Value.ToString();
					break;
				case ContactSetting.ExchangeServiceEntryId:
					ChangedProperty =
((Contact)source).GetContactInformation(ContactInformationType.DisplayName).ToString()
+ " Exchange service Entry Id " + data.Value.ToString();
					break;
				case ContactSetting.Source:
					ChangedProperty =
((Contact)source).GetContactInformation(ContactInformationType.DisplayName).ToString()
+ " Sources changed " + data.Value.ToString();
					break;
				case ContactSetting.Tagged:
					ChangedProperty =
((Contact)source).GetContactInformation(ContactInformationType.DisplayName).ToString()
+ " Tagging changed " + data.Value.ToString();
					break;
		}
			MessageBox.Show("Contact Setting Changed: " +
ChangedProperty);
	}

Contact Uri Changed

The following example handles the event raised when a contact's Uri has changed. The example uses a MessageBox to alert a user of the change.

C#  Copy imageCopy Code
		/// <summary>
		/// Alerts user when a Contact Uri has changed
		/// </summary>
		/// <param name="source">object. Contact whose Uri
has changed</param>
		/// <param name="data">UriChangedEventArgs Event
data</param>
		void _Contact_OnUriChanged(Object source,
UriChangedEventArgs data)
		{
		 
System.Windows.Forms.MessageBox.Show(((Contact)source).GetContactInformation(ContactInformationType.DisplayName).ToString()
+ " uri changed to " + data.NewUri);
	}

See Also