예제 #1
0
        private async void GetTodayEventsButton_Click(Object sender, RoutedEventArgs e)
        {
            try
            {
                var options = new List <QueryOption>
                {
                    new QueryOption("startDateTime", DateTime.Today.ToString("o")),
                    new QueryOption("endDateTime", DateTime.Today.AddDays(1).ToString("o"))
                };
                calendar = await graphClient.Me.Calendar.CalendarView.Request(options)
                           .Select("subject,organizer,location,start,end")
                           .GetAsync();

                MyEvents = new ObservableCollection <Models.Event>();

                foreach (var myEvent in calendar)
                {
                    MyEvents.Add(new Models.Event
                    {
                        Id      = myEvent.Id,
                        Subject = (myEvent.Subject != null) ?
                                  myEvent.Subject :
                                  "No subject",
                        Location = (myEvent.Location != null) ?
                                   myEvent.Location.DisplayName :
                                   "Unknown location",
                        Organizer = (myEvent.Organizer != null) ?
                                    myEvent.Organizer.EmailAddress.Name :
                                    "Unknown organizer",
                        Start = DateTime.Parse(myEvent.Start.DateTime).ToLocalTime(),
                        End   = DateTime.Parse(myEvent.End.DateTime).ToLocalTime()
                    });
                }

                EventCountTextBlock.Text   = $"You have {calendar.Count()} events today:";
                EventsDataGrid.ItemsSource = MyEvents;
            }
            catch (ServiceException ex)
            {
                EventCountTextBlock.Text = $"We could not get today's events: {ex.Error.Message}";
            }
        }