/// <summary> /// Parse the results of the Bing search /// </summary> /// <param name="reader">The xml reader containing the search results</param> public Collection<Article> ParseItems(XmlReader reader, Feed ownerFeed) { Collection<Article> results = new Collection<Article>(); reader.ReadToFollowing("item"); do { if (reader.ReadToFollowing("title")) { string name = reader.ReadElementContentAsString(); if (reader.ReadToFollowing("link")) { string uri = reader.ReadElementContentAsString(); // Assign feed information to Article object. Article newResult = new Article { ArticleTitle = name, ArticleBaseURI = uri }; // Safely add the search result to the collection. lock (_lockObject) { results.Add(newResult); } } } } while (reader.ReadToFollowing("item")); return results; }
//Delete an article. public void DeleteArticle(Article deleteArticle) { db.Article.DeleteOnSubmit(deleteArticle); SaveChangesToDB(); }
/// <summary> /// Obtains the latest featured articles and sets them up to be displayed. /// </summary> public void GetFeatured() { // Gather the latest featured articles. // If there are no new ones, then old ones will be used. FeaturedAlgorithm.UpdateFeatured(); // Set the articles to be displayed. // Gather each article from the database to ensure that it actually exists. if (Settings.FeaturedArticles != null) { HubTileArticle1 = App.DataBaseUtility.QueryArticle(Convert.ToInt32(Settings.FeaturedArticles[0].ArticleID)); HubTileArticle2 = App.DataBaseUtility.QueryArticle(Convert.ToInt32(Settings.FeaturedArticles[1].ArticleID)); HubTileArticle3 = App.DataBaseUtility.QueryArticle(Convert.ToInt32(Settings.FeaturedArticles[2].ArticleID)); HubTileArticle4 = App.DataBaseUtility.QueryArticle(Convert.ToInt32(Settings.FeaturedArticles[3].ArticleID)); HubTileArticle5 = App.DataBaseUtility.QueryArticle(Convert.ToInt32(Settings.FeaturedArticles[4].ArticleID)); HubTileArticle6 = App.DataBaseUtility.QueryArticle(Convert.ToInt32(Settings.FeaturedArticles[5].ArticleID)); } }
/// <summary> /// Function to parse the item of a feed and obtain useful data. /// </summary> /// <param name="feed">The Feed the article being parsed belongs to.</param> /// <param name="synFeed">Syndication Feed to be parsed</param> /// <param name="item">SyndicationItem that will be added to the database</param> public Collection<Article> ParseItems(XmlReader reader, Feed parentFeed) { // Collection to store all parsed articles Collection<Article> parsedArticles = new Collection<Article>(); SyndicationFeed synFeed; // Create a syndicationFeed from the provided reader try { synFeed = SyndicationFeed.Load(reader); } catch { return null; } if (null != synFeed) { // First, obtain an image for the feed if it does not have one. if (!ImageGrabber.IfImageExists(parentFeed)) { ImageGrabber.GetImage(parentFeed, synFeed); latestDate = new DateTime(); } // Parse the xml file, getting each article. foreach (SyndicationItem item in synFeed.Items) { // Get the necessary details from the SyndicationItem. string title = (item.Title != null) ? item.Title.Text : String.Empty; title = HTMLParser(title); // parse the title for html leftovers string itemURI = (item.Links[0].Uri.ToString() != null) ? item.Links[0].Uri.ToString() : String.Empty; DateTimeOffset date = item.PublishDate; // Special case for the text/preview of article. StringBuilder text = new StringBuilder(); if (item.Summary != null) { text.Append(item.Summary.Text); } // If the article instead writes to the content:encoded portion of the xml. else { foreach (SyndicationElementExtension extension in item.ElementExtensions) { XElement ele = extension.GetObject<XElement>(); if (ele.Name.LocalName == "encoded" && ele.Name.Namespace.ToString().Contains("content")) { text.Append(ele.Value + "<br/>"); } } } string parsedText = HTMLParser(text.ToString()); if (parsedText.Length >= 3500) { parsedText = parsedText.Substring(0, 2499); } if (null == latestDate) { lock (_lockObject) { latestDate = new DateTime(); } } bool val; lock (_lockObject) { val = latestDate.CompareTo(date.DateTime) < 0; } if (val) { // Initialize new article, then add it to the database. Article newArticle = new Article { ArticleTitle = title, Authors = parentFeed.FeedTitle, PublishDate = date.DateTime.ToLocalTime(), Summary = parsedText, LastUpdatedTime = DateTime.Now, ArticleBaseURI = itemURI, FeedID = parentFeed.FeedID, ImageURL = parentFeed.ImageURL }; parsedArticles.Add(newArticle); } } } return parsedArticles; }
partial void DeleteArticle(Article instance);
partial void UpdateArticle(Article instance);
partial void InsertArticle(Article instance);
/// <summary> /// Parse the results of the Bing search /// </summary> /// <param name="reader">The xml reader containing the search results</param> private void ParseResults(XmlReader reader) { reader.ReadToFollowing("item"); do { if (reader.ReadToFollowing("title")) { string name = reader.ReadElementContentAsString(); if (reader.ReadToFollowing("link")) { string uri = reader.ReadElementContentAsString(); Article newResult = new Article { ArticleTitle = name, ArticleBaseURI = uri }; // Safely add the search result to the collection. lock (_lockObject) { results.Add(newResult); } } } } while (reader.ReadToFollowing("item")); }