GetUserAvailabilityResults在Exchange Web服务的工作时间之外显示结果
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GetUserAvailabilityResults在Exchange Web服务的工作时间之外显示结果相关的知识,希望对你有一定的参考价值。
GetUserAvailabilityResults显示Exchange Web服务中工作时间以外的结果,尽管我已设置MaximumNonWorkHoursSuggestionsPerDay = 0此外,我想知道如何获取和设置工作时间。而且,results.AttendeesAvailability返回null
private static void GetSuggestedMeetingTimes(ExchangeService service)
{
// Create a list of attendees.
List<AttendeeInfo> attendees = new List<AttendeeInfo>();
attendees.Add(new AttendeeInfo()
{
SmtpAddress = "vrr@e.edu.sa",
AttendeeType = MeetingAttendeeType.Organizer
});
attendees.Add(new AttendeeInfo()
{
SmtpAddress = "abc@e.edu.sa",
AttendeeType = MeetingAttendeeType.Required
});
AvailabilityOptions meetingOptions = new AvailabilityOptions();
meetingOptions.MeetingDuration = 30;
meetingOptions.MaximumNonWorkHoursSuggestionsPerDay = 0;
meetingOptions.GoodSuggestionThreshold = 49;
meetingOptions.MinimumSuggestionQuality = SuggestionQuality.Good;
meetingOptions.DetailedSuggestionsWindow = new TimeWindow(DateTime.Now, DateTime.Now.AddDays(2));
meetingOptions.MaximumSuggestionsPerDay = 48;
// Return a set of of suggested meeting times.
GetUserAvailabilityResults results = service.GetUserAvailability(attendees,
new TimeWindow(DateTime.Now, DateTime.Now.AddDays(2)),
AvailabilityData.Suggestions,
meetingOptions);
// Console.WriteLine(results.AttendeesAvailability[0].WorkingHours.EndTime);
// Display available meeting times.
Console.WriteLine("Availability for {0} and {1}", attendees[0].SmtpAddress, attendees[0].SmtpAddress);
Console.WriteLine();
//foreach (AttendeeAvailability aa in results.AttendeesAvailability)
//{
// //Console.WriteLine(aa.Result.Date);
// Console.WriteLine(aa.CalendarEvents.Count);
//}
foreach (Suggestion suggestion in results.Suggestions)
{
Console.WriteLine(suggestion.Date);
Console.WriteLine();
foreach (TimeSuggestion timeSuggestion in suggestion.TimeSuggestions)
{
Console.WriteLine("Suggested meeting time:" + timeSuggestion.MeetingTime);
Console.WriteLine();
}
}
}
答案
在Exchange中,为每个用户单独维护工作时间。每个用户都可以有自己的工作时间(虽然对于1个组织的员工来说似乎不合理)
GetUserAvailabilityResults在工作时间以外提供建议,因为参与者的工作时间之一与另一个不同
您无法为用户设置工作时间(据我所知)但是每个用户都可以使用outlook Outlook Change working hour更改工作时间
您可以使用results.AttendeesAvailability查看每个与会者的工作时间
结果。如果使用AvailabilityData.FreeBusyAndSuggestions而不是AvailabilityData.Suggestions,则attendeesAvailability将不会为null,以下是修改后的代码
private static void GetSuggestedMeetingTimes(ExchangeService service)
{
// Create a list of attendees.
List<AttendeeInfo> attendees = new List<AttendeeInfo>();
attendees.Add(new AttendeeInfo()
{
SmtpAddress = "shomaail@kfupm.edu.sa",
AttendeeType = MeetingAttendeeType.Required,
ExcludeConflicts = false
});
attendees.Add(new AttendeeInfo()
{
SmtpAddress = "vrr@kfupm.edu.sa",
AttendeeType = MeetingAttendeeType.Required
});
AvailabilityOptions meetingOptions = new AvailabilityOptions();
meetingOptions.MeetingDuration = 30;
meetingOptions.MaximumNonWorkHoursSuggestionsPerDay = 0;
meetingOptions.GoodSuggestionThreshold = 49;
meetingOptions.MinimumSuggestionQuality = SuggestionQuality.Excellent;
meetingOptions.DetailedSuggestionsWindow = new TimeWindow(DateTime.Now, DateTime.Now.AddDays(2));
meetingOptions.MaximumSuggestionsPerDay = 48;
// Return a set of of suggested meeting times.
GetUserAvailabilityResults results = service.GetUserAvailability(attendees,
new TimeWindow(DateTime.Now, DateTime.Now.AddDays(2)),
AvailabilityData.FreeBusyAndSuggestions,
meetingOptions);
// Console.WriteLine(results.AttendeesAvailability[0].WorkingHours.EndTime);
// Display available meeting times.
Console.WriteLine("Availability for {0} and {1}", attendees[0].SmtpAddress, attendees[1].SmtpAddress);
Console.WriteLine();
foreach (AttendeeAvailability aa in results.AttendeesAvailability)
{
Console.WriteLine("=============================================");
Console.WriteLine(aa.Result.ToString());
Console.WriteLine(aa.ViewType.ToString());
Console.WriteLine(aa.CalendarEvents.Count);
Console.WriteLine(aa.WorkingHours.StartTime);
Console.WriteLine(aa.WorkingHours.EndTime);
Console.WriteLine(aa.WorkingHours.DaysOfTheWeek.Count);
Console.WriteLine(aa.WorkingHours.DaysOfTheWeek[0]);
Console.WriteLine(aa.WorkingHours.DaysOfTheWeek[aa.WorkingHours.DaysOfTheWeek.Count-1]);
foreach (DayOfTheWeek dow in aa.WorkingHours.DaysOfTheWeek)
{
Console.WriteLine(dow);
}
}
foreach (Suggestion suggestion in results.Suggestions)
{
Console.WriteLine(suggestion.Date);
Console.WriteLine();
foreach (TimeSuggestion timeSuggestion in suggestion.TimeSuggestions)
{
Console.WriteLine("Suggested meeting time:" + timeSuggestion.MeetingTime);
Console.WriteLine();
}
}
}
以上是关于GetUserAvailabilityResults在Exchange Web服务的工作时间之外显示结果的主要内容,如果未能解决你的问题,请参考以下文章