/// <summary> /// Processes the news feed. /// </summary> /// <param name="subscriptionUrl">The RSS URL.</param> public static ArrayList ProcessNewsFeed(string subscriptionUrl) { if (subscriptionUrl == null) throw new ArgumentNullException("subscriptionUrl"); ArrayList returnList = new ArrayList(); try { WebRequest myRequest = WebRequest.Create(subscriptionUrl); WebResponse myResponse = myRequest.GetResponse(); Stream rssStream = myResponse.GetResponseStream(); XmlDocument rssDoc = new XmlDocument(); if (rssStream != null) rssDoc.Load(rssStream); XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item"); if (rssItems != null) foreach (XmlNode currentRssItem in rssItems) { var tempNewsItem = new NewsItem(); //Gets the title of the current RSS node. XmlNode rssDetail = currentRssItem.SelectSingleNode("title"); tempNewsItem.Title = rssDetail != null ? rssDetail.InnerText : ""; //Gets the links of the current RSS node. rssDetail = currentRssItem.SelectSingleNode("link"); tempNewsItem.Link = rssDetail != null ? rssDetail.InnerText : ""; //Gets the description of the current RSS node. rssDetail = currentRssItem.SelectSingleNode("description"); tempNewsItem.Description = rssDetail != null ? rssDetail.InnerText : ""; //Add the temporary news item to the return ArrayList. returnList.Add(tempNewsItem); } } catch (Exception ex) { ErrorMessageBox.Show(ex.Message, ex.ToString()); Logger.ErrorLogger("error.txt", ex.ToString()); } return returnList; }
public static List<NewsItem> GetNewsItemList() { List<NewsItem> returnData = new List<NewsItem>(); try { using (SQLiteConnection sqLiteConnection = new SQLiteConnection(ConnectionString)) { sqLiteConnection.Open(); SQLiteCommand sqLiteCommand = new SQLiteCommand(sqLiteConnection) { CommandText = "SELECT * " + "FROM NEWS_STORAGE " }; SQLiteDataReader reader = sqLiteCommand.ExecuteReader(); DataTable dataTable = new DataTable(); dataTable.Load(reader); for (int i = 0; i < dataTable.Rows.Count; i++) { NewsItem newsItem = new NewsItem { Title = dataTable.Rows[i][1] as string, Link = dataTable.Rows[i][2] as string, Description = dataTable.Rows[i][3] as string, AquisitionDate = dataTable.Rows[i][5] as DateTime? }; returnData.Add(newsItem); } reader.Close(); sqLiteConnection.Close(); } } catch (Exception ex) { ErrorMessageBox.Show(ex.Message, ex.ToString()); Logger.ErrorLogger("error.txt", ex.ToString()); } return returnData; }