Delegate call handling is done in the same way as non-delegate calls except that you register for events on the ConversationManager property of the DelegatorClient instead of on LyncClient . In the ConversationManager . . :: . . ConversationAdded event, you should get the name of the delegator as well as the name of the calling user.

This walkthrough shows you how to register for delegator client events, register for conversation events on a delegator, and get a delegator user name in a ConversationManager . . :: . . ConversationAdded event handler.

Delegator Event Registration

A Microsoft.Lync.Model . . :: . . DelegatorClient representing a call delegator is added to the LyncClient . . :: . . DelegatorClients collection whenever a user delegates the local user to take incoming audio calls. To catch that event, you register for LyncClient . . :: . . DelegatorClientAdded . When the call delegator removes the local user from the call delegate list, the LyncClient . . :: . . DelegatorClientRemoved event is raised.

Register for Delegator Events in a Form Load Event Handler

  1. Get the Microsoft.Lync.Model . . :: . . LyncClient . Make sure the State is ConversationState . SignedIn. For information about signing in to Microsoft Lync 2010, see Walkthrough: Sign In to Lync .

  2. Register for LyncClient . . :: . . DelegatorClientAdded and LyncClient . . :: . . DelegatorClientRemoved on Microsoft.Lync.Model . . :: . . LyncClient

  3. Iterate on the collection of Microsoft.Lync.Model . . :: . . DelegatorClient instances in the DelegatorClients property.

    1. Register for the ConversationManager . . :: . . ConversationAdded event on the ConversationManager property of the Microsoft.Lync.Model . . :: . . DelegatorClient

    2. Register for the ConversationManager . . :: . . ConversationRemoved event on the ConversationManager property of the Microsoft.Lync.Model . . :: . . DelegatorClient

Handle Delegator Events

You register for delegate conversation events for each DelegatorClient in the DelegatorClients collection after you have obtained a LyncClient instance in your form load event. In addition, you register and un-register for conversation events in the delegator event handlers.

Handle Delegator Added and Delegator Removed

  1. Create a method to handle the LyncClient . . :: . . DelegatorClientAdded event. The method signature is System.EventHandler< DelegatorClientCollectionEventArgs >.

  2. Create a method to handle the LyncClient . . :: . . DelegatorClientRemoved event. The method signature is System.EventHandler< DelegatorClientCollectionEventArgs >.

  3. In the DelegatorClientAdded event, register for the ConversationAdded and ConversationRemoved events on the Client . . :: . . ConversationManager property of the DelegatorClient

  4. In the DelegatorClientRemoved event, un-register for the ConversationAdded and ConversationRemoved events on the Client . . :: . . ConversationManager property of the DelegatorClient

Get a Delegator User Name When a Delegated Call is Added

To give the local user the delegator name on an incoming delegated call, you add code from the following procedure to your ConversationAdded event handler.

For more information about handing incoming calls see, Walkthrough: Respond to a Conversation Invitation .

Get Call Delegator's Name

  • For each DelegatorClient in the LyncClient . . :: . . DelegatorClients property, you get a ConversationManager by reading the ConversationManager property on Microsoft.Lync.Model . . :: . . DelegatorClient .

    1. Compare the delegator client's ConversationManager to the source of the ConversationAdded event. (ConversationManager)source.

    2. If the two ConversationManagerinstances are the same then the added conversation is a delegated conversation.

      1. Get the Contact of the call delegator by calling into GetContactByUri and passing the Uri of the Microsoft.Lync.Model . . :: . . DelegatorClient .

      2. Call GetContactInformation , passing ContactInformationType . DisplayNameto get the name of the call delegator.

      3. Break out of the foreachloop.

Examples

Register for Delegator Events in a Form Load Event Handler

The following example handles the Load event on a Windows Form. For information about signing in to Lync 2010, see Walkthrough: Sign In to Lync with UI Suppressed .

C#  Copy imageCopy Code
		...
		private LyncClient _lyncClient;
		...
		/// <summary>
		/// Main form loader
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void MainForm_Load(object sender, EventArgs e)
		{
			try
			{
				_lyncClient = LyncClient.GetClient();

				//Client sign-in code is omitted for clarity
				...
				_LyncClient.DelegatorClientAdded +=
_LyncClient_DelegatorClientAdded;
				_LyncClient.DelegatorClientRemoved +=
_LyncClient_DelegatorClientRemoved;

				foreach (DelegatorClient _DelegatorClient in
_ClientModel._LyncClient.DelegatorClients)
				{
				 
_DelegatorClient.ConversationManager.ConversationAdded +=
ConversationManager_ConversationAdded;
				 
_DelegatorClient.ConversationManager.ConversationRemoved +=
ConversationManager_ConversationRemoved;
			}
		}
			catch (Exception ex)
			{
				MessageBox.Show("Critial Exception on initiate
client " + ex.Message);
		}
	}

Handle Delegator Added and Delegator Removed

The following example registers or un-registers for conversation events on a delegator client.

C#  Copy imageCopy Code
		/// <summary>
		/// Handles event raised when a user removes local user
from a call delegate list
		/// </summary>
		/// <param name="sender">LyncClient. The local
client</param>
		/// <param name="e"></param>
		void _LyncClient_DelegatorClientRemoved(object sender,
DelegatorClientCollectionEventArgs e)
		{
			e.DelegatorClient.ConversationManager.ConversationAdded
-= ConversationManager_ConversationAdded;
	}

		/// <summary>
		/// Handles event raised when a user adds local user to a
call delegate list
		/// </summary>
		/// <param name="sender">LyncClient. The local
client</param>
		/// <param name="e"></param>
		void _LyncClient_DelegatorClientAdded(object sender,
DelegatorClientCollectionEventArgs e)
		{
			e.DelegatorClient.ConversationManager.ConversationAdded
+= ConversationManager_ConversationAdded;
	}

Get Call Delegator's Name

The following example code should be added to your ConversationAdded event handler.

C#  Copy imageCopy Code
	//The call is a delegated call.
	if ((ConversationManager)sender !=
_LyncClient.ConversationManager)
	{
		//Look for the delegator ConversationManager that raised
the event.
		foreach (DelegatorClient _DelegateClient in
_LyncClient.DelegatorClients)
		{
			//Did this delegator conversation manager raise the
ConversationAdded event?
			if (_DelegateClient.ConversationManager ==
(ConversationManager)sender)
			{
				//Get the Contact representing the call delegator.
				Contact delegatorContact =
_LyncClient.ContactManager.GetContactByUri(_DelegateClient.Uri);
				//Add the name of the delegator to a StringBuilder
instance.
				sb.Append("Incoming call delegated by " +
delegatorContact.GetContactInformation(ContactInformationType.DisplayName).ToString());

				//Add the name of the caller to the string builder
instance
				string delegateCallName =
e.Conversation.Participants[1].Contact.GetContactInformation(ContactInformationType.DisplayName).ToString();
				sb.Append("Caller: " + delegateCallName);

				//Break out of foreach loop, correct delegator
conversation manager found.
				break;
		}
	}
}

See Also