我使用EWS FindAppointment
获取日期(see here for why Im using FindAppointments rather the FindItems)
// Set the start and end time and number of appointments to retrieve.
CalendarView cView = new CalendarView(start, end, 1000);
// Retrieve a collection of appointments by using the calendar view.
FindItemsResults<Appointment> findAppointmentResults = calendar.FindAppointments(cView);
我枚举结果并仅创建List
Appointments
由于FindAppointment
没有为定期会议返回主人,因此我使用AppointmentType.Occurrence
约会来获取他们的主人
Appointment.BindToRecurringMaster(this.exchangeService, new ItemId(occurrence.Id.ToString()));
通过这个,我形成了我所有主人List
的另一个Appointment
。
我正在尝试使用Masters来检索系列中的每个约会,但那是我遇到麻烦的地方 我试图遍历列表(as shown here, MSDN)
public List<Appointment> getAllOccurrencesFromMaster(Appointment masterOccurrence) {
List<Appointment> retVal = new List<Appointment>();
int iCurrentIndex = 1;
DateTime occurStart = masterOccurrence.Start;
try {
// Get the appointment that is located at the current index in the series.
Appointment seriesAppt = Appointment.BindToOccurrence(this.exchangeService, new ItemId(masterOccurrence.Id.ToString()), iCurrentIndex);
retVal.Add(seriesAppt);
while (true) {
try {
Appointment appt = Appointment.BindToOccurrence(this.exchangeService, new ItemId(masterOccurrence.Id.ToString()), iCurrentIndex + 1);
retVal.Add(appt);
} catch (ServiceResponseException sre) {
Console.WriteLine("Occurrence with this index was previously deleted from the recurrence. " + sre.ToString());
} catch (Exception e) {
throw e;
}
}
iCurrentIndex++;
}
}catch (Exception e) {
if (e.Message == "Occurrence index is out of recurrence range.") {
Console.WriteLine("The end of the series has been reached.");
} else {
Console.WriteLine("bad error. " + e.ToString());
throw e;
}
}
return retVal;
}
我对上述代码的问题是,当达到已删除的项目时,它会抛出与索引超出范围时相同的异常:ServiceResponseException
。
这是一个问题,因为对于一个我想要继续而另一个我想要打破,我不打算根据消息文本切换。此外,我需要删除的事件。如何在定期系列中获得所有约会?
我还尝试使用Master Appointment的DeletedOccurances
属性,但没有任何条目填充了他们的ID。我们从Exchange到我们的系统进行单向同步,我需要知道删除了什么,以便我可以从我们的系统中删除它。我们会跟踪calenderItem.ID
,因此我需要在删除某些内容时知道要在我们的系统中删除哪个会议。
答案 0 :(得分:1)
而不是在系列中获得所有约会。我使用了Master Reurrence appointment.recurrence
对象以及删除和修改过的事件来弄清楚约会正在进行的事情,并在我们这方面正确同步。
答案 1 :(得分:1)
跟进很老了,但我需要迭代一个系列并遇到这篇文章。对原始问题的简短回答是使用ServiceResponseException.ErrorCode
,当您点击缺失的实例时会获得ErrorCalendarOccurrenceIsDeletedFromRecurrence
,而当您点击系列的结尾时会获得ErrorCalendarOccurrenceIndexIsOutOfRecurrenceRange
。 HTH某人。