当前位置: 首页>>代码示例>>C#>>正文


C# ExchangeService.GetRooms方法代码示例

本文整理汇总了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;
        }
开发者ID:liliankasem,项目名称:ProjectSpike,代码行数:64,代码来源:ValuesController.cs


注:本文中的ExchangeService.GetRooms方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。