问题
The Problem
I need to be able to get appointment data from meeting rooms using the Exchange Managed API. I have had a service running for about a month that serves this purpose just fine by using ExchangeService.GetUserAvailability()
as follows:
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);
}
However, I have recently had to extend this service to perform some other tasks that have required larger spans of time (gone from one day to several months). This method becomes highly inefficient with an increase in time, and can occasionally throw errors when there are too many results.
The Question
Is this the most efficient way of going about this? I have found no better ways, but I would be grateful for confirmation.
回答1:
You can try using ExchangeService.FindItems which enables you to :
- use pagination to fetch huge resultsets.
- select the fields you want to get from the server
specify a SearchFilter that could filter this query server side :
from e in events where e.EndTime > time select e
回答2:
I Use Delegate,Hope usefull. Code Sample...
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);
来源:https://stackoverflow.com/questions/14723679/getting-room-appointments-efficiently-from-exchange