Search code examples
c#lynclync-client-sdk

GetAutomation() is not working when Lync application is running UI Suppression


We are developing an Lync client application, in this we need to dial a number to outside number the below code works fine when we are not using UI Suppression

LyncClient lyncClient = LyncClient.GetClient();
var automation = LyncClient.GetAutomation();
var conversationModes = AutomationModalities.Audio;
var conversationSettings = new Dictionary<AutomationModalitySettings, object>();
List<string> participants = new List<string>();
var contact = lyncClient.ContactManager.GetContactByUri("tel:" + _TelephoneNumber);
participants.Add(contact.Uri);
automation.BeginStartConversation(AutomationModalities.Audio, participants, null, null, automation);

The same code while we are running the application in UI Suppression mode LyncClient.GetAutomation() throwing an error "Exception from HRESULT: 0x80C8000B". In forums found that GetAutomation() will not work in UISuppression mode. Is there any alternative way to achieve this functionality if so could anyone provide us sample code.


Solution

  • That's right - you can't use the Automation API in UI suppression mode at all, as it needs a running, visible instance of Lync to interact with.

    You can start calls in UI supression, but it's a lot more work. First, get hold of the Lync client using:

    var _client = LyncClient.GetClient();
    

    Then add a new conversation using the ConversationManager:

    _client.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;
    _client.ConversationManager.AddConversation();
    

    The following code shows how to handle the events and operations that stem from adding the new conversation:

    private void ConversationManager_ConversationAdded(object sender, ConversationManagerEventArgs e)
    {
        _conversation = e.Conversation;
        _conversation.ParticipantAdded += Conversation_ParticipantAdded;
    
        var contact = _client.ContactManager.GetContactByUri("+441234567890");
        _conversation.AddParticipant(contact);
    }
    
    private void Conversation_ParticipantAdded(object sender, ParticipantCollectionChangedEventArgs e)
    {
        if (!e.Participant.IsSelf)
        {
            _avModality = (AVModality)_conversation.Modalities[ModalityTypes.AudioVideo];
    
            if (_avModality.CanInvoke(ModalityAction.Connect))
            {
                _avModality.BeginConnect(AVModalityConnectCallback, _avModality);
            }
        }
    }
    private void AVModalityConnectCallback(IAsyncResult ar)
    {
        _avModality.EndConnect(ar);
    }
    

    Hopefully that should get you started.