我正在开发 lync 的自动化服务,该服务将根据他们的可用性/lync“存在”自动将人们添加到 IM 对话中。它本质上是一个列表,检查谁在线,并将第一个人添加到呼叫中。
我遇到的问题是有时(通常在必须重新启动 lync 时),它并不总是获取联系人的存在。
首先,我只是让它抓住了存在。然后我添加了代码来检查 ContactInformationChanged 事件是否触发,但这似乎不会发生,除非我进入应用程序并手动输入我正在寻找的别名。
我在某处缺少 Refresh() 方法吗?或者有什么办法强迫它找到这个?这是我的搜索方法:
public Contact GetContact(string emailAddress)
{
Contact user;
lock (ContactLookupCache)
{
while (!ContactLookupCache.TryGetValue(emailAddress.ToLower(), out user))
{
lock (Client)
{
Client.ContactManager.BeginSearch(emailAddress, this.HandleContactLookup, null);
}
Monitor.Wait(ContactLookupCache);
}
}
return user;
}
public string GetContactPresenceState(Contact contact)
{
string presenceStatus = contact.GetContactInformation(ContactInformationType.Activity).ToString();
// see if the status is either "Presence unknown" or "Updating..."
if (IsUnknownPresenceState(presenceStatus))
{
lock (contact)
{
//bug?? This event seems to only fire sometimes when you search on the app for contact details
contact.ContactInformationChanged += (object sender, ContactInformationChangedEventArgs e) =>
{
if (e.ChangedContactInformation.Contains(ContactInformationType.Activity))
{
lock (contact)
{
presenceStatus = contact.GetContactInformation(ContactInformationType.Activity).ToString();
if(!IsUnknownPresenceState(presenceStatus))
Monitor.PulseAll(contact);
}
}
};
Monitor.Wait(contact);
}
}
return presenceStatus;
}
另外,对于糟糕的代码感到抱歉......我只是想让它工作并不断抛出更多垃圾代码,希望能有所帮助。