问题
我需要能够使用Exchange托管API从会议室获取约会数据。我已经有一个服务运行了大约一个月就可以使用ExchangeService.GetUserAvailability()
完成此目的,如下所示:
private IEnumerable<CalendarEvent> GetEvents(ExchangeService ExchangeService, string room, DateTime time, DateTime end)
{
List<AttendeeInfo> attendees = new List<AttendeeInfo>();
end = new DateTime(time.Ticks + Math.Max(end.Ticks - time.Ticks, time.AddDays(1).Ticks - time.Ticks));
AttendeeInfo roomAttendee = new AttendeeInfo();
roomAttendee.AttendeeType = MeetingAttendeeType.Room;
roomAttendee.SmtpAddress = GetEmailAddress(room);
attendees.Add(roomAttendee);
Collection<CalendarEvent> events = ExchangeService.GetUserAvailability(
attendees,
new TimeWindow(time, end),
AvailabilityData.FreeBusy
).AttendeesAvailability[0].CalendarEvents;
return (from e in events
where e.EndTime > time
select e);
}
但是,我最近不得不扩展此服务以执行一些需要更长时间(从一天到几个月)的其他任务。随着时间的增加,这种方法变得非常低效,并且当结果太多时偶尔会抛出错误。
问题
这是解决这个问题最有效的方法吗?我找不到更好的方法,但我很感激确认。
答案 0 :(得分:2)
您可以尝试使用ExchangeService.FindItems,以便:
指定可以过滤此查询服务器端的SearchFilter:
来自事件中的e 其中e.EndTime&gt;时间 选择e
答案 1 :(得分:0)
我使用委托,希望有用。代码示例......
ExchangeService service = new ExchangeService();
ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
service.Credentials = new NetworkCredential(username, password);
service.Url = new Uri("...");
List<DelegateUser> newDelegates = new System.Collections.Generic.List<DelegateUser>();
DelegateUser calendarDelegate = new DelegateUser(roomemail);
calendarDelegate.Permissions.CalendarFolderPermissionLevel = DelegateFolderPermissionLevel.Reviewer;
newDelegates.Add(calendarDelegate);