Exemplo n.º 1
0
 /// <summary>
 /// 读取数据文件中的文章数据
 /// </summary>
 /// <param name="loadFeed"></param>
 /// <returns>读取到的文章数量</returns>
 public int loadFeedItems(Feed loadFeed) {
     loadFeed.Items.Clear();
     IXmlNode database = dbDoc.SelectSingleNode("database");
     IXmlNode feedXml = database.SelectSingleNode("feed[uniqueId='" + loadFeed.UniqueId + "']");
     if (feedXml == null) return 0;
     XmlNodeList feeditemXmlList = feedXml.SelectNodes("feeditem");
     foreach (IXmlNode feeditemXml in feeditemXmlList) {
         FeedItem feedItem = new FeedItem();
         feedItem.Title = feeditemXml.SelectSingleNode("title").InnerText;
         feedItem.PubDate = DateTime.Parse(feeditemXml.SelectSingleNode("pubdate").InnerText);
         feedItem.Author = feeditemXml.SelectSingleNode("author").InnerText;
         feedItem.Content = feeditemXml.SelectSingleNode("content").InnerText;
         feedItem.Link = new Uri(feeditemXml.SelectSingleNode("link").InnerText);
         feedItem.IsRead = Boolean.Parse(feeditemXml.SelectSingleNode("isread").InnerText);
         feedItem.Feed = loadFeed;
         loadFeed.Items.Add(feedItem);
     }
     return feeditemXmlList.Count;
 }
Exemplo n.º 2
0
 /// <summary>
 /// 将Feed中指定的文章标记为未读
 /// </summary>
 /// <param name="item"></param>
 public async Task noReadFeedItem(FeedItem item) {
     IXmlNode database = dbDoc.SelectSingleNode("database");
     IXmlNode feedXml = database.SelectSingleNode("feed[uniqueId='" + item.Feed.UniqueId + "']");
     IXmlNode feeditemXml = feedXml.SelectSingleNode("feeditem[link='" + item.Link + "']");
     noReadFeedItemXml(feeditemXml);
     await saveCache();
 }
Exemplo n.º 3
0
        public async Task loadFeedAsync(Feed loadFeed) {
            // using Windows.Web.Syndication;
            SyndicationClient client = new SyndicationClient();

            try {
                SyndicationFeed synFeed = await client.RetrieveFeedAsync(loadFeed.Source);

                // This code is executed after RetrieveFeedAsync returns the SyndicationFeed.
                // Process it and copy the data we want into our FeedData and FeedItem classes.

                if (loadFeed.Title.Trim().Length == 0) {
                    loadFeed.Title = synFeed.Title.Text;
                }
                if (synFeed.Subtitle.Text != null && synFeed.Subtitle.Text.Trim().Length != 0) {
                    loadFeed.Subtitle = synFeed.Subtitle.Text;
                }
                if (synFeed.Items.Count != 0) {
                    loadFeed.Description = synFeed.Items[0].Title.Text;
                }
                // Use the date of the latest post as the last updated date.
                loadFeed.PubDate = synFeed.Items[0].PublishedDate.DateTime;

                // 加载Feed中的文章,并保存到DB中
                List<FeedItem> feedItemList = new List<FeedItem>();
                foreach (SyndicationItem item in synFeed.Items) {
                    FeedItem feedItem = new FeedItem();
                    feedItem.Title = item.Title.Text;
                    feedItem.PubDate = item.PublishedDate.DateTime;
                    feedItem.Author = item.Authors[0].Name.ToString();
                    // Handle the differences between RSS and Atom feeds
                    if (synFeed.SourceFormat == SyndicationFormat.Atom10) {
                        feedItem.Content = item.Content.Text;
                        feedItem.Link = new Uri("http://windowsteamblog.com" + item.Id);
                    } else if (synFeed.SourceFormat == SyndicationFormat.Rss20) {
                        feedItem.Content = item.Summary.Text;
                        feedItem.Link = item.Links[0].Uri;
                    }
                    feedItem.Feed = loadFeed;
                    feedItemList.Add(feedItem);
                }
                // 保存到DB
                FeedItemDatabase.getInstance().saveFeedItems(loadFeed, feedItemList);
                // 读取DB
                FeedItemDatabase.getInstance().loadFeedItems(loadFeed);
                await FeedItemDatabase.getInstance().saveCache();
            } catch (Exception) {
                return;
            }
        }