Пример #1
0
        private async Task RefreshCalendar()
        {
            var sw = Stopwatch.StartNew();

            var calendarService = new CalendarService(
                ApplicationDataController.GetValue(KeyNames.CalendarServiceUrl, string.Empty));

            var allAppointments = new List <Appointment>();

            foreach (var calendarId in ApplicationDataController.GetValue(KeyNames.CalendarIdentifiers, new string[] { }))
            {
                var calendar = await calendarService.GetCalendar(calendarId);

                if (calendar == null)
                {
                    continue;
                }
                allAppointments.AddRange(calendar.Appointments);
            }

            // We are displaying appointments for the next 7 days.
            var days = new Dictionary <DateTime, List <Appointment> >
            {
                { TimeManager.Today, new List <Appointment>() },
                { TimeManager.Today.AddDays(1), new List <Appointment>() },
                { TimeManager.Today.AddDays(2), new List <Appointment>() },
                { TimeManager.Today.AddDays(3), new List <Appointment>() },
                { TimeManager.Today.AddDays(4), new List <Appointment>() },
                { TimeManager.Today.AddDays(5), new List <Appointment>() },
                { TimeManager.Today.AddDays(6), new List <Appointment>() },
            };

            foreach (var appointment in allAppointments)
            {
                if (days.ContainsKey(appointment.StartTime.Date))
                {
                    days[appointment.StartTime.Date].Add(appointment);
                }
                else
                {
                    LogError("Appointment occurring on day that we can't display. Appointment StartDate=" +
                             appointment.StartTime);
                }
            }

            await RunOnDispatch(() =>
            {
                for (var i = 0; i < days.Count; i++)
                {
                    var currentDay = TimeManager.Today.AddDays(i);
                    var appointmentsForCurrentDay = days[currentDay];
                    var heading = (TextBlock)FindName($"Day{i}Txb");
                    Style appointmentHourStyle  = null;
                    Style appointmentEntryStyle = null;
                    if (heading == null)
                    {
                        LogError("Unable to find the heading textblock for the date " + currentDay);
                    }
                    else
                    {
                        if (currentDay.Date == TimeManager.Today)
                        {
                            heading.Text          = Strings.TodaysAgendaHeading;
                            appointmentHourStyle  = (Style)Resources["SmallTextStyle"];
                            appointmentEntryStyle = (Style)Resources["AppointmentEntryStyleMedium"];
                        }
                        else if (currentDay.Date == TimeManager.Today.AddDays(1))
                        {
                            appointmentHourStyle  = (Style)Resources["AppointmentHourStyle"];
                            appointmentEntryStyle = (Style)Resources["AppointmentEntryStyle"];
                            heading.Text          = Strings.TomorrowHeading;
                        }
                        else
                        {
                            appointmentHourStyle  = (Style)Resources["AppointmentHourStyle"];
                            appointmentEntryStyle = (Style)Resources["AppointmentEntryStyle"];
                            heading.Text          = GetDayOfWeek(currentDay.DayOfWeek).ToLower();
                        }
                    }

                    // Set appointments
                    var daySp = (StackPanel)FindName($"Day{i}Sp");
                    if (daySp == null)
                    {
                        LogError("Unable to find the calendar stack panel for the date " + currentDay);
                    }
                    else
                    {
                        daySp.Children.Clear();
                        var appointmentGrouping = appointmentsForCurrentDay
                                                  .GroupBy(a => a.StartTime.ToLocalTime().ToString(Strings.CalendarHourGroupByFormatString))
                                                  .OrderBy(ag => ag.Key);
                        if (!appointmentGrouping.Any())
                        {
                            daySp.Children.Add(new TextBlock
                            {
                                TextTrimming = TextTrimming.WordEllipsis,
                                Style        = appointmentEntryStyle,
                                Text         = Strings.NoAppointments
                            });
                        }
                        else
                        {
                            foreach (var ag in appointmentGrouping)
                            {
                                // Group by hour
                                var hourSp       = new StackPanel();
                                var hourHeadning = ag.Key;
                                if (hourHeadning.Length < 3)
                                {
                                    hourHeadning = hourHeadning + ":00";
                                }
                                hourSp.Children.Add(new TextBlock
                                {
                                    Style = appointmentHourStyle,
                                    Text  = hourHeadning,
                                });

                                foreach (var appointment in ag)
                                {
                                    var entry = new TextBlock
                                    {
                                        TextTrimming = TextTrimming.WordEllipsis,
                                        Style        = appointmentEntryStyle,
                                        Text         = appointment.Subject
                                    };
                                    hourSp.Children.Add(entry);
                                }

                                daySp.Children.Add(hourSp);
                            }
                        }
                    }
                }
                var tc = new TelemetryClient();
                tc.TrackMetric("Refresh Calendar Time Ms", sw.Elapsed.TotalMilliseconds);
            });
        }
Пример #2
0
        private async Task RefreshCalendar()
        {
            var sw = Stopwatch.StartNew();

            var calendarService = new CalendarService(
                ApplicationDataController.GetValue(KeyNames.CalendarServiceUrl, string.Empty));

            var allAppointments = new List<Appointment>();
            foreach (var calendarId in ApplicationDataController.GetValue(KeyNames.CalendarIdentifiers, new string[] { }))
            {
                var calendar = await calendarService.GetCalendar(calendarId);
                if (calendar == null)
                    continue;
                allAppointments.AddRange(calendar.Appointments);
            }

            // We are displaying appointments for the next 7 days.
            var days = new Dictionary<DateTime, List<Appointment>>
            {
                {TimeManager.Today, new List<Appointment>()},
                {TimeManager.Today.AddDays(1), new List<Appointment>()},
                {TimeManager.Today.AddDays(2), new List<Appointment>()},
                {TimeManager.Today.AddDays(3), new List<Appointment>()},
                {TimeManager.Today.AddDays(4), new List<Appointment>()},
                {TimeManager.Today.AddDays(5), new List<Appointment>()},
                {TimeManager.Today.AddDays(6), new List<Appointment>()},
            };

            foreach (var appointment in allAppointments)
            {
                if (days.ContainsKey(appointment.StartTime.Date))
                {
                    days[appointment.StartTime.Date].Add(appointment);
                }
                else
                {
                    LogError("Appointment occurring on day that we can't display. Appointment StartDate=" +
                              appointment.StartTime);
                }
            }

            await RunOnDispatch(() =>
            {
                for (var i = 0; i < days.Count; i++)
                {
                    var currentDay = TimeManager.Today.AddDays(i);
                    var appointmentsForCurrentDay = days[currentDay];
                    var heading = (TextBlock)FindName($"Day{i}Txb");
                    Style appointmentHourStyle = null;
                    Style appointmentEntryStyle = null;
                    if (heading == null)
                    {
                        LogError("Unable to find the heading textblock for the date " + currentDay);
                    }
                    else
                    {
                        if (currentDay.Date == TimeManager.Today)
                        {
                            heading.Text = Strings.TodaysAgendaHeading;
                            appointmentHourStyle = (Style)Resources["SmallTextStyle"];
                            appointmentEntryStyle = (Style)Resources["AppointmentEntryStyleMedium"];
                        }
                        else if (currentDay.Date == TimeManager.Today.AddDays(1))
                        {
                            appointmentHourStyle = (Style) Resources["AppointmentHourStyle"];
                            appointmentEntryStyle = (Style) Resources["AppointmentEntryStyle"];
                            heading.Text = Strings.TomorrowHeading;
                        }
                        else
                        {
                            appointmentHourStyle = (Style)Resources["AppointmentHourStyle"];
                            appointmentEntryStyle = (Style)Resources["AppointmentEntryStyle"];
                            heading.Text = GetDayOfWeek(currentDay.DayOfWeek).ToLower();
                        }
                    }

                    // Set appointments
                    var daySp = (StackPanel)FindName($"Day{i}Sp");
                    if (daySp == null)
                    {
                        LogError("Unable to find the calendar stack panel for the date " + currentDay);
                    }
                    else
                    {
                        daySp.Children.Clear();
                        var appointmentGrouping = appointmentsForCurrentDay
                            .GroupBy(a => a.StartTime.ToLocalTime().ToString(Strings.CalendarHourGroupByFormatString))
                            .OrderBy(ag => ag.Key);
                        if (!appointmentGrouping.Any())
                        {
                            daySp.Children.Add(new TextBlock
                            {
                                TextTrimming = TextTrimming.WordEllipsis,
                                Style = appointmentEntryStyle,
                                Text = Strings.NoAppointments
                            });
                        }
                        else
                            foreach (var ag in appointmentGrouping)
                            {
                                // Group by hour
                                var hourSp = new StackPanel();
                                var hourHeadning = ag.Key;
                                if (hourHeadning.Length < 3)
                                    hourHeadning = hourHeadning + ":00";
                                hourSp.Children.Add(new TextBlock
                                {
                                    Style = appointmentHourStyle,
                                    Text = hourHeadning,
                                });

                                foreach (var appointment in ag)
                                {
                                    var entry = new TextBlock
                                    {
                                        TextTrimming = TextTrimming.WordEllipsis,
                                        Style = appointmentEntryStyle,
                                        Text = appointment.Subject
                                    };
                                    hourSp.Children.Add(entry);
                                }

                                daySp.Children.Add(hourSp);
                            }
                    }
                }
                var tc = new TelemetryClient();
                tc.TrackMetric("Refresh Calendar Time Ms", sw.Elapsed.TotalMilliseconds);
            });

        }