繰り返しの管理
日次繰り返しの操作
Aspose.Email は MapiCalendarDailyRecurrencePattern を使用した日次繰り返しの作成をサポートします。EndAfterNOccurrences、EndAfterDate、NeverEnd の 3 つの異なる Mapi カレンダー繰り返し終了タイプを使用できます。このセクションでは、さまざまな日次繰り返しパターンの作成例を示します。
発生回数付きの日次繰り返し
このタイプの繰り返しでは、以下のように他の情報と共に繰り返し回数を設定します:
- 開始日、終了日、期限日を設定します。
- MapiTask を作成します。
- タスクの状態を NotAssigned に設定します。
- PatternType、Period、WeekStartDay、EndType、OccurenceCount などのプロパティを設定して、日次繰り返しオブジェクトを作成します。
- MapiTask.Recurrence プロパティにこの日次繰り返しオブジェクトを設定します。
- このメッセージをディスクに保存します。
以下のコードスニペットは、繰り返し終了タイプを EndAfterNOccurrence としたタスクの作成方法を示しています。
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Outlook();
TimeZone localZone = TimeZone.CurrentTimeZone;
TimeSpan timeSpan = localZone.GetUtcOffset(DateTime.Now);
DateTime StartDate = new DateTime(2015, 7, 16);
StartDate = StartDate.Add(timeSpan);
DateTime DueDate = new DateTime(2015, 7, 16);
DateTime endByDate = new DateTime(2015, 8, 1);
DueDate = DueDate.Add(timeSpan);
endByDate = endByDate.Add(timeSpan);
MapiTask task = new MapiTask("This is test task", "Sample Body", StartDate, DueDate);
task.State = MapiTaskState.NotAssigned;
// Set the Daily recurrence
var rec = new MapiCalendarDailyRecurrencePattern
{
PatternType = MapiCalendarRecurrencePatternType.Day,
Period = 1,
WeekStartDay = DayOfWeek.Sunday,
EndType = MapiCalendarRecurrenceEndType.EndAfterNOccurrences,
OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=DAILY"),
};
if (rec.OccurrenceCount==0)
{
rec.OccurrenceCount = 1;
}
task.Recurrence = rec;
task.Save(dataDir + "Daily_out.msg", TaskSaveFormat.Msg);
以下の関数は、2 つの日付間のイベント数を計算するために使用できます:
private static uint GetOccurrenceCount(DateTime start, DateTime endBy, string rrule)
{
CalendarRecurrence pattern = new CalendarRecurrence(string.Format("DTSTART:{0}\r\nRRULE:{1}", start.ToString("yyyyMMdd"), rrule));
DateCollection dates = pattern.GenerateOccurrences(start, endBy);
return (uint)dates.Count;
}
繰り返し回数の設定
以下のコードスニペットは、繰り返し回数の値を設定する方法を示しています。
// Set the Daily recurrence
var record = new MapiCalendarDailyRecurrencePattern
{
PatternType = MapiCalendarRecurrencePatternType.Day,
Period = 1,
WeekStartDay = DayOfWeek.Sunday,
EndType = MapiCalendarRecurrenceEndType.EndAfterNOccurrences,
OccurrenceCount = 5,
};
task.Recurrence = record;
日次繰り返し: EndAfterDate 終了タイプ
"End By" オプションは、GetOccurrenceCount() 関数で計算された OccurrenceCount プロパティを設定することで実現します。この関数は開始日、終了日、RRULE 文字列を受け取ります。
日次繰り返し: 毎日の値の設定
以下のコードスニペットは、RRULE 文字列で period 値と INTERVAL 値の両方を 1 に設定する方法を示しています。
// Set the Daily recurrence
var record = new MapiCalendarDailyRecurrencePattern
{
PatternType = MapiCalendarRecurrencePatternType.Day,
Period = 1,
EndType = MapiCalendarRecurrenceEndType.EndAfterDate,
OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=DAILY;INTERVAL=1"),
EndDate = endByDate
};
以下の例のように、Every Day の値は任意の適切な値に設定できます:
// Set the Daily recurrence
var record = new MapiCalendarDailyRecurrencePattern
{
PatternType = MapiCalendarRecurrencePatternType.Day,
Period = 2,
EndType = MapiCalendarRecurrenceEndType.EndAfterDate,
OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=DAILY;INTERVAL=2"),
};
日次繰り返し: NeverEnd 終了タイプ
終了タイプは MapiCalendarRecurrenceEndType.NeverEnd を使用して設定できます。以下の例では、Period または INTERVAL を必要な値(例: 1)に設定します。
// Set the Daily recurrence
var record = new MapiCalendarDailyRecurrencePattern
{
PatternType = MapiCalendarRecurrencePatternType.Day,
Period = 1,
EndType = MapiCalendarRecurrenceEndType.NeverEnd,
};
週次繰り返しの操作
Aspose.Email は MapiCalendarWeeklyRecurrencePattern を使用した週次繰り返しの作成に豊富な機能を提供します。EndAfterNOccurrences、EndAfterDate、NeverEnd の 3 つの異なる Mapi カレンダー繰り返し終了タイプを使用できます。このセクションでは、さまざまな週次繰り返しパターンの作成例を示します。
週次繰り返し: EndAfterNOccurrences 終了タイプ
このタイプの繰り返しでは、以下のように他の情報と共に繰り返し回数を設定します:
- 開始日、終了日、期限日を設定します。
- MapiTask を作成します。
- タスクの状態を NotAssigned に設定します。
- PatternType、Period、WeekStartDay、EndType、OccurrenceCount などのプロパティを設定して、週次繰り返しオブジェクトを作成します。
- MapiTask.Recurrence プロパティにこの週次繰り返しオブジェクトを設定します。
- このメッセージをディスクに保存します。
以下のコードスニペットは、繰り返し終了タイプを EndAfterNOccurrence としたタスクの作成方法を示します。
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Outlook();
TimeZone localZone = TimeZone.CurrentTimeZone;
TimeSpan ts = localZone.GetUtcOffset(DateTime.Now);
DateTime StartDate = new DateTime(2015, 7, 16);
StartDate = StartDate.Add(ts);
DateTime DueDate = new DateTime(2015, 7, 16);
DateTime endByDate = new DateTime(2015, 9, 1);
DueDate = DueDate.Add(ts);
endByDate = endByDate.Add(ts);
MapiTask task = new MapiTask("This is test task", "Sample Body", StartDate, DueDate);
task.State = MapiTaskState.NotAssigned;
// Set the weekly recurrence
var rec = new MapiCalendarWeeklyRecurrencePattern
{
EndType = MapiCalendarRecurrenceEndType.EndAfterNOccurrences,
PatternType = MapiCalendarRecurrencePatternType.Week,
Period = 1,
WeekStartDay = DayOfWeek.Sunday,
DayOfWeek = MapiCalendarDayOfWeek.Friday,
OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=WEEKLY;BYDAY=FR"),
};
if (rec.OccurrenceCount == 0)
{
rec.OccurrenceCount = 1;
}
task.Recurrence = rec;
task.Save(dataDir + "Weekly_out.msg", TaskSaveFormat.Msg);
以下の関数は、2 つの日付間のイベント数を計算するために使用できます:
private static uint GetOccurrenceCount(DateTime start, DateTime endBy, string rrule)
{
CalendarRecurrence pattern = new CalendarRecurrence(string.Format("DTSTART:{0}\r\nRRULE:{1}", start.ToString("yyyyMMdd"),rrule));
DateCollection dates = pattern.GenerateOccurrences(start, endBy);
return (uint)dates.Count;
}
週の複数の日を選択
以下のコードスニペットは、週の複数の日を選択する方法を示しています。
// Set the weekly recurrence
var rec = new MapiCalendarWeeklyRecurrencePattern
{
EndType = MapiCalendarRecurrenceEndType.EndAfterNOccurrences,
PatternType = MapiCalendarRecurrencePatternType.Week,
Period = 1,
WeekStartDay = DayOfWeek.Sunday,
DayOfWeek = MapiCalendarDayOfWeek.Friday | MapiCalendarDayOfWeek.Monday,
OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=WEEKLY;BYDAY=FR,MO"),
};
週の複数の日を選択し、間隔を設定
以下のコードスニペットは、週の複数の日を選択し、間隔を設定する方法を示しています。
// Set the weekly recurrence
var rec = new MapiCalendarWeeklyRecurrencePattern
{
EndType = MapiCalendarRecurrenceEndType.EndAfterNOccurrences,
PatternType = MapiCalendarRecurrencePatternType.Week,
Period = 2,
WeekStartDay = DayOfWeek.Sunday,
DayOfWeek = MapiCalendarDayOfWeek.Friday | MapiCalendarDayOfWeek.Monday,
OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=WEEKLY;BYDAY=FR,MO;INTERVAL=2"),
};
週次繰り返し: EndAfterDate 終了タイプ
"End By" オプションは、GetOccurrenceCount() 関数で計算された OccurrenceCount プロパティを設定することで実現します。この関数は開始日、終了日、RRULE 文字列を受け取ります。
週次繰り返し: 毎日の値の設定
以下のコードスニペットは、RRULE 文字列で period 値と INTERVAL 値の両方を 1 に設定する方法を示しています。
// Set the weekly recurrence
var rec = new MapiCalendarWeeklyRecurrencePattern
{
EndType = MapiCalendarRecurrenceEndType.EndAfterDate,
PatternType = MapiCalendarRecurrencePatternType.Week,
Period = 1,
WeekStartDay = DayOfWeek.Sunday,
DayOfWeek = MapiCalendarDayOfWeek.Friday,
EndDate = endByDate,
OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=WEEKLY;BYDAY=FR;INTERVAL=1"),
};
Every Day の値は任意の適切な値に設定でき、以下の例のように複数の日を選択できます:
var record = new MapiCalendarWeeklyRecurrencePattern
{
EndType = MapiCalendarRecurrenceEndType.EndAfterDate,
PatternType = MapiCalendarRecurrencePatternType.Week,
Period = 2,
WeekStartDay = DayOfWeek.Sunday,
EndDate = endByDate,
DayOfWeek = MapiCalendarDayOfWeek.Friday | MapiCalendarDayOfWeek.Monday,
OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=WEEKLY;BYDAY=FR,MO;INTERVAL=2"),
};
週次繰り返し: NeverEnd 終了タイプ
終了タイプは MapiCalendarRecurrenceEndType.NeverEnd を使用して設定できます。以下の例では、Period または INTERVAL を必要な値(例: 1)に設定します。
// Set the weekly recurrence
var recurrence = new MapiCalendarWeeklyRecurrencePattern
{
EndType = MapiCalendarRecurrenceEndType.NeverEnd,
PatternType = MapiCalendarRecurrencePatternType.Week,
Period = 1,
WeekStartDay = DayOfWeek.Sunday,
DayOfWeek = MapiCalendarDayOfWeek.Friday,
OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=WEEKLY;BYDAY=FR"),
};
月次繰り返しの操作
Aspose.Email は MapiCalendarMonthlyRecurrencePattern を使用した月次繰り返しの作成をサポートします。EndAfterNOccurrences、EndAfterDate、NeverEnd の 3 つの異なる Mapi カレンダー繰り返し終了タイプを使用できます。このセクションでは、さまざまな月次繰り返しパターンの作成例を示します。
月次繰り返し: EndAfterNOccurrences 終了タイプ
このタイプの繰り返しでは、以下のように他の情報と共に繰り返し回数を設定します:
- 開始日、終了日、期限日を設定します。
- MapiTask を作成します。
- タスクの状態を NotAssigned に設定します。
- PatternType、Period、WeekStartDay、EndType、OccurrenceCount などのプロパティを設定して、月次繰り返しオブジェクトを作成します。
- MapiTask.Recurrence プロパティにこの月次繰り返しオブジェクトを設定します。
- このメッセージをディスクに保存します。
以下のコードスニペットは、繰り返し終了タイプを EndAfterNOccurrence としたタスクの作成方法を示します。
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Outlook();
TimeZone localZone = TimeZone.CurrentTimeZone;
TimeSpan ts = localZone.GetUtcOffset(DateTime.Now);
DateTime StartDate = new DateTime(2015, 7, 16);
StartDate = StartDate.Add(ts);
DateTime DueDate = new DateTime(2015, 7, 16);
DateTime endByDate = new DateTime(2015, 12, 31);
DueDate = DueDate.Add(ts);
endByDate = endByDate.Add(ts);
MapiTask task = new MapiTask("This is test task", "Sample Body", StartDate, DueDate);
task.State = MapiTaskState.NotAssigned;
// Set the Monthly recurrence
var rec = new MapiCalendarMonthlyRecurrencePattern
{
Day = 15,
Period = 1,
PatternType = MapiCalendarRecurrencePatternType.Month,
EndType = MapiCalendarRecurrenceEndType.EndAfterNOccurrences,
OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=MONTHLY;BYMONTHDAY=15;INTERVAL=1"),
WeekStartDay = DayOfWeek.Monday,
};
if (rec.OccurrenceCount == 0)
{
rec.OccurrenceCount = 1;
}
task.Recurrence = rec;
//task.Save(dataDir + "Monthly_out.msg", TaskSaveFormat.Msg);
以下の関数は、2 つの日付間のイベント数を計算するために使用できます:
private static uint GetOccurrenceCount(DateTime start, DateTime endBy, string rrule)
{
CalendarRecurrence pattern = new CalendarRecurrence(string.Format("DTSTART:{0}\r\nRRULE:{1}", start.ToString("yyyyMMdd"), rrule));
DateCollection dates = pattern.GenerateOccurrences(start, endBy);
return (uint)dates.Count;
}
固定回数の繰り返し数を設定
以下のコードスニペットは、固定回数の繰り返し数を設定する方法を示します。
// Set the Monthly recurrence
var records = new MapiCalendarMonthlyRecurrencePattern
{
Day = 15,
Period = 1,
PatternType = MapiCalendarRecurrencePatternType.Month,
EndType = MapiCalendarRecurrenceEndType.EndAfterNOccurrences,
OccurrenceCount = 5,
WeekStartDay = DayOfWeek.Monday
};
月次繰り返し: EndAfterDate 終了タイプ
"End By" オプションは、GetOccurrenceCount() 関数で計算された OccurrenceCount プロパティを設定することで実現します。この関数は開始日、終了日、RRULE 文字列を受け取ります。以下のコードスニペットは、開始日と終了日で指定された期間の各月 15 日に繰り返しを作成する方法を示します。
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Outlook();
TimeZone localZone = TimeZone.CurrentTimeZone;
TimeSpan ts = localZone.GetUtcOffset(DateTime.Now);
DateTime StartDate = new DateTime(2015, 7, 1);
StartDate = StartDate.Add(ts);
DateTime DueDate = new DateTime(2015, 7, 1);
DateTime endByDate = new DateTime(2015, 12, 31);
DueDate = DueDate.Add(ts);
endByDate = endByDate.Add(ts);
MapiTask task = new MapiTask("This is test task", "Sample Body", StartDate, DueDate);
task.State = MapiTaskState.NotAssigned;
// Set the Monthly recurrence
var recurrence = new MapiCalendarMonthlyRecurrencePattern
{
Day = 15,
Period = 1,
PatternType = MapiCalendarRecurrencePatternType.Month,
EndType = MapiCalendarRecurrenceEndType.EndAfterDate,
OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=MONTHLY;BYMONTHDAY=15;INTERVAL=1"),
WeekStartDay = DayOfWeek.Monday,
EndDate = endByDate
};
task.Recurrence = recurrence;
//task.Save(dataDir + "SetMonthlyEndAfterDateRecurrence_out.msg", TaskSaveFormat.Msg);
月次繰り返し: NeverEnd 終了タイプ
以下のコードスニペットは、MapiCalendarRecurrenceEndType.NeverEnd を使用して終了タイプを設定する方法を示します。
var recurrence = new MapiCalendarMonthlyRecurrencePattern
{
Day = 15,
Period = 1,
PatternType = MapiCalendarRecurrencePatternType.Month,
EndType = MapiCalendarRecurrenceEndType.NeverEnd,
WeekStartDay = DayOfWeek.Monday,
};
年次繰り返しの操作
Aspose.Email は MapiCalendarMonthlyRecurrencePattern を使用した年次繰り返しの作成をサポートします。period プロパティを 12 に設定することで、年次繰り返しパターンを実現できます。EndAfterNOccurrences、EndAfterDate、NeverEnd の 3 つの異なる Mapi カレンダー繰り返し終了タイプを使用できます。このセクションでは、さまざまな年次繰り返しパターンの作成例を示します。
年次繰り返し: EndAfterNOccurrences 終了タイプ
このタイプの繰り返しでは、以下のように他の情報と共に繰り返し回数を設定します:
- 開始日、終了日、期限日を設定します。
- MapiTask を作成します。
- タスクの状態を NotAssigned に設定します。
- PatternType、Period、WeekStartDay、EndType、OccurrenceCount などのプロパティを設定して、月次繰り返しオブジェクトを作成します。
- MapiTask.Recurrence プロパティにこの月次繰り返しオブジェクトを設定して、年次繰り返しを実現します。
- このメッセージをディスクに保存します。
以下のコードスニペットは、繰り返し終了タイプを EndAfterNOccurrence としたタスクの作成方法を示します。
TimeZone localZone = TimeZone.CurrentTimeZone;
TimeSpan ts = localZone.GetUtcOffset(DateTime.Now);
DateTime StartDate = new DateTime(2015, 7, 1);
StartDate = StartDate.Add(ts);
DateTime DueDate = new DateTime(2015, 7, 1);
DateTime endByDate = new DateTime(2020, 12, 31);
DueDate = DueDate.Add(ts);
endByDate = endByDate.Add(ts);
MapiTask task = new MapiTask("This is test task", "Sample Body", StartDate, DueDate);
task.State = MapiTaskState.NotAssigned;
// Set the Yearly recurrence
var recurrence = new MapiCalendarMonthlyRecurrencePattern
{
Day = 15,
Period = 12,
PatternType = MapiCalendarRecurrencePatternType.Month,
EndType = MapiCalendarRecurrenceEndType.EndAfterNOccurrences,
OccurrenceCount = 3,
};
task.Recurrence = recurrence;
task.Save("Yearly.msg", TaskSaveFormat.Msg);
年次繰り返し: EndAfterDate 終了タイプ
"End By" オプションは、GetOccurrenceCount() 関数で計算された OccurrenceCount プロパティを設定することで実現します。この関数は開始日、終了日、RRULE 文字列を受け取ります。以下のコードスニペットは、開始日と終了日の間で 7 か月ごとの 15 日に繰り返しを作成する方法を示します。
// Set the Yearly recurrence
var rec = new MapiCalendarMonthlyRecurrencePattern
{
Day = 15,
Period = 12,
PatternType = MapiCalendarRecurrencePatternType.Month,
EndType = MapiCalendarRecurrenceEndType.EndAfterDate,
EndDate = endByDate,
OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=YEARLY;BYMONTHDAY=15;BYMONTH=7;INTERVAL=1"),
};
task.Recurrence = rec;
年次繰り返し: NeverEnd 終了タイプ
以下のコードスニペットは、MapiCalendarRecurrenceEndType.NeverEnd を使用して終了タイプを設定する方法を示します。
// Set the Yearly recurrence
var recurrence = new MapiCalendarMonthlyRecurrencePattern
{
Day = 15,
Period = 12,
PatternType = MapiCalendarRecurrencePatternType.Month,
EndType = MapiCalendarRecurrenceEndType.NeverEnd,
};
繰り返し規則から繰り返しを生成
Aspose.Email API は、Recurrence Rule (RRULE) から繰り返しパターンを生成する機能を提供します。RFC 5545 iCal 仕様に従って RRULE から情報を解析し、MapiCalendarRecurrencePatternFactory.FromString メソッドで繰り返しパターンを生成します。以下のコードスニペットは、RRULE から繰り返しパターンを生成する方法を示します。
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Outlook();
DateTime startDate = new DateTime(2015, 7, 16);
DateTime endDate = new DateTime(2015, 8, 1);
MapiCalendar app1 = new MapiCalendar("test location", "test summary", "test description", startDate, endDate);
app1.StartDate = startDate;
app1.EndDate = endDate;
string pattern = "DTSTART;TZID=Europe/London:20150831T080000\r\nDTEND;TZID=Europe/London:20150831T083000\r\nRRULE:FREQ=DAILY;INTERVAL=1;COUNT=7\r\nEXDATE:20150831T070000Z,20150904T070000Z";
app1.Recurrence.RecurrencePattern = MapiCalendarRecurrencePatternFactory.FromString(pattern);
繰り返しカレンダーイベントに添付ファイルを追加
Aspose.Email API は繰り返しカレンダーイベントに添付ファイルを追加する機能を提供します。
DateTime startDate = new DateTime(2018, 7, 19).AddHours(12);
MapiCalendar calendar = new MapiCalendar("location1", "summary1", "description1", startDate, startDate.AddHours(1));
MapiCalendarEventRecurrence recurrence = new MapiCalendarEventRecurrence();
MapiCalendarRecurrencePattern pattern = recurrence.RecurrencePattern = new MapiCalendarDailyRecurrencePattern();
pattern.PatternType = MapiCalendarRecurrencePatternType.Day;
pattern.Period = 1;
pattern.EndType = MapiCalendarRecurrenceEndType.NeverEnd;
DateTime exceptionDate = startDate.AddDays(3);
MapiCalendarExceptionInfo exception = new MapiCalendarExceptionInfo
{
Location = "exceptionLoc",
Subject = "exceptionSubj",
Body = "exceptionBody",
OriginalStartDate = exceptionDate,
StartDateTime = exceptionDate,
EndDateTime = exceptionDate.AddHours(5),
Attachments = new MapiAttachmentCollection(calendar)
};
exception.Attachments.Add("file.txt", Encoding.ASCII.GetBytes("hello, world!"));
pattern.Exceptions.Add(exception);
pattern.ModifiedInstanceDates.Add(exceptionDate);
pattern.DeletedInstanceDates.Add(exceptionDate);
calendar.Recurrence = recurrence;
using (var newPst = PersonalStorage.Create(dataDir + "AddAttachmentToMapiExceptionInfo.pst", FileFormatVersion.Unicode))
{
var newFolder = newPst.CreatePredefinedFolder("Calendar", StandardIpmFolder.Appointments);
newFolder.AddMapiMessageItem(calendar);
}