ExchangeService.FindItems()

ExchangeService.FindItems()

我被要求创建一个应用程序,该应用程序应该从 3 个不同的电子邮件地址来源创建一个公共基础,并使用最常见的更新数据集更新每个基础。 在这三个来源中,我有一个 Exchange 服务器联系人地址簿。我知道我可以通过 EWS 访问此类数据,具体来说,我可能应该使用 ExchangeService.FindPeople() 方法或 FindPersona()。 这应该可行,但是,由于我只查找 new/updated 联系人,它会显着加载服务器(可能不是新记录,但我不明白如何检索更新记录),这不是一个好习惯。 我在 MSDN 文档中找到了一种在消息库更新时收到通知的方法,但与联系人更新无关:

https://msdn.microsoft.com/en-us/library/office/dn458791(v=exchg.150).aspx

是否有关于联系人更新的通知(即使是通过第三方 products/APIs)。

P.S。我想用 C#(或其他 .NET 语言)编写代码,但我对其他语言持开放态度。

您应该能够通过遍历联系人并访问每个联系人的 DateTimeCreated 属性 来检查新创建的联系人。

要检查更新的联系人,您可以使用 LastModifiedTime 属性。

// Get the number of items in the Contacts folder.
ContactsFolder contactsfolder = ContactsFolder.Bind(service, WellKnownFolderName.Contacts);

// Set the number of items to the number of items in the Contacts folder or 50, whichever is smaller.
int numItems = contactsfolder.TotalCount < 50 ? contactsfolder.TotalCount : 50;

// Instantiate the item view with the number of items to retrieve from the Contacts folder.
ItemView view = new ItemView(numItems);

// To keep the request smaller, request only the DateTimeCreated and LastModifiedTime properties.
view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ContactSchema.DateTimeCreated, ContactSchema.LastModifiedTime);

// Retrieve the items in the Contacts folder that have the properties that you selected.
FindItemsResults<Item> contactItems = service.FindItems(WellKnownFolderName.Contacts, view);

// Display the list of contacts. 
foreach (Item item in contactItems)
{
    if (item is Contact)
    {
        Contact contact = item as Contact;
        if (contact.DateTimeCreated.Date == DateTime.Today.Date)
        {
           //Notify - Newly created contact
        }

        if (contact.LastModifiedTime.Date == DateTime.Today.Date)
        {
           //Notify - Newly modified contact
        }
    }
}

这是一个通过昵称查找联系人的简单示例。您可以找到更高级的搜索 here.

// Create a view with a page size of 1.
ItemView view = new ItemView(1);

// Create the search filter.
SearchFilter searchFilter = new SearchFilter.IsEqualTo(ContactSchema.NickName, "806555335");

FindItemsResults<Item> contactItems = service.FindItems(WellKnownFolderName.Contacts, searchFilter, view);

if(contactItems != null && contactItems.Count()>0){
    //contact found!
    Contact contact = contactItems.First() as Contact;
}