当Lync应用程序运行UI抑制时,GetAutomation()不起作用

时间:2014-03-18 10:36:33

标签: c# lync lync-client-sdk

我们正在开发一个Lync客户端应用程序,在此我们需要拨打一个号码到外部号码,当我们不使用UI抑制时,下面的代码工作正常

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);

当我们在UI抑制模式下运行应用程序时,相同的代码LyncClient.GetAutomation()抛出错误“来自HRESULT的异常:0x80C8000B”。在论坛中发现GetAutomation()不能在UISuppression模式下工作。有没有其他方法可以实现此功能,如果有人可以提供示例代码。

1 个答案:

答案 0 :(得分:2)

没错 - 你根本无法在UI抑制模式下使用Automation API,因为它需要一个运行的,可见的Lync实例来与之交互。

你可以在UI抑制中开始通话,但它需要做更多的工作。首先,使用以下方法获取Lync客户端:

var _client = LyncClient.GetClient();

然后使用ConversationManager添加新会话:

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

以下代码显示了如何处理因添加新会话而产生的事件和操作:

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

希望这能让你开始。