从 Exchange Server 过滤约会

Aspose.Email for C++ 使开发者能够使用 IEWSClient 和 ExchangeQueryBuilder API。您可以按日期范围、循环状态或其他约会属性过滤约会,仅检索所需的事件。

本文中的示例使用了以下头文件和名称空间:

#include <Calendar/Appointment.h>
#include <Clients/Exchange/WebService/EWSClient/EWSClient.h>
#include <Clients/Exchange/WebService/EWSClient/IEWSClient.h>
#include <Clients/Exchange/Search/ExchangeQueryBuilder.h>
#include <Clients/Exchange/Search/AppointmentQueryBuilder.h>
#include <Tools/Search/MailQuery.h>
#include <Tools/Search/DateComparisonField.h>
#include <Tools/Search/BoolComparisonField.h>
#include <system/array.h>
#include <system/convert.h>

using namespace System;
using namespace Aspose::Email::Calendar;
using namespace Aspose::Email::Clients::Exchange;
using namespace Aspose::Email::Clients::Exchange::WebService;
using namespace Aspose::Email::Tools::Search;

按日期范围过滤约会

该 Appointment 成员 ExchangeQueryBuilder 提供日历项的字段。对其 Start 和 End 日期选择一段期间的约会; GetQuery 将它们转换为一个 MailQuery 那 ListAppointments 在服务器端求值。

SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");

SharedPtr<ExchangeQueryBuilder> builder = MakeObject<ExchangeQueryBuilder>();
builder->get_Appointment()->get_Start()->Since(DateTime(2025, 9, 15));
builder->get_Appointment()->get_End()->BeforeOrEqual(DateTime(2025, 10, 10));

ArrayPtr<SharedPtr<Appointment>> appointments = client->ListAppointments(builder->GetQuery());
Console::WriteLine(u"Appointments in the period: " + Convert::ToString(appointments->get_Length()));

client->Dispose();

过滤循环或非循环约会

该 IsRecurring 字段将系列与单一事件分离。示例列出不属于系列的约会。

SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");

SharedPtr<ExchangeQueryBuilder> builder = MakeObject<ExchangeQueryBuilder>();
builder->get_Appointment()->get_IsRecurring()->Equals(false);

ArrayPtr<SharedPtr<Appointment>> appointments = client->ListAppointments(builder->GetQuery());
for (SharedPtr<Appointment> appointment : appointments)
{
    Console::WriteLine(appointment->get_Summary() + u" - " + appointment->get_StartDate().ToString());
}

client->Dispose();