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

本文关键字:GetAutomation 不起作用 应用程序 Lync 运行 UI | 更新日期: 2023-09-27 17:50:42

我们正在开发一个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抑制模式下运行应用程序时,同样的代码lynclient . getautomation()抛出错误"Exception from HRESULT: 0x80C8000B"。在论坛中发现GetAutomation()将无法在UISuppression模式下工作。是否有任何替代方法来实现这个功能,如果是这样,谁可以提供我们的示例代码。

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

这是正确的-您根本不能在UI抑制模式下使用自动化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);
}

希望这能让你开始。