不允许来电Lync Api或禁用来电的声音

时间:2014-12-04 11:12:02

标签: c# lync

我使用Lync api开发了一个Windows应用程序。我的客户端想要禁用对此应用程序的传入呼叫。所以我添加了一些这样的东西。我能够切断电话但是在能够做到这一点之前几乎没有响铃

private void ClientInitialized(IAsyncResult result)
        {
            try
            {
                //registers for conversation related events
                //these events will occur when new conversations are created (incoming/outgoing) and removed
                client.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;
                client.ConversationManager.ConversationRemoved += ConversationManager_ConversationRemoved;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Problem in adding/removing conversation", "Bella IVIS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

void ConversationManager_ConversationAdded(object sender, ConversationManagerEventArgs e)
        {
     try
     {    
     var _client = client;
     if (e.Conversation.State == ConversationState.Active)
     {
     for (int intLoop = 0; intLoop < _client.ConversationManager.Conversations.Count; intLoop++)
     {
         _client.ConversationManager.Conversations[intLoop].End();
     }
     _client = null;
      return;
     }
    }
  }

1 个答案:

答案 0 :(得分:0)

我不知道是否有办法在Conversation_Added事件之前捕获对话。但是,如果Lync状态与您无关,则将Lync状态更改为“请勿打扰”。这样您就不会收到任何传入请求(除非用户Lync设置允许这样做)

var newInformation =new Dictionary<PublishableContactInformationType, object>();
        newInformation.Add(PublishableContactInformationType.Availability, ContactAvailability.DoNotDisturb);

try
{
     this.lyncClient.Self.BeginPublishContactInformation(newInformation,(result) => this.lyncClient.Self.EndPublishContactInformation(result) , null);
}  catch {}