本文整理汇总了C#中ExchangeService.GetRooms方法的典型用法代码示例。如果您正苦于以下问题:C# ExchangeService.GetRooms方法的具体用法?C# ExchangeService.GetRooms怎么用?C# ExchangeService.GetRooms使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExchangeService
的用法示例。
在下文中一共展示了ExchangeService.GetRooms方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FreeRoom
private string FreeRoom(string roomName)
{
// ToDo: error stategy to be implemented
// log into Officee 365
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
//service.Credentials = new WebCredentials("[email protected]", "Passw0rd!");
service.Credentials = new WebCredentials("[email protected]", "Passw0rd!");
//service.Credentials = new WebCredentials("[email protected]", "");
service.UseDefaultCredentials = false;
service.AutodiscoverUrl("[email protected]", RedirectionUrlValidationCallback);
//EmailMessage email = new EmailMessage(service);
//email.ToRecipients.Add("[email protected]");
//email.Subject = "HelloWorld";
//email.Body = new MessageBody("This is the first email I've sent by using the EWS Managed API.");
//email.Send();
// GetRoomLists
EmailAddressCollection roomGroup = service.GetRoomLists();
// GetRooms(roomGroup)
Collection<EmailAddress> rooms = service.GetRooms(roomGroup[0]);
string response = "No meeting room found";
//if the room.Address matchaes the one you are looking for then
foreach (EmailAddress room in rooms)
{
if (room.Name == roomName)
{
Mailbox mailBox = new Mailbox(room.Address, "Mailbox");
//Mailbox mailBox = new Mailbox("[email protected]", "Mailbox");
// Create a FolderId instance of type WellKnownFolderName.Calendar and a new mailbox with the room's address and routing type
FolderId folderID = new FolderId(WellKnownFolderName.Calendar, mailBox);
// Create a CalendarView with from and to dates
DateTime start = DateTime.Now.ToUniversalTime().AddHours(-8);
DateTime end = DateTime.Now.ToUniversalTime().AddHours(5);
//end.AddHours(3);
CalendarView calendarView = new CalendarView(start, end);
// Call findAppointments on FolderId populating CalendarView
FindItemsResults<Appointment> appointments = service.FindAppointments(folderID, calendarView);
// Iterate the appointments
if (appointments.Items.Count == 0)
response = "The room is free";
else
{
DateTime appt = appointments.Items[0].Start;
TimeSpan test = DateTime.Now.Subtract(appt);
int t = (int)Math.Round(Convert.ToDecimal(test.TotalMinutes.ToString()));
if (test.TotalMinutes < 0)
response = "a meeting is booked at this time";
else
response = "the room is free for " + t.ToString() + "minutes";
}
Console.WriteLine(response);
}
}
return response;
}