Exemplo n.º 1
0
        private void ReminderTick(object sender, EventArgs e)
        {
            var todays_menu = MenuRepository.GetTodaysMenu();

            NotificationService.ShowNotification(todays_menu, () => MainWindow.Open(todays_menu));

            if (!string.IsNullOrWhiteSpace(Settings.ReminderEmail))
            {
                EmailService.Send(todays_menu);
            }

            SetTimeToNextReminder();
        }
Exemplo n.º 2
0
        private async void CheckForUpdates(object sender, EventArgs args)
        {
            // Make sure we don't start multiple updates simultaneously
            if (is_updating)
            {
                return;
            }
            is_updating = true;

            logger.Debug("Checking for new menus...");

            if (Settings.ShowNotificationOnUpdate)
            {
                var checking_menus_message = LocalizationService.Localize("CheckingMenusNotification");
                NotificationService.ShowNotification(checking_menus_message);
            }

            var notify_updates = false;

            try
            {
                logger.Debug("Downloading page: " + main_page_url);
                var page = await DownloadPage(main_page_url);

                var menus = await ParseWeekMenus(page);

                foreach (var menu in menus.Where(menu => !MenuRepository.HasMenuforWeek(menu.Week)))
                {
                    logger.Debug("Downloading page: " + menu.Link);
                    var week_page = await DownloadPage(menu.Link);

                    var start_of_week_date = DateUtils.FirstDateOfWeek(menu.Year, menu.Week);

                    var day_menus = await ParseMenu(week_page, start_of_week_date);

                    foreach (var day_menu in day_menus)
                    {
                        menu.Add(day_menu);
                    }

                    // Set the correct (localized) header
                    var menu_header = LocalizationService.Localize("WeeklyMenuHeader");
                    menu.SetLanguage(menu_header);

                    MenuRepository.Add(menu);
                    notify_updates = true;

                    if (Settings.ShowNotificationOnUpdate)
                    {
                        // Make a copy of the menu reference for the notification action
                        var temp_menu         = menu;
                        var new_menus_message = LocalizationService.Localize("NewMenusNotification") + menu.Header;
                        NotificationService.ShowNotification(new_menus_message, () => MainWindow.Open(temp_menu));
                    }
                }
            }
            catch (WebException we)
            {
                Settings.AutomaticMenuUpdate = false;

                // Create message
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(string.Format("Couldn't check for menus... ({0})", we.Message));
                sb.AppendLine();
                sb.Append("Disabling automatic updates (fix and reenable in settings)");
                // Show and log message
                logger.Debug(sb.ToString());
                MainWindow.Open(); // Ensure that we can see the error message (because it needs an owner window)
                DialogService.ShowOkMessage(sb.ToString(), "Error");
            }
            finally
            {
                if (notify_updates)
                {
                    NotifyMenusUpdated();
                }

                is_updating = false;
            }
        }