예제 #1
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            // TODO: Insert path to own settings file where settings are stored in a key/value format like:
            // Key1 [value]
            // Key2 [value2]
            // Key3Array [value3,value4]
            var settingsKeyVals =
                await Task.Run(() => File.ReadAllLines("MagicPiMirrorSettings.txt"));

            await ApplicationDataController.LoadDefaultSettings(settingsKeyVals);

            //ApplicationLanguages.PrimaryLanguageOverride = "da-DK";
            ApplicationLanguages.PrimaryLanguageOverride = ApplicationDataController.GetValue(KeyNames.Language, string.Empty);

            await RefreshUiControls();

            // StartClockSync();
            StartClockBlinky();
            StartClock();
            await webServer.InitializeWebServer();

            await RefreshWeatherData();
            await RefreshCalendar();

            StartWeatherRefresher();
            StartCalendarRefresher();

            aiClient.TrackEvent("PageLoaded");
        }
예제 #2
0
 private async Task RefreshSpecialNote()
 {
     await RunOnDispatch(() =>
     {
         SpecialNote.Text = ApplicationDataController.GetValue(KeyNames.SpecialNote, string.Empty);
     });
 }
예제 #3
0
        private async Task RefreshWeatherData()
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                var weather             = new WeatherService(ApplicationDataController.GetValue(KeyNames.OpenWeatherMapApiKey, string.Empty), new CultureInfo(ApplicationLanguages.PrimaryLanguageOverride));
                WeatherData weatherData = null;
                try
                {
                    //weatherData = await weather.GetWeatherDataForCity(ApplicationDataController.GetValue(KeyNames.WeatherZip, string.Empty), ApplicationDataController.GetValue(KeyNames.WeatherCountry, string.Empty));
                    weatherData = await weather.GetWeatherDataForCity(ApplicationDataController.GetValue(KeyNames.WeatherCityName, string.Empty));
                }
                catch (WeatherServiceException weatherServiceException)
                {
                    await ShowMessageDialogIfSupported(weatherServiceException.Message, "Error");
                }

                if (weatherData == null)
                {
                    await ShowMessageDialogIfSupported(Strings.UnableToConnectToWeatherService, Strings.Error);
                }
                else
                {
                    WeatherIcon.Source = GetImageSourceFromUri(weatherData.WeatherIconUri.AbsolutePath);
                    LocationTxb.Text   = Strings.Get(weatherData.Location);
                    if (string.IsNullOrEmpty(LocationTxb.Text))
                    {
                        LocationTxb.Text = weatherData.Location;
                    }
                    TemperatureTxb.Text        = Math.Round(weatherData.Temp) + "°";
                    WeatherDescirptionTxb.Text = string.IsNullOrEmpty(weatherData.Description) ? string.Empty : weatherData.Description.ToLower();
                }
            });
        }
예제 #4
0
 private async Task RefreshSpecialNoteVisible()
 {
     await RunOnDispatch(() =>
     {
         if (ApplicationDataController.GetValue(KeyNames.SpecialNoteOn, false))
         {
             SpecialNote.Visibility = Visibility.Visible;
         }
         else
         {
             SpecialNote.Visibility = Visibility.Collapsed;
         }
     });
 }
예제 #5
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);
            });
        }