How to: Handle Delegated Calls

[This is preliminary documentation and is subject to change.]

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.

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

  1. Get the Microsoft.Lync.Model.LyncClient. Ensure the State is ConversationState.SignedIn. For information about signing in to Microsoft Lync 2013 Preview, see How to: 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.

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

  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, unregister for the ConversationAdded and ConversationRemoved events on the Client.ConversationManager property of the DelegatorClient.

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 How to: Respond to a Conversation Invitation.

To get call delegator’s name

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 2013 Preview, see How to: Sign In to Lync with UI Suppressed.


        ...
        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;
            }
        }
    }

Community Additions

Show:
© 2014 Microsoft