예제 #1
0
        internal XmlDocument LoadFeedXml(Uri url)
        {
            XmlDocument     feedXml   = new XmlDocument();
            CachedWebClient cachedWeb = CachedWebClient.GetInstance();

            string feedString = cachedWeb.DownloadString(url, PodcastProvider.CacheHTTPHours);

            // The LoadXml method of XmlDocument doesn't work correctly all of the time,
            // so convert the string to a UTF-8 byte array
            byte[] encodedString = Encoding.UTF8.GetBytes(feedString);

            // And then load this into the XmlDocument via a stream
            using (MemoryStream feedStream = new MemoryStream(encodedString))
            {
                feedStream.Flush();
                feedStream.Position = 0;

                feedXml.Load(feedStream);
            }

            return(feedXml);
        }
예제 #2
0
        private Bitmap RSSNodeImage(XmlNode node, XmlNamespaceManager namespaceMgr)
        {
            CachedWebClient cachedWeb = CachedWebClient.GetInstance();

            try
            {
                XmlNode imageNode = node.SelectSingleNode("itunes:image", namespaceMgr);

                if (imageNode != null)
                {
                    Uri    imageUrl  = new Uri(imageNode.Attributes["href"].Value);
                    byte[] imageData = cachedWeb.DownloadData(imageUrl, CacheHTTPHours);

                    using (MemoryStream imageStream = new MemoryStream(imageData))
                    {
                        using (Bitmap streamBitmap = new Bitmap(imageStream))
                        {
                            return(new Bitmap(streamBitmap));
                        }
                    }
                }
            }
            catch
            {
                // Ignore errors and try the next option instead
            }

            try
            {
                XmlNode imageUrlNode = node.SelectSingleNode("image/url");

                if (imageUrlNode != null)
                {
                    Uri    imageUrl  = new Uri(imageUrlNode.InnerText);
                    byte[] imageData = cachedWeb.DownloadData(imageUrl, CacheHTTPHours);

                    using (MemoryStream imageStream = new MemoryStream(imageData))
                    {
                        using (Bitmap streamBitmap = new Bitmap(imageStream))
                        {
                            return(new Bitmap(streamBitmap));
                        }
                    }
                }
            }
            catch
            {
                // Ignore errors and try the next option instead
            }

            try
            {
                XmlNode imageNode = node.SelectSingleNode("media:thumbnail", namespaceMgr);

                if (imageNode != null)
                {
                    Uri    imageUrl  = new Uri(imageNode.Attributes["url"].Value);
                    byte[] imageData = cachedWeb.DownloadData(imageUrl, CacheHTTPHours);

                    using (MemoryStream imageStream = new MemoryStream(imageData))
                    {
                        using (Bitmap streamBitmap = new Bitmap(imageStream))
                        {
                            return(new Bitmap(streamBitmap));
                        }
                    }
                }
            }
            catch
            {
                // Ignore errors
            }

            return(null);
        }