3

我正在开发 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;
        }

另外,对于糟糕的代码感到抱歉......我只是想让它工作并不断抛出更多垃圾代码,希望能有所帮助。

4

1 回答 1

0

您能否验证代码是否适用于您的联系人列表中的所有联系人,并且只是那些未正确引发状态更改事件的未列出的联系人?

这对我来说很有意义,因为您使用的是客户端 SDK,它只会告诉您客户端感兴趣的事件。例如,如果所有 85,000 个客户端都收到公司中其他 85,000 个客户端的状态更改,那将是相当大的流量密集型。

我认为您处于定期轮询存在或将联系人添加到客户的领域(可能在相关组下只是为了保持整洁)。

如果您不希望查看比客户端 SDK 更适合集中式服务的 UCMA SDK。

于 2014-07-24T08:58:33.800 回答