samedi 25 avril 2015

How to create a MeetingRequest using EWS that is available for all attendees


I'm stumped on how to create an appointment using the EWS Api with .NET that I know in advance is an available time.

I am building a program to book resources like conference rooms that automatically accept an invite if the time is open. But I have not figured out a way to determine for a resource calendar if the meeting I am trying to book will be accepted because that time is open.

Testing the value of Appointment.Save does not work, because I am trying to determine the schedule of the resource, not my own.

I have the following code so far which lists out the Busy times for each participant in a meeting request.

// Create a list of attendees.
 List<AttendeeInfo> attendees = new List<AttendeeInfo>();

 attendees.Add(new AttendeeInfo()
 {
     SmtpAddress = "steve@mycompany.com",
     AttendeeType = MeetingAttendeeType.Organizer
 });

 attendees.Add(new AttendeeInfo() 
 {
     SmtpAddress = "ConfRoom@mycompany.com",
     AttendeeType = MeetingAttendeeType.Required
 });

 // Specify availability options.
 AvailabilityOptions myOptions = new AvailabilityOptions();
 myOptions.MeetingDuration = 30;
 myOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;

 // Return a set of free/busy times.
 GetUserAvailabilityResults freeBusyResults = service.GetUserAvailability(attendees, 
                                                                      new TimeWindow(DateTime.Now.AddDays(2), DateTime.Now.AddDays(3)), 
                                                                          AvailabilityData.FreeBusy, 
                                                                          myOptions);
 // Determine available meeting times.

 foreach (AttendeeAvailability availability in freeBusyResults.AttendeesAvailability)
 {
         foreach (CalendarEvent calendarItem in availability.CalendarEvents)
     {
        // check CalendarEvent.FreeBusyStatus & .StartTime & .EndTime

     }
 }

The problem is the code only tells you booked appointments for the person you are scanning, not really their "Free" time. It only ever states "Free" if you have a calendar appointment that you have marked as Free (rather than Busy).

So to determine if a conference room is free, I have to do a FreeBusy scan than parse all the records returned, figure out if the time I want to book is available (which is not simple because my end time may overlap with a busy time), and then send an invitation using Appointment.Save.

Is there a EWS function that would let me do something like:

IsCalendarOpen = ExchangeService.IsAvailable("smtp resource name", startDatetime, endDatetime)


Aucun commentaire:

Enregistrer un commentaire