从Exchange的GetUserAvailability()结果中获得与会者

时间:2014-09-12 12:33:13

标签: c# .net exchangewebservices

Exchange Web服务API中的

GetUserAvailability()需要IList的与会者,并根据该列表提供一组结果。现在从我所知道的情况来看,AttendeesAvailability属性没有一个字段/指示符来说明哪个与会者报告了其可用性。

我可以假设attendee[0] == AttendeeAvailability[0]attendee[1] == AttendeeAvailability[1]等,但是我没有在MSDN中明确记录,所以我不想要依靠它。如果它确实是一个简单的1:1匹配,我想知道它在哪里记录: - )

我是否遗漏了MSDN中的内容,或者是保证映射的唯一方法(如果映射参与者ID及其可用性很重要)是在列表上迭代调用GetUserAvailability()

为了完整起见,我按如下方式调用GetUserAvailability:

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

var attendees = new List<AttendeeInfo>()
attendees.Add(new AttendeeInfo { SmtpAddress = "bob@our.domain.org", AttendeeType = MeetingAttendeeType.Required);
attendees.Add(new AttendeeInfo { SmtpAddress = "alice@our.domain.org", 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?
}

2 个答案:

答案 0 :(得分:2)

我也在努力解决这个问题,无法找到文档。所以,没有真正的方法来&#34; Marry&#34;适当的与会者与合适的事件。

我通过大量测试找到的解决方法是,它为第一位与会者获取所有事件,然后转到下一位与会者并查找所有这些事件,依此类推。所以这是你提到的1:1比赛。 要跟踪哪个与会者与我做了哪个事件。这看起来有点狡猾,但我做了很多测试,它对我有用。

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

var attendees = new List<AttendeeInfo>()
attendees.Add(new AttendeeInfo { SmtpAddress = "bob@our.domain.org", AttendeeType = MeetingAttendeeType.Required);
attendees.Add(new AttendeeInfo { SmtpAddress = "alice@our.domain.org", 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;

答案 1 :(得分:1)

我遇到了同样的问题。

正如我在MSDN中给出的示例中看到的那样,他们依赖于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++;
}