Exchange Server から予定をフィルタリングする

Aspose.Email for C++ は、Microsoft Exchange のカレンダー予定をフィルタリングするために使用できる 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();