private void listBox_SelectedValueChanged(object sender, EventArgs e) { if (listBox.SelectedItems.Count > 1) { return; } // update Listview listView.BeginUpdate(); Podcast key = (Podcast)listBox.SelectedItem; listView.Items.Clear(); foreach (Item item in Model.Instance.Podcasts[key.Url].Items) { ListViewItem listViewItem = new ListViewItem(); listViewItem.SubItems[0] = new ListViewItem.ListViewSubItem(listViewItem, item.Status.ToString()); listViewItem.SubItems.Add(item.Title); ListViewItem.ListViewSubItem subItem = new ListViewItem.ListViewSubItem(); subItem.Text = item.Date.ToShortDateString(); subItem.Tag = item.Date; listViewItem.SubItems.Add(subItem); listViewItem.SubItems.Add(item.Description); listViewItem.Tag = item; listViewItem.ToolTipText = item.Description; listView.Items.Add(listViewItem); } // Loop through and size each column header to fit the column header text. foreach (ColumnHeader ch in this.listView.Columns) { ch.Width = -2; } listView.EndUpdate(); // update Model Model.Instance.SelectedPodcast = key; }
private bool Equals(Podcast obj) { bool result = true; result &= string.Equals(Title, obj.Title) && string.Equals(Description, obj.Description) && string.Equals(Url, obj.Url); for (int i = 0; i < Items.Count; i++) { result &= Items[i].Equals(obj.Items[i]); if (!result) { break; } } return(result); }
private bool Equals(Podcast obj) { bool result = true; result &= string.Equals(Title, obj.Title) && string.Equals(Description, obj.Description) && string.Equals(Url, obj.Url); for (int i = 0; i < Items.Count; i++) { result &= Items[i].Equals(obj.Items[i]); if (!result) break; } return result; }
public void GetDirectoryOfFeedTest() { string rssUrl = @"file://" + rssFile; Podcast expected = new Podcast(); expected.Title = "CRE: Technik, Kultur, Gesellschaft"; expected.Description = "Der Interview-Podcast mit Tim Pritlove"; expected.Url = rssUrl; expected.Items = new List<Item>(); Item item1 = new Item(); item1.FileName = "cre197-ipv6.mp3"; item1.Title = "CRE197 IPv6"; item1.Url = @"http://feedproxy.google.com/~r/cre-podcast/~5/vFEBFGH8_qQ/cre197-ipv6.mp3"; item1.Status = Status.New; expected.Items.Add(item1); Item item2 = new Item(); item2.FileName = "cre166_segeln.mp3"; item2.Title = "CRE166 Segeln"; item2.Url = @"http://feedproxy.google.com/~r/cre-podcast/~5/zzCLAjsGg5Q/cre166_segeln.mp3"; item2.Status = Status.New; expected.Items.Add(item2); Podcast actual; actual = Controller.GetCatalogOfFeed(rssUrl); Assert.AreEqual(expected, actual); }
public static void RefreshFeeds() { SerializableDictionary <string, Podcast> podcasts = Model.Instance.Podcasts; foreach (var item in podcasts) { Podcast podcast = item.Value; string rssUrl = podcast.Url; // load the podcast XmlDocument doc = new XmlDocument(); try { doc.Load(rssUrl); // get meta info of feed string xpathExpr = string.Format(CultureInfo.InvariantCulture, "/rss/channel/title"); XmlNode xmlNode = doc.SelectSingleNode(xpathExpr); xpathExpr = string.Format(CultureInfo.InvariantCulture, "/rss/channel/description"); xmlNode = doc.SelectSingleNode(xpathExpr); // builds a list of item nodes XmlNodeList items = doc.SelectNodes("//item"); List <Item> files = new List <Item>(); // loop through list and check for new items for (int i = 0; i < items.Count; i++) { string title = items[i].SelectSingleNode("title").InnerText; // check if file is already contained in list of files bool newFile = true; foreach (var file in podcast.Items) { if (file.Title == title) { newFile = false; break; } } if (newFile) { Item file = new Item(); file.Title = items[i].SelectSingleNode("title").InnerText; file.Url = items[i].SelectSingleNode("enclosure").Attributes["url"].Value; DateTime date = new DateTime(); DateTime.TryParse(items[i].SelectSingleNode("pubDate").InnerText, out date); file.Date = date; //file.ItunesSummary = items[i].SelectSingleNode("itunes:summary").InnerText; file.Description = items[i].SelectSingleNode("description").InnerText; file.Status = Status.New; int indexOfSlash = file.Url.LastIndexOf("/"); file.FileName = file.Url.Substring(indexOfSlash + 1, file.Url.Length - indexOfSlash - 1); podcast.Items.Add(file); } } } catch (WebException ex) { System.Windows.Forms.MessageBox.Show(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ErrorReadingRssFeed, rssUrl, ex.Message)); } // Sort files according to date podcast.Items.Sort(CompareItemsByDate); } }
public static Podcast GetCatalogOfFeed(string rssUrl) { String xpathExpr = String.Empty; XmlNode xmlNode; Podcast result = null; // load the Podcast XmlDocument doc = new XmlDocument(); try { doc.Load(rssUrl); result = new Podcast(); // get meta info of feed xpathExpr = string.Format(CultureInfo.InvariantCulture, "/rss/channel/title"); xmlNode = doc.SelectSingleNode(xpathExpr); result.Title = xmlNode.InnerText; xpathExpr = string.Format(CultureInfo.InvariantCulture, "/rss/channel/description"); xmlNode = doc.SelectSingleNode(xpathExpr); result.Description = xmlNode.InnerText; result.Url = rssUrl; // builds a list of item nodes XmlNodeList items = doc.SelectNodes("//item"); List<Item> files = new List<Item>(); // loop through list and write out title, URL and filename for (int i = 0; i < items.Count; i++) { Item file = new Item(); file.Title = items[i].SelectSingleNode("title").InnerText; file.Url = items[i].SelectSingleNode("enclosure").Attributes["url"].Value; DateTime date = new DateTime(); DateTime.TryParse(items[i].SelectSingleNode("pubDate").InnerText, out date); file.Date = date; //file.ItunesSummary = items[i].SelectSingleNode("itunes:summary").InnerText; file.Description = items[i].SelectSingleNode("description").InnerText; file.Status = Status.New; int indexOfSlash = file.Url.LastIndexOf("/"); file.FileName = file.Url.Substring(indexOfSlash + 1, file.Url.Length - indexOfSlash - 1); files.Add(file); } result.Items = files; } catch (WebException) { System.Windows.Forms.MessageBox.Show("RSS-Feed cannot be read from server."); } return result; }