c# - 检测对话是传入还是传出
问题描述
我使用 Lync SDK 2013 并尝试检查新对话是传入还是传出。我不想只检查音频/视频通话,我想检查每种模式类型。
private void Conversation_Added(object sender, ConversationManagerEventArgs e)
{
Conversation conversation = e.Conversation;
IDictionary<ModalityTypes, Modality> modalities = conversation.Modalities;
bool conversationIsIncoming = modalities.Any(modality => modality.Value.State == ModalityState.Notified);
}
当事件被触发并且涉及到Any
我得到这个错误的方法时
NullReferenceException对象引用未设置为对象的实例。System.Collections.Generic.KeyValuePair.Value.get 返回 null。
所以很明显我必须在这里使用空检查,但也许整个代码可能是错误的?如何检查对话是传入还是传出?
解决方案
您的想法基本上是正确的,但是当您检查通知状态时是不正确的。
您需要挂钩 ModalityStateChanged 事件,如果您只想了解音频/视频“通话”,那么您也只需要挂钩具有 AudioVideo 模态类型的对话。
例如
private void ConversationManager_ConversationAdded(object sender, ConversationManagerEventArgs e)
{
if (e.Conversation.Modalities.TryGetValue(ModalityTypes.AudioVideo, out var avModality))
{
avModality.ModalityStateChanged += AvModalityOnStateChanged;
}
}
private void AvModalityOnStateChanged(object sender, ModalityStateChangedEventArgs e)
{
if (e.NewState == ModalityState.Notified)
{
bool conversationIsIncoming = true;
}
}
当您不再需要知道状态更改时,不要忘记从 ModalityStateChanged 中解脱。
推荐阅读
- linq - 在 ASP.NET Core MVC 中使用选择查询时出现 InvalidOperationException
- javascript - 同步超时问题(Javascript 和 ajax)
- android - 使用 TabLayout android studio 将 ViewPager 的(轮播/滑块)指示器(点)定位在底部
- android - Dagger2 架构失败,.Application 未实现 dagger.android.HasAndroidInjector
- java - Tomcat 服务器显示无法启动
- python - Generating and printing random multiple lists in python
- c# - 为什么排序列表时我的 lamda 为空?
- c# - 如何判断一个对象是否具有其类型的默认值?
- regex - 自定义报告,正则表达式 - 仅过滤来自包含关键字的特定网站/网址的结果
- sql-server - 如何优化存储过程代码