Beispiel #1
0
        private async Task UpdateNotificationsAsync(int newArticlesCount, Article newArticle)
        {
            if (newArticle != null)
            {
                Settings settings = IsolatedStorageHelper.GetObject <Settings>("Settings") ?? new Settings();
                newArticlesCount = IsolatedStorageHelper.GetInt("LastNewArticlesCount", 0) + newArticlesCount;

                if (settings != null && settings.IsToastNotificationUsed == true)
                {
                    bool canNotify = true;
                    if (settings.IsQuietHoursUsed == true)
                    {
                        if ((settings.QuietHoursStartTime.TimeOfDay < DateTime.Now.TimeOfDay) && (DateTime.Now.TimeOfDay < settings.QuietHoursEndTime.TimeOfDay))
                        {
                            canNotify = false;
                        }
                    }

                    if (canNotify)
                    {
                        try
                        {
                            ShellToast shellToast = new ShellToast {
                                Content = newArticle.Title, NavigationUri = new Uri(string.Format("/Views/MainPage.xaml?Id={0}&Category={1}", newArticle.ArticleId, TopStories), UriKind.Relative), Title = "The Hindu"
                            };
                            //if (IsTargetedVersion)
                            //{
                            //    SetProperty(shellToast, "Sound", new Uri(@"\Sounds\MyToastSound.mp3", UriKind.RelativeOrAbsolute));
                            //}

                            shellToast.Show();
                        }
                        catch (Exception exception)
                        {
                            if (Debugger.IsAttached)
                            {
                                Debug.WriteLine("ScheduledAgent:" + exception);
                            }
                        }
                    }
                }

                if (settings != null && settings.IsLiveTileSupport == true)
                {
                    try
                    {
                        if (!string.IsNullOrEmpty(newArticle.Thumbnail))
                        {
                            await DownLoadLiveTileAndShowAsync(newArticle);
                        }
                    }
                    catch (Exception exception)
                    {
                        if (Debugger.IsAttached)
                        {
                            Debug.WriteLine("ScheduledAgent:" + exception);
                        }
                    }
                }
                else
                {
                    try
                    {
                        ShellTile appTile = ShellTile.ActiveTiles.First();
                        if (appTile != null)
                        {
                            appTile.Delete();
                        }
                    }
                    catch (Exception exception)
                    {
                        if (Debugger.IsAttached)
                        {
                            Debug.WriteLine("ScheduledAgent:" + exception);
                        }
                    }
                }

                SaveSettingValueImmediately("LastNewArticlesCount", newArticlesCount);
                NotifyComplete();
            }
        }