Beispiel #1
0
        void UpdatePodcast(Podcast podcast)
        {
            var r = new Random();

            Thread.Sleep(r.Next(3000));
            var doc = new XmlDocument();

            doc.Load(podcast.SubscriptionUrl);

            XmlElement  channel = doc["rss"]["channel"];
            XmlNodeList items   = channel.GetElementsByTagName("item");

            podcast.Title       = channel["title"].InnerText;
            podcast.Link        = channel["link"].InnerText;
            podcast.Description = channel["description"].InnerText;
            if (podcast.Episodes == null)
            {
                podcast.Episodes = new List <Episode>();
            }
            foreach (XmlNode item in items)
            {
                var guid    = item["guid"].InnerText;
                var episode = podcast.Episodes.FirstOrDefault(e => e.Guid == guid);
                if (episode == null)
                {
                    episode = new Episode()
                    {
                        Guid = guid, IsNew = true
                    };
                    episode.Title   = item["title"].InnerText;
                    episode.PubDate = item["pubDate"].InnerText;
                    var xmlElement = item["description"];
                    if (xmlElement != null)
                    {
                        episode.Description = xmlElement.InnerText;
                    }
                    var element = item["link"];
                    if (element != null)
                    {
                        episode.Link = element.InnerText;
                    }
                    var enclosureElement = item["enclosure"];
                    if (enclosureElement != null)
                    {
                        episode.AudioFile = enclosureElement.Attributes["url"].InnerText;
                    }
                    podcast.Episodes.Add(episode);
                }
            }
        }
Beispiel #2
0
        private void OnButtonAddSubscriptionClick(object sender, EventArgs e)
        {
            var form = new NewPodcastForm();

            if (form.ShowDialog() == DialogResult.OK)
            {
                var pod = new Podcast()
                {
                    SubscriptionUrl = form.PodcastUrl
                };
                UpdatePodcast(pod);
                AddPodcastToTreeView(pod);
            }
        }
        private void OnButtonAddSubscriptionClick(object sender, EventArgs e)
        {
            var form = new NewPodcastForm();

            if (form.ShowDialog() == DialogResult.OK)
            {
                var pod = new Podcast()
                {
                    SubscriptionUrl = form.PodcastUrl
                };
                UpdatePodcast(pod);
                var index = listBoxPodcasts.Items.Add(pod);
                listBoxPodcasts.SelectedIndex = index;
            }
        }
Beispiel #4
0
        private void AddPodcastToTreeView(Podcast pod)
        {
            var podNode = new TreeNode(pod.Title)
            {
                Tag = pod
            };

            subscriptionView.treeViewPodcasts.Nodes.Add(podNode);
            foreach (var episode in pod.Episodes)
            {
                podNode.Nodes.Add(new TreeNode(episode.Title)
                {
                    Tag = episode
                });
            }
        }
Beispiel #5
0
        private void AddPodcastToTreeView(Podcast podcast)
        {
            var podNode = new TreeNode(podcast.Title)
            {
                Tag = podcast, Name = podcast.Id.ToString()
            };

            foreach (var episode in podcast.Episodes)
            {
                podNode.Nodes.Add(new TreeNode(episode.Title)
                {
                    Tag = episode, Name = episode.Guid
                });
            }

            subscriptionView.AddNode(podNode);
        }
Beispiel #6
0
 public void RemoveSubscription(Podcast podcast)
 {
     podcasts.Remove(podcast);
 }
Beispiel #7
0
 public void AddSubscription(Podcast podcast)
 {
     podcasts.Add(podcast);
 }
Beispiel #8
0
 public void SetPodcast(Podcast selectedPodcast)
 {
     labelTitle.Text        = selectedPodcast.Title;
     labelEpisodeCount.Text = String.Format("{0} episodes", selectedPodcast.Episodes.Count);
 }
Beispiel #9
0
 internal void SetPodcast(Podcast selectedPodcast)
 {
     labelTitle.Text        = selectedPodcast.Title;
     labelEpisodeCount.Text = String.Format($"{selectedPodcast.Episodes.Count} episodes");
 }
        bool UpdatePodcast(Podcast podcast)
        {
            var r = new Random();

            Thread.Sleep(r.Next(3000));
            var doc = new XmlDocument();

            doc.Load(podcast.SubscriptionUrl);

            XmlElement channel;

            if (doc.HasChildNodes && doc.ChildNodes.Cast <XmlNode>().Where(x => x.Name == "rss").Any())
            {
                channel = doc["rss"]["channel"];
            }
            else
            {
                MessageBox.Show("Sorry, the URL is not a podcast feed");
                return(false);
            }
            XmlNodeList items = channel.GetElementsByTagName("item");

            podcast.Title       = channel["title"].InnerText;
            podcast.Link        = channel["link"].InnerText;
            podcast.Description = channel["description"].InnerText;
            if (podcast.Episodes == null)
            {
                podcast.Episodes = new List <Episode>();
            }
            foreach (XmlNode item in items)
            {
                var guid    = item["guid"].InnerText;
                var episode = podcast.Episodes.FirstOrDefault(e => e.Guid == guid);
                if (episode == null)
                {
                    episode = new Episode()
                    {
                        Guid = guid, IsNew = true
                    };
                    episode.Title   = item["title"].InnerText;
                    episode.PubDate = item["pubDate"].InnerText;
                    var xmlElement = item["description"];
                    if (xmlElement != null)
                    {
                        episode.Description = xmlElement.InnerText;
                    }
                    var element = item["link"];
                    if (element != null)
                    {
                        episode.Link = element.InnerText;
                    }
                    var enclosureElement = item["enclosure"];
                    if (enclosureElement != null)
                    {
                        episode.AudioFile = enclosureElement.Attributes["url"].InnerText;
                    }
                    podcast.Episodes.Add(episode);
                }
            }
            return(true);
        }