使用 Lync ContactManager 获取所有联系人

发布于 2024-10-26 18:13:07 字数 323 浏览 0 评论 0原文

现在我正在使用 LyncClient.ContactManager.BeginSearch 方法来查找联系人。但是,我一直无法弄清楚如何获取所有联系人。我尝试过将“*”和“%”作为通配符传递,但这没有用。现在这是我的函数调用。

_lyncClient.ContactManager.BeginSearch("*", SearchProviders.GlobalAddressList, SearchFields.DisplayName, SearchOptions.ContactsOnly, 400, SearchCallback, "Searching Contacts");

Right now I'm using the the LyncClient.ContactManager.BeginSearch method to find contacts. However, I haven't been able to figure out how to get all the contacts. I've tried passing "*" and "%" as wild-card characters but that has not worked. Right now here is my function call.

_lyncClient.ContactManager.BeginSearch("*", SearchProviders.GlobalAddressList, SearchFields.DisplayName, SearchOptions.ContactsOnly, 400, SearchCallback, "Searching Contacts");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠檬色的秋千 2024-11-02 18:13:07

Lync 联系人按组进行组织,因此您需要从组级别开始。获得群组后,您可以枚举其联系人

foreach(var group in _client.ContactManager.Groups)
{
    foreach (var contact in group)
    {
        MessageBox.Show(contact.Uri);
    }
}

本文 适合背景和更高级的功能

编辑:具体来说,对于通讯组扩展问题,我认为示例此处 有缺陷。

不要调用 BeginExpand 并等待 WaitHandle,而是提供一个回调方法来处理 Expand 回调。所以,不要:

asyncOpResult = DGGroup.BeginExpand(null, null);
asyncOpResult.AsyncWaitHandle.WaitOne();

DGGroup.EndExpand(asyncOpResult);

尝试这个:

...
asyncOpResult = DGGroup.BeginExpand(ExpandCallback, DGGroup);
...

public void ExpandCallback(IAsyncResult ar)
{
    DistributionGroup DGGroup = (DistributionGroup)ar.AsyncState;
    DGGroup.EndExpand(ar);

    etc...
}

这对我来说非常有效。

Lync contacts are organised into groups, so you need to start at the Groups level. Once you've got a group, you can then enumerate through it's Contacts

foreach(var group in _client.ContactManager.Groups)
{
    foreach (var contact in group)
    {
        MessageBox.Show(contact.Uri);
    }
}

This article is good for background, and more advanced features

Edit: Specifically, for the distribution groups expansion question, I think the sample here is flawed.

Instead of calling BeginExpand and waiting on the WaitHandle, provide a callback method to handle the Expand callback. So, instead of:

asyncOpResult = DGGroup.BeginExpand(null, null);
asyncOpResult.AsyncWaitHandle.WaitOne();

DGGroup.EndExpand(asyncOpResult);

try this:

...
asyncOpResult = DGGroup.BeginExpand(ExpandCallback, DGGroup);
...

public void ExpandCallback(IAsyncResult ar)
{
    DistributionGroup DGGroup = (DistributionGroup)ar.AsyncState;
    DGGroup.EndExpand(ar);

    etc...
}

This works perfectly for me.

左秋 2024-11-02 18:13:07

我最终进行了多次搜索以获取所有联系人。我浏览字母表中的每个字母来找到它们。加载时间足够快,当它启动时,我只会在网格上显示加载图像一段时间。对于我们拥有的 200 名左右的联系人,这种方法效果很好,但对于 150 名或更少的联系人,我会推荐 Paul 的解决方案。这是我所做的:

private static char[] Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
...

public void GetAllContacts()
{
   int initialLetterIndex = 0;

  _lyncClient.ContactManager.BeginSearch(
    Alphabet[initialLetterIndex].ToString();
    SearchProviders.GlobalAddressList,
    SearchFields.FirstName,
    SearchOptions.ContactsOnly,
    300,
    SearchAllCallback
    new object[] { initialLetterIndex, new List<Contact>() }
  );
}

private void SearchAllCallback(IAsyncResult result)
{
  object[] parameters = (object[])result.AsyncState;
  int letterIndex = (int)parameters[0] + 1;
  List<Contact> contacts = (List<Contact>)parameters[1];

  SearchResults results = _lyncClient.ContactManager.EndSearch(result);
  contacts.AddRange(results.Contacts);

  if (letterIndex < Alphabet.Length)
  {
    _lyncClient.ContactManager.BeginSearch(
      Alphabet[letterIndex].ToString(), 
      SearchAllCallback, 
      new object[] { letterIndex, contacts }
    );
  }
  else
  {
    //Now that we have all the contacts 
    //trigger an event with 'contacts' as the event arguments.
  }
}

I ended up doing multiple searches for now to get all the contacts. I go through each letter of the alphabet to find them. The load time is quick enough and I'll just show a loading image on the grid for a little while when it fires up. This worked well for the 200 or so contacts we have though I would recommend Paul's solution for 150 or less. Here is what I did:

private static char[] Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
...

public void GetAllContacts()
{
   int initialLetterIndex = 0;

  _lyncClient.ContactManager.BeginSearch(
    Alphabet[initialLetterIndex].ToString();
    SearchProviders.GlobalAddressList,
    SearchFields.FirstName,
    SearchOptions.ContactsOnly,
    300,
    SearchAllCallback
    new object[] { initialLetterIndex, new List<Contact>() }
  );
}

private void SearchAllCallback(IAsyncResult result)
{
  object[] parameters = (object[])result.AsyncState;
  int letterIndex = (int)parameters[0] + 1;
  List<Contact> contacts = (List<Contact>)parameters[1];

  SearchResults results = _lyncClient.ContactManager.EndSearch(result);
  contacts.AddRange(results.Contacts);

  if (letterIndex < Alphabet.Length)
  {
    _lyncClient.ContactManager.BeginSearch(
      Alphabet[letterIndex].ToString(), 
      SearchAllCallback, 
      new object[] { letterIndex, contacts }
    );
  }
  else
  {
    //Now that we have all the contacts 
    //trigger an event with 'contacts' as the event arguments.
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文