Ejemplo n.º 1
0
        /// <summary>
        ///     Method called when PeriodicTask is invoked.
        /// </summary>
        /// <param name="task">Periodic task invoked.</param>
        protected override void OnInvoke(ScheduledTask task)
        {
            if (!new SettingsController().CatURLExists())
            {
                // Cat URL doesn't exist, so parse RSS.
                this.ParseRSSFeed();
            }
            else
            {
                // Cat URL exists, so perform date check.
                SettingsController settingsController = new SettingsController();

                if (settingsController.LastUpdatedExists())
                {
                    // lastUpdated setting exists, so check.
                    DateTime lastUpdated = new SettingsController().GetLastUpdated();
                    DateTime now = DateTime.Now;

                    if (lastUpdated.Date.CompareTo(now.Date) < 0)
                    {
                        // lastUpdated date is before Today, so parse RSS Feed to get a new image.
                        this.ParseRSSFeed();
                    }
                }
                else
                {
                    // lastUpdated setting doesn't exist, so parse RSS.
                    this.ParseRSSFeed();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Method to perform actions required once RSS Feed has been downloaded.
        /// </summary>
        /// <param name="sender">Sender object</param>
        /// <param name="e">Event arguments object</param>
        private void DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                // ERROR - Downloading RSS Feed. As can't continue PeriodicTask completes.
                this.NotifyComplete();
            }
            else
            {
                // RSS feed downloaded successfully, so get new image URL.
                string catImageURL = this.GetTodaysCatImageURL(e.Result);

                if (!catImageURL.Equals(string.Empty))
                {
                    // Obtained cat URL successfully.
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        SettingsController settingsController = new SettingsController();
                        StorageController storageController = new StorageController();

                        // Set cat URI
                        settingsController.SetCatURL(catImageURL);

                        // Set last updated setting.
                        settingsController.SetLastUpdated();

                        if (storageController.DownloadedCatImageExists())
                        {
                            // Cat image exists in memory, so delete.
                            storageController.DeleteDownloadedCatImage();
                        }

                        // Update live tile.
                        new LiveTileController().UpdateLiveTile();

                        // Notify PeriodicTask completion.
                        NotifyComplete();
                    });
                }
                else
                {
                    // ERROR - In getting Cat URL. As can't continue PeriodiTask completes.
                    this.NotifyComplete();
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Method to update content on the Application page.
        /// </summary>
        private void UpdateDisplay()
        {
            // Set text for date field.
            this.DateTextBlock.Text = DateTime.Now.ToString(LolCatCalendarResources.DateFormat);

            SettingsController settingsController = new SettingsController();
            StorageController storageController = new StorageController();

            if (settingsController.CatURLExists())
            {
                // Cat URL exists so use that image.
                if (storageController.DownloadedCatImageExists())
                {
                    // Downloaded cat image exists, so display that.
                    this.img.Source = storageController.GetDownloadedCatImage();
                }
                else
                {
                    // Downloaded cat iamge doesn't exist, so display from Internet and then download.
                    string url = settingsController.GetCatURL();

                    this.img.Source = new BitmapImage(new Uri(url));

                    new ImageDownloader().DownloadCatImage(url);
                }
            }
            else
            {
                // Cat URL doesn't exist, so get default cat image.
                this.img.Source = storageController.GetDefaultCatImage();
            }
        }