반복 관리

Outlook은 반복 일정이나 작업의 일정을 반복 패턴에 저장합니다. Aspose.Email for C++은 이를 다음 클래스들로 모델링합니다 Aspose::Email::Mapi 네임스페이스: MapiCalendarDailyRecurrencePattern, MapiCalendarWeeklyRecurrencePattern 및 MapiCalendarMonthlyRecurrencePattern, 모두는 다음에서 파생됩니다 MapiCalendarRecurrencePattern. 완성된 패턴은 다음에 할당됩니다 Recurrence 의 속성 MapiTask 또는, 통해 MapiCalendarEventRecurrence, 의 MapiCalendar.

모든 패턴은 동일한 속성 집합으로 설명됩니다:

| 속성 | 의미 | | — | — | | PatternType | 스케줄의 단위: MapiCalendarRecurrencePatternType Day, Week, Month, MonthNth 등등. | | Period | 두 발생 사이에 해당 단위가 몇 개 있는지. | | WeekStartDay | 주간 패턴의 첫 요일. | | EndType | 시리즈가 중단되는 방식: MapiCalendarRecurrenceEndType EndAfterNOccurrences, EndAfterDate 또는 NeverEnd. | | OccurrenceCount | 시리즈가 횟수 후에 종료될 때 발생 횟수 | | 예외 | 시리즈의 다른 발생과 다른 발생 |

아래 샘플은 이러한 헤더와 네임스페이스를 사용합니다:

#include <Calendar/AppointmentSaveFormat.h>
#include <Calendar/Recurrences/CalendarRecurrence.h>
#include <Calendar/Recurrences/DateCollection.h>
#include <Mapi/MapiTask.h>
#include <Mapi/MapiTaskState.h>
#include <Mapi/TaskSaveFormat.h>
#include <Mapi/MapiCalendar.h>
#include <Mapi/MapiMessage.h>
#include <Mapi/MapiAttachmentCollection.h>
#include <Mapi/MapiCalendarEventRecurrence.h>
#include <Mapi/MapiCalendarExceptionInfo.h>
#include <Mapi/MapiCalendarRecurrencePattern.h>
#include <Mapi/MapiCalendarRecurrencePatternFactory.h>
#include <Mapi/MapiCalendarDailyRecurrencePattern.h>
#include <Mapi/MapiCalendarWeeklyRecurrencePattern.h>
#include <Mapi/MapiCalendarMonthlyRecurrencePattern.h>
#include <Mapi/MapiCalendarRecurrencePatternType.h>
#include <Mapi/MapiCalendarRecurrenceEndType.h>
#include <Mapi/MapiCalendarDayOfWeek.h>
#include <system/text/encoding.h>
#include <system/convert.h>

using namespace System;
using namespace Aspose::Email;
using namespace Aspose::Email::Mapi;
using namespace Aspose::Email::Calendar;
using namespace Aspose::Email::Calendar::Recurrences;

고정된 발생 횟수를 가진 일일 시리즈

Outlook은 "이 날짜까지 반복"을 종료 날짜가 아니라 발생 횟수로 표현하므로, 특정 날짜에 중단되어야 하는 시리즈는 먼저 해당 횟수를 계산해야 합니다. CalendarRecurrence 산술 연산을 수행합니다: RRULE 문자열에서 구축하고 원하는 종료 날짜까지 확장합니다.

// Counts the occurrences a rule produces up to the given date
uint32_t GetOccurrenceCount(DateTime start, DateTime endBy, String rrule)
{
    SharedPtr<CalendarRecurrence> pattern = MakeObject<CalendarRecurrence>(
        String::Format(u"DTSTART:{0}\r\nRRULE:{1}", start.ToString(u"yyyyMMdd"), rrule));

    // the overload that takes only the end of the range counts from DTSTART
    SharedPtr<DateCollection> dates = pattern->GenerateOccurrences(endBy);
    return static_cast<uint32_t>(dates->get_Count());
}
DateTime startDate(2025, 7, 16);
DateTime dueDate(2025, 7, 16);
DateTime endByDate(2025, 8, 1);

SharedPtr<MapiTask> task = MakeObject<MapiTask>(u"This is a test task", u"Sample Body", startDate, dueDate);
task->set_State(MapiTaskState::NotAssigned);

// every day, ending after a fixed number of occurrences
SharedPtr<MapiCalendarDailyRecurrencePattern> recurrence = MakeObject<MapiCalendarDailyRecurrencePattern>();
recurrence->set_PatternType(MapiCalendarRecurrencePatternType::Day);
recurrence->set_Period(1);
recurrence->set_WeekStartDay(DayOfWeek::Sunday);
recurrence->set_EndType(MapiCalendarRecurrenceEndType::EndAfterNOccurrences);
recurrence->set_OccurrenceCount(GetOccurrenceCount(startDate, endByDate, u"FREQ=DAILY"));

if (recurrence->get_OccurrenceCount() == 0)
{
    recurrence->set_OccurrenceCount(1);
}

task->set_Recurrence(recurrence);
task->Save(u"DailyTask.msg", TaskSaveFormat::Msg);

Console::WriteLine(u"Occurrences: " + Convert::ToString(recurrence->get_OccurrenceCount()));

주간, 월간 및 연간 시리즈

주간 패턴에 DayOfWeek, 여러 요일이 결합된 플래그 열거형이 추가됩니다 |. 월간 패턴에 Day, 시리즈가 진행되는 월의 일입니다. 연간 시리즈는 12개월 주기의 월간 패턴입니다. NeverEnd 시리즈를 미정으로 남겨 두며, 이 경우 OccurrenceCount 사용되지 않습니다.

DateTime startDate(2025, 7, 16);
DateTime dueDate(2025, 7, 16);

SharedPtr<MapiTask> task = MakeObject<MapiTask>(u"This is a test task", u"Sample Body", startDate, dueDate);
task->set_State(MapiTaskState::NotAssigned);

// every second week, on Monday and Friday, ten times
SharedPtr<MapiCalendarWeeklyRecurrencePattern> weekly = MakeObject<MapiCalendarWeeklyRecurrencePattern>();
weekly->set_PatternType(MapiCalendarRecurrencePatternType::Week);
weekly->set_Period(2);
weekly->set_WeekStartDay(DayOfWeek::Sunday);
weekly->set_DayOfWeek(MapiCalendarDayOfWeek::Monday | MapiCalendarDayOfWeek::Friday);
weekly->set_EndType(MapiCalendarRecurrenceEndType::EndAfterNOccurrences);
weekly->set_OccurrenceCount(10);
task->set_Recurrence(weekly);
task->Save(u"WeeklyTask.msg", TaskSaveFormat::Msg);

// the 16th day of every month, without an end
SharedPtr<MapiCalendarMonthlyRecurrencePattern> monthly = MakeObject<MapiCalendarMonthlyRecurrencePattern>();
monthly->set_PatternType(MapiCalendarRecurrencePatternType::Month);
monthly->set_Period(1);
monthly->set_Day(16);
monthly->set_EndType(MapiCalendarRecurrenceEndType::NeverEnd);
task->set_Recurrence(monthly);
task->Save(u"MonthlyTask.msg", TaskSaveFormat::Msg);

// the same day every year: a monthly pattern with a period of twelve months
SharedPtr<MapiCalendarMonthlyRecurrencePattern> yearly = MakeObject<MapiCalendarMonthlyRecurrencePattern>();
yearly->set_PatternType(MapiCalendarRecurrencePatternType::Month);
yearly->set_Period(12);
yearly->set_Day(1);
yearly->set_EndType(MapiCalendarRecurrenceEndType::EndAfterNOccurrences);
yearly->set_OccurrenceCount(5);
task->set_Recurrence(yearly);
task->Save(u"YearlyTask.msg", TaskSaveFormat::Msg);

RRULE 문자열에서 패턴 구축

스케줄이 이미 iCalendar 텍스트(ICS 파일 또는 다른 시스템에서 가져온)로 존재하는 경우 - MapiCalendarRecurrencePatternFactory::FromString RFC 5545에 따라 구문 분석하고 MAPI 패턴을 생성합니다. EXDATE 항목이 들어갑니다 DeletedInstanceDates.

DateTime startDate(2025, 7, 16);
DateTime endDate(2025, 8, 1);

SharedPtr<MapiCalendar> calendar = MakeObject<MapiCalendar>(u"test location", u"test summary",
    u"test description", startDate, endDate);

String pattern =
    u"DTSTART;TZID=Europe/London:20250831T080000\r\n"
    u"DTEND;TZID=Europe/London:20250831T083000\r\n"
    u"RRULE:FREQ=DAILY;INTERVAL=1;COUNT=7\r\n"
    u"EXDATE:20250902T070000Z,20250904T070000Z";

// the RRULE text is turned into a MAPI recurrence pattern
calendar->get_Recurrence()->set_RecurrencePattern(MapiCalendarRecurrencePatternFactory::FromString(pattern));

calendar->Save(u"FromRRule.msg", AppointmentSaveFormat::Msg);

SharedPtr<MapiCalendarRecurrencePattern> parsed = calendar->get_Recurrence()->get_RecurrencePattern();
Console::WriteLine(u"Occurrences: " + Convert::ToString(parsed->get_OccurrenceCount()) +
    u", deleted instances: " + Convert::ToString(parsed->get_DeletedInstanceDates()->get_Count()));

위에서 구문 분석된 패턴은 7개의 발생과 2개의 삭제된 인스턴스를 보고합니다.

단일 발생에 자체 콘텐츠 할당

시리즈의 단일 발생은 다른 발생과 다를 수 있습니다 - 다른 회의실, 다른 주제, 그 회의에 첨부된 안건 등. 이러한 편차는 MapiCalendarExceptionInfo 객체가 추가된 예외 패턴 컬렉션. OriginalStartDate 교체되는 발생을 식별하고, 예외는 자체 첨부 컬렉션을 가집니다.

DateTime startDate = DateTime(2025, 7, 19).AddHours(12);

SharedPtr<MapiCalendar> calendar = MakeObject<MapiCalendar>(u"location1", u"summary1", u"description1",
    startDate, startDate.AddHours(1));

SharedPtr<MapiCalendarEventRecurrence> recurrence = MakeObject<MapiCalendarEventRecurrence>();
SharedPtr<MapiCalendarDailyRecurrencePattern> pattern = MakeObject<MapiCalendarDailyRecurrencePattern>();
pattern->set_PatternType(MapiCalendarRecurrencePatternType::Day);
pattern->set_Period(1);
pattern->set_EndType(MapiCalendarRecurrenceEndType::NeverEnd);
recurrence->set_RecurrencePattern(pattern);

// one occurrence differs from the rest of the series
DateTime exceptionDate = startDate.AddDays(3);
SharedPtr<MapiCalendarExceptionInfo> exception = MakeObject<MapiCalendarExceptionInfo>();
exception->set_Location(u"exceptionLoc");
exception->set_Subject(u"exceptionSubj");
exception->set_Body(u"exceptionBody");
exception->set_OriginalStartDate(exceptionDate);
exception->set_StartDateTime(exceptionDate);
exception->set_EndDateTime(exceptionDate.AddHours(5));

// and carries an attachment of its own
exception->set_Attachments(MakeObject<MapiAttachmentCollection>(calendar));
exception->get_Attachments()->Add(u"file.txt", System::Text::Encoding::get_ASCII()->GetBytes(u"hello, world!"));

pattern->get_Exceptions()->Add(exception);
pattern->get_ModifiedInstanceDates()->Add(exceptionDate);

calendar->set_Recurrence(recurrence);
calendar->Save(u"RecurrenceWithException.msg", AppointmentSaveFormat::Msg);

SharedPtr<MapiCalendar> reloaded = DynamicCast<MapiCalendar>(MapiMessage::Load(u"RecurrenceWithException.msg")->ToMapiMessageItem());
Console::WriteLine(u"Exceptions: " +
    Convert::ToString(reloaded->get_Recurrence()->get_RecurrencePattern()->get_Exceptions()->get_Count()));

관련 항목