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


C# ExchangeService.FindAppointments方法代码示例

本文整理汇总了C#中ExchangeService.FindAppointments方法的典型用法代码示例。如果您正苦于以下问题:C# ExchangeService.FindAppointments方法的具体用法?C# ExchangeService.FindAppointments怎么用?C# ExchangeService.FindAppointments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExchangeService的用法示例。


在下文中一共展示了ExchangeService.FindAppointments方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetNextAppointments

        public AppointmentGroup GetNextAppointments()
        {
            try
            {
                var newAppointments = new AppointmentGroup();

                var service = new ExchangeService();
                service.UseDefaultCredentials = true;
                service.AutodiscoverUrl(UserPrincipal.Current.EmailAddress);

                DateTime from = DateTime.Now.AddMinutes(-5);
                DateTime to = DateTime.Today.AddDays(1);

                IEnumerable<Appointment> appointments =
                    service.FindAppointments(WellKnownFolderName.Calendar, new CalendarView(from, to))
                        .Select(MakeAppointment);

                newAppointments.Next =
                    appointments.Where(o => o != null && o.Start >= DateTime.Now)
                        .OrderBy(o => o.Start).ToList();

                nextAppointments = newAppointments;
                return newAppointments;
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
                return nextAppointments;
            }
        }
开发者ID:MatthewRichards,项目名称:better-outlook-reminder,代码行数:30,代码来源:OutlookService.cs

示例2: ThisMonthItems

        // URI like http://127.0.0.1:81/Schedule/ThisMonthItems?MailAddress=...&Password=...
        public ActionResult ThisMonthItems(O365AccountModel model)
        {
            // Exchange Online に接続 (今回はデモなので、Address は決めうち !)
            string emailAddress = model.MailAddress;
            string password = model.Password;
            ExchangeVersion ver = new ExchangeVersion();
            ver = ExchangeVersion.Exchange2010_SP1;
            ExchangeService sv = new ExchangeService(ver, TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time"));
            //sv.TraceEnabled = true; // デバッグ用
            sv.Credentials = new System.Net.NetworkCredential(emailAddress, password);
            //sv.EnableScpLookup = false;
            //sv.AutodiscoverUrl(emailAddress, AutodiscoverCallback);
            //sv.Url = new Uri(@"https://hknprd0202.outlook.com/EWS/Exchange.asmx");
            sv.Url = new Uri(model.Url);

            // 今月の予定 (Appointment) を取得
            //DateTime nowDate = DateTime.Now;
            DateTime nowDate = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.Now.ToUniversalTime(), "Tokyo Standard Time");
            DateTime firstDate = new DateTime(nowDate.Year, nowDate.Month, 1);
            DateTime lastDate = firstDate.AddDays(DateTime.DaysInMonth(nowDate.Year, nowDate.Month) - 1);
            CalendarView thisMonthView = new CalendarView(firstDate, lastDate);
            FindItemsResults<Appointment> appointRes = sv.FindAppointments(WellKnownFolderName.Calendar, thisMonthView);

            // 結果 (Json 値) を作成
            IList<object> resList = new List<object>();
            foreach (Appointment appointItem in appointRes.Items)
            {
                // (注意 : Json では、Date は扱えない !)
                resList.Add(new
                {
                    Subject = appointItem.Subject,
                    StartYear = appointItem.Start.Year,
                    StartMonth = appointItem.Start.Month,
                    StartDate = appointItem.Start.Day,
                    StartHour = appointItem.Start.Hour,
                    StartMinute = appointItem.Start.Minute,
                    StartSecond = appointItem.Start.Second
                });
            }
            return new JsonResult()
            {
                Data = resList,
                ContentEncoding = System.Text.Encoding.UTF8,
                ContentType = @"application/json",
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
开发者ID:tsmatsuz,项目名称:20110629_ExchangeOnlineSample,代码行数:48,代码来源:ScheduleController.cs

示例3: 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

示例4: InternalGetCalendar

        private async Task<CalendarModel> InternalGetCalendar(string id, DateTime start, DateTime end)
        {
            start = start.Date;
            end = end.Date;
            var credentials = credentialProvider.GetCredentials(id);
            if (credentials == null)
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, ""));

            var calendarModel = new CalendarModel
            {
                Owner = id,
            };

            switch (credentials.Type)
            {
                case "EWS":
                    var ewsService = new ExchangeService
                    {
                        Credentials = new WebCredentials(credentials.Username, credentials.Password, credentials.Domain),
                        Url = new Uri(credentials.ServiceUrl)
                    };
                    var week = ewsService.FindAppointments(WellKnownFolderName.Calendar,
                        new CalendarView(start, end.AddDays(1)));

                    calendarModel.Appointments = week.Select(a => new AppointmentModel
                    {
                        Subject = a.Subject,
                        StartTime = a.Start.ToUniversalTime(),
                        EndTime = a.End.ToUniversalTime(),
                        Duration = a.Duration,
                        IsPrivate =
                            a.Sensitivity == Sensitivity.Private || a.Sensitivity == Sensitivity.Confidential
                    });
                    break;
                case "ICS":
                    var cache = calendarCache.GetCalendar(id);
                    if (cache != null)
                    {
                        var icsServiceResponse = await icsService.GetIcsContent(credentials.ServiceUrl, cache.ETag);
                        if (icsServiceResponse.NotModified)
                        {
                            calendarModel.Appointments = cache.CalendarModel.Appointments;
                        }
                        else
                        {
                            calendarModel.Appointments = icsServiceResponse.Appointments;
                            calendarCache.PutCalendar(id,
                                new CalendarCacheEntry(id) { CalendarModel = calendarModel, ETag = icsServiceResponse.ETag });
                        }
                    }
                    else
                    {
                        var icsResponse = await icsService.GetIcsContent(credentials.ServiceUrl, string.Empty);
                        calendarModel.Appointments = icsResponse.Appointments;
                        calendarCache.PutCalendar(id,
                            new CalendarCacheEntry(id) { CalendarModel = calendarModel, ETag = icsResponse.ETag });
                    }
                    break;
                default:
                    throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ""));
            }

            // Now only return the appointments in the requested range
            return new CalendarModel
            {
                Owner = calendarModel.Owner,
                Appointments = calendarModel.Appointments
                    .Where(a => a != null &&
                                a.StartTime.Date >= start && a.StartTime.Date <= end)
                    .OrderBy(a => a.StartTime)
            };
        }
开发者ID:nicklasjepsen,项目名称:FamilyCalandarApi,代码行数:72,代码来源:CalendarController.cs


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