Callie J
Callie J

Reputation: 31296

Getting attendee from Exchange's GetUserAvailability() results

GetUserAvailability() in the Exchange Web Services API takes an IList of attendees and gives an set of results based on that list. Now from what I can tell, the AttendeesAvailability property doesn't have an field/indicator to say which attendee it's reporting the availability of.

I could make the assumption that attendee[0] == AttendeeAvailability[0], attendee[1] == AttendeeAvailability[1], and so on, however this isn't explicitly documented in MSDN as far as I can see so I don't want to rely on it. If it really is the case that it is a simple 1:1 match, I'd like to know where it's documented :-)

Have I missed something in the MSDN, or is the only way to guarantee the mapping (if mapping twixt the attendee ID and their availability matters) is to call GetUserAvailability() iteratively over the list?

For completeness, I'm calling GetUserAvailability as follows:

var options = new AvailabilityOptions
     {
         MeetingDuration = 30,
         RequestedFreeBusyView = FreeBusyViewType.DetailedMerged
     };

var attendees = new List<AttendeeInfo>()
attendees.Add(new AttendeeInfo { SmtpAddress = "[email protected]", AttendeeType = MeetingAttendeeType.Required);
attendees.Add(new AttendeeInfo { SmtpAddress = "[email protected]", AttendeeType = MeetingAttendeeType.Required);

var results = this.exchangeService.GetUserAvailability(
    attendees,
    new TimeWindow(DateTime.Now, DateTime.Now.AddDays(1)),
    AvailabilityData.FreeBusy,
    options);

foreach (AttendeeAvailability avail in results.AttendeesAvailability)
{
    // How to marry each AttendeeAvailability object with the appropriate attendee?
}

Upvotes: 4

Views: 2210

Answers (2)

Koce
Koce

Reputation: 116

I run into the same problem.

As I see in the example given in MSDN, they relied on the same assumption that attendees[0] == AttendeeAvailability[0]

https://msdn.microsoft.com/en-us/library/office/dn643673(v=exchg.150).aspx

 int i = 0;

// Display free/busy times.
foreach (AttendeeAvailability availability in results.AttendeesAvailability)
{
    Console.WriteLine("Availability information for {0}:\n", attendees[i].SmtpAddress);

    foreach (CalendarEvent calEvent in availability.CalendarEvents)
    {
        Console.WriteLine("\tBusy from {0} to {1} \n", calEvent.StartTime.ToString(), calEvent.EndTime.ToString());
    }

    i++;
}

Upvotes: 1

reinhoc
reinhoc

Reputation: 29

I have struggled through this as well and could not find documentation. So, there is no real way to "Marry" an appropriate attendee with the right event.

The workaround I have found through a lot of testing was that it gets all of the events for the first attendee then goes to the next attendee and finds all of those events and so on. So it is a 1:1 match as you mentioned. To keep track of which attendee was with which event I did this. It seems a little dodgy, but I did a lot of testing with this and it has worked for me.

var options = new AvailabilityOptions
     {
         MeetingDuration = 30,
         RequestedFreeBusyView = FreeBusyViewType.DetailedMerged
     };

var attendees = new List<AttendeeInfo>()
attendees.Add(new AttendeeInfo { SmtpAddress = "[email protected]", AttendeeType = MeetingAttendeeType.Required);
attendees.Add(new AttendeeInfo { SmtpAddress = "[email protected]", AttendeeType = MeetingAttendeeType.Required);

var results = this.exchangeService.GetUserAvailability(
    attendees,
    new TimeWindow(DateTime.Now, DateTime.Now.AddDays(1)),
    AvailabilityData.FreeBusy,
    options);
//This will represent the first attendee in your list.
int i = 0;
//I was passing strings around for my program. Not sure what you want with it.
StringBuilder sb = new StringBuilder();
foreach (AttendeeAvailability avail in results.AttendeesAvailability)
{
    sb.Append("Availability for: ").Append(attendees[i].SmtpAddress).Append("\n");
    foreach (CalendarEvent calItem in avail.CalendarEvents)
    {
       //The info you are looking for like Free/Busy or event times.
       //This is an example of their free busy status with start and end time of that event
       sb.Append(calItem.FreeBusyStatus).Append(": ").Append(calItem.StartTime);
       sb.Append(" - ").Append(calItem.EndTime).Append("\n");
    }
    //This will show the name of the next attendee through the next foreach loop
    i++;
}
return sb;

Upvotes: 3

Related Questions