本文整理汇总了C#中ExchangeService.GetUserAvailability方法的典型用法代码示例。如果您正苦于以下问题:C# ExchangeService.GetUserAvailability方法的具体用法?C# ExchangeService.GetUserAvailability怎么用?C# ExchangeService.GetUserAvailability使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExchangeService
的用法示例。
在下文中一共展示了ExchangeService.GetUserAvailability方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var url = "http://spsdevserver:9998/EWS/Exchange.asmx"; // "https://192.168.150.1/EWS/Exchange.asmx";
var username = "[email protected]"; //"MaryN";
var password = "password1"; //"[email protected]";
var domain = (string)null; //"CONTOSO";
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true; // ignore certificate errors for HTTPS
var exchange = new ExchangeService(ExchangeVersion.Exchange2007_SP1)
{
Url = new Uri(url),
Credentials = new WebCredentials(username, password, domain),
};
// req#1: this succeeds
Test("GetUserAvailability (FreeBusy only)",
() => exchange.GetUserAvailability(new[]{new AttendeeInfo{SmtpAddress = username}}, new TimeWindow(DateTime.Today, DateTime.Today.AddDays(1)), AvailabilityData.FreeBusy));
// req#2: this fails with an empty response
Test("GetUserAvailability (FreeBusyAndSuggestions)",
() => exchange.GetUserAvailability(new[]{new AttendeeInfo{SmtpAddress = username}}, new TimeWindow(DateTime.Today, DateTime.Today.AddDays(1)), AvailabilityData.FreeBusyAndSuggestions));
// req#3: this fails because the ResponseMessages xml element is empty
Test("CreateItem",
() =>
{
var appointment = new Appointment(exchange);
appointment.Start = DateTime.Today.AddHours(10);
appointment.End = DateTime.Today.AddHours(12);
appointment.Subject = "Test appointment";
appointment.Save();
});
}
示例2: GetSuggestedMeetingTimesAndFreeBusyInfo
private static GetUserAvailabilityResults GetSuggestedMeetingTimesAndFreeBusyInfo(ExchangeService service)
{
// Create a collection of attendees.
List<AttendeeInfo> attendees = new List<AttendeeInfo>();
attendees.Add(new AttendeeInfo()
{
SmtpAddress = "[email protected]", //get the current user email
AttendeeType = MeetingAttendeeType.Organizer
});
attendees.Add(new AttendeeInfo()
{
SmtpAddress = "[email protected]",
AttendeeType = MeetingAttendeeType.Required
});
// Specify options to request free/busy information and suggested meeting times.
AvailabilityOptions availabilityOptions = new AvailabilityOptions();
availabilityOptions.GoodSuggestionThreshold = 49;
availabilityOptions.MaximumNonWorkHoursSuggestionsPerDay = 0;
availabilityOptions.MaximumSuggestionsPerDay = 2;
// Note that 60 minutes is the default value for MeetingDuration, but setting it explicitly for demonstration purposes.
availabilityOptions.MeetingDuration = 60;
availabilityOptions.MinimumSuggestionQuality = SuggestionQuality.Good;
availabilityOptions.DetailedSuggestionsWindow = new TimeWindow(DateTime.Now.AddDays(1), DateTime.Now.AddDays(2));
availabilityOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;
// Return free/busy information and a set of suggested meeting times.
// This method results in a GetUserAvailabilityRequest call to EWS.
GetUserAvailabilityResults results = null;
results = service.GetUserAvailability(attendees,
availabilityOptions.DetailedSuggestionsWindow,
AvailabilityData.FreeBusyAndSuggestions,
availabilityOptions);
return results;
#region find the suggestions and availability
// Display suggested meeting times.
//Console.WriteLine("Availability for {0} and {1}", attendees[0].SmtpAddress, attendees[1].SmtpAddress);
//Console.WriteLine();
//foreach (Suggestion suggestion in results.Suggestions)
//{
// Console.WriteLine("Suggested date: {0}\n", suggestion.Date.ToShortDateString());
// Console.WriteLine("Suggested meeting times:\n");
// foreach (TimeSuggestion timeSuggestion in suggestion.TimeSuggestions)
// {
// Console.WriteLine("\t{0} - {1}\n",
// timeSuggestion.MeetingTime.ToShortTimeString(),
// timeSuggestion.MeetingTime.Add(TimeSpan.FromMinutes(availabilityOptions.MeetingDuration)).ToShortTimeString());
// }
//}
//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++;
//}
#endregion
}
示例3: buildCalAgenda
private void buildCalAgenda(DirectoryEntry result)
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.UseDefaultCredentials = true; // Use domain account for connecting
//service.Credentials = new WebCredentials("[email protected]", "password"); // used if we need to enter a password, but for now we are using domain credentials
//service.AutodiscoverUrl("[email protected]"); //XXX we should use the service user for webmgmt!
service.Url = new System.Uri("https://mail.aau.dk/EWS/exchange.asmx");
List<AttendeeInfo> attendees = new List<AttendeeInfo>();
attendees.Add(new AttendeeInfo()
{
SmtpAddress = result.Properties["userPrincipalName"].Value.ToString(),
AttendeeType = MeetingAttendeeType.Organizer
});
// Specify availability options.
AvailabilityOptions myOptions = new AvailabilityOptions();
myOptions.MeetingDuration = 30;
myOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;
// Return a set of free/busy times.
DateTime dayBegin = DateTime.Now.Date;
var window = new TimeWindow(dayBegin, dayBegin.AddDays(1));
GetUserAvailabilityResults freeBusyResults = service.GetUserAvailability(attendees,
window,
AvailabilityData.FreeBusy,
myOptions);
var sb = new StringBuilder();
// Display available meeting times.
DateTime now = DateTime.Now;
foreach (AttendeeAvailability availability in freeBusyResults.AttendeesAvailability)
{
foreach (CalendarEvent calendarItem in availability.CalendarEvents)
{
if (calendarItem.FreeBusyStatus != LegacyFreeBusyStatus.Free)
{
bool isNow = false;
if (now > calendarItem.StartTime && calendarItem.EndTime > now)
{
sb.Append("<b>");
isNow = true;
}
sb.Append(string.Format("{0}-{1}: {2}<br/>", calendarItem.StartTime.ToString("HH:mm"), calendarItem.EndTime.ToString("HH:mm"), calendarItem.FreeBusyStatus));
if (isNow)
{
sb.Append("</b>");
}
}
}
}
lblcalAgenda.Text = sb.ToString();
}