如何使后台代理检查新的源

时间:2013-09-28 00:26:48

标签: c# windows-phone-8 windows-phone rss-reader background-agents

我想让我的Windows Phone应用程序中的后台代理在后台检查新的feed,我使用webclient下载它们并将它们显示在列表框中我使用webbrowser控件向页面显示所选的feed来自我从syndicationitem获得的via url,现在我想保存让我们说标题或发布日期到隔离存储,并且后台代理每隔30分钟检查一次。对于Feed和检查是否有一些新的Feed可用,比较最后一个Feed标题或已经保存的最后一个publishdate和页面上的newsest,那么如果有更新的Feed,它应该发送一个带有feed标题的Toast通知,打开我的应用程序。

我之前没有做任何保存饲料,我不知道如何做到这一点,我不知道如何使用后台代理,并做我上面写的。我使用rss阅读器的Microsofts示例作为我的app逻辑的背景。下载,在此处显示所有类似示例 - http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh487167(v=vs.105).aspx

这里有一些代码:

我用它来下载提要

WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(new System.Uri("http://wpnovosti.com/feeds/posts/default?alt=rss"));

这是我用来在我的列表框中显示它们,并且还有一些实时图块的逻辑:

public void UpdateFeedList(string feedXML)
    {


        StringReader stringReader = new StringReader(feedXML);
        XmlReader xmlReader = XmlReader.Create(stringReader);
        SyndicationFeed feed = SyndicationFeed.Load(xmlReader);  

        Deployment.Current.Dispatcher.BeginInvoke(() =>
        {
            // Bind the list of SyndicationItems to our ListBox.
            feedListBox.ItemsSource = feed.Items;
            SystemTray.SetProgressIndicator(this, null);

            //Live Tiles
            ShellTile appTile = ShellTile.ActiveTiles.First();
            if (appTile != null)
            {
                FlipTileData TileData = new FlipTileData()
                {
                    Title = "",
                    BackTitle = "WP Novosti",
                    BackContent = feed.Items.First().Title.Text,
                    WideBackContent = feed.Items.First().Title.Text,
                    Count = 0,
                };

                appTile.Update(TileData);
            }
            else
            {
            }


        });

如果在列表框中选择了一个项目,我会使用

public void feedListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        ListBox listBox = sender as ListBox;


        if (listBox != null && listBox.SelectedItem != null)
        {
            // Get the SyndicationItem that was tapped.
            SyndicationItem sItem = (SyndicationItem)listBox.SelectedItem;


            // Set up the page navigation only if a link actually exists in the feed item.
            if (sItem.Links.Count > 0)
            {                   
               Uri uri = sItem.Links.FirstOrDefault().Uri;

               NavigationService.Navigate(new Uri("/Pregled.xaml?url=" + uri, UriKind.Relative));

               UpdateFeedList(State["feed"] as string);
            }

        }
    }

其余的只是通过webbrowser控件在另一个页面上显示这个传递的url。我怎么能让这个真正起作用,就像我想要在顶部描述一样?!

0 个答案:

没有答案