Walkthrough: Handle Delegated Calls (Lync 2010 SDK)
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 instance 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.
To register for delegator events in a Forms Load event handler
Get the Microsoft.Lync.Model.LyncClient. Ensure the State is ConversationState.SignedIn. For information about signing in to Microsoft Lync 2010, see Walkthrough: Sign In to Lync (Lync 2010 SDK).
Register for LyncClient.DelegatorClientAdded and LyncClient.DelegatorClientRemoved on Microsoft.Lync.Model.LyncClient.
Iterate on the collection of Microsoft.Lync.Model.DelegatorClient instances in the DelegatorClients property.
Register for the ConversationManager.ConversationAdded event on the ConversationManager property of the Microsoft.Lync.Model.DelegatorClient.
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 instance in the DelegatorClients collection after you have obtained a LyncClient instance in your form Load event. In addition, you register and unregister for conversation events in the delegator event handlers.
To handle delegator added and delegator removed
Create a method to handle the LyncClient.DelegatorClientAdded event. The method signature is System.EventHandler<DelegatorClientCollectionEventArgs>.
Create a method to handle the LyncClient.DelegatorClientRemoved event. The method signature is System.EventHandler<DelegatorClientCollectionEventArgs>.
In the DelegatorClientAdded event, register for the ConversationAdded and ConversationRemoved events on the Client.ConversationManager property of the DelegatorClient.
In the DelegatorClientRemoved event, unregister 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 (Lync 2010 SDK).
To get call delegator’s name
For each DelegatorClient instance in the LyncClient.DelegatorClients property, you get a ConversationManager by reading the ConversationManager property on Microsoft.Lync.Model.DelegatorClient.
Compare the delegator client’s ConversationManager to the source of the ConversationAdded event:(ConversationManager)source.
If the two ConversationManager instances are identical, then the added conversation is a delegated conversation.
Get the Contact of the call delegator by calling into GetContactByUri and then passing the Uri of the Microsoft.Lync.Model.DelegatorClient.
Call GetContactInformation, passing ContactInformationType.DisplayName to get the name of the call delegator.
Break out of the foreach loop.
Examples
Register for Delegator Events in a Forms Load Event Handler
The following example handles the Load event in a Microsoft Windows Forms form. For information about signing in to Lync 2010, see Walkthrough: Sign In to Lync with UI Suppressed (Lync 2010 SDK).
...
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 unregisters for conversation events on a delegator client.
/// <summary>
/// Handles event that is 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 that is 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.
//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
Tasks
Walkthrough: Sign In to Lync with UI Suppressed (Lync 2010 SDK)
Concepts
Walkthrough: Respond to a Conversation Invitation (Lync 2010 SDK)