Пример #1
0
            private IEnumerable <MediaFeedItem> GetMediaFeedItems()
            {
                while (m_reader != null && m_reader.ReadToFollowing("item"))
                {
                    var item = new MediaFeedItem();

                    if (m_reader.ReadToFollowing("title"))
                    {
                        item.Title = m_reader.ReadElementContentAsString();
                    }

                    if (m_reader.ReadToFollowing("description"))
                    {
                        item.Description = m_reader.ReadElementContentAsString();
                    }

                    if (m_reader.ReadToFollowing("media:content"))
                    {
                        m_reader.MoveToFirstAttribute();
                        item.ContentType = m_reader.Value;

                        m_reader.MoveToNextAttribute();
                        item.ContentURL = m_reader.Value;

                        m_reader.MoveToContent();
                        if (m_reader.ReadToDescendant("media:keywords"))
                        {
                            item.Keywords = m_reader.ReadElementContentAsString();
                        }

                        if (m_reader.ReadToNextSibling("media:thumbnail"))
                        {
                            item.ThumbnailURL = m_reader.ReadElementContentAsString();
                        }
                    }

                    yield return(item);
                }

                Close();
            }
Пример #2
0
            //Ideally this should be done outside of the main thread, or in some async way that won't hold up the game thread
            public void Load(string url, string user, string password)
            {
                Items = new List <MediaFeedItem>();

                XmlReaderSettings settings = new XmlReaderSettings {
                    NameTable = new NameTable()
                };
                XmlNamespaceManager xmlns = new XmlNamespaceManager(settings.NameTable);

                xmlns.AddNamespace("media", @"http://search.yahoo.com/mrss/");
                XmlParserContext context = new XmlParserContext(null, xmlns, string.Empty, XmlSpace.Default);

                if (!string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(password))
                {
                    XmlUrlResolver resolver = new XmlUrlResolver();
                    resolver.Credentials = new System.Net.NetworkCredential(user, password);
                    settings.XmlResolver = resolver;
                }

                using (XmlReader reader = XmlReader.Create(url, settings, context))
                {
                    for (int i = 0; i < 9; i++)
                    {
                        if (reader.ReadToFollowing("item"))
                        {
                            MediaFeedItem item = new MediaFeedItem();
                            Items.Add(item);

                            if (reader.ReadToFollowing("title"))
                            {
                                item.Title = reader.ReadElementContentAsString();
                            }

                            if (reader.ReadToFollowing("description"))
                            {
                                item.Description = reader.ReadElementContentAsString();
                            }

                            if (reader.ReadToFollowing("media:content"))
                            {
                                reader.MoveToFirstAttribute();
                                item.ContentType = reader.Value;

                                reader.MoveToNextAttribute();
                                item.ContentURL = reader.Value;

                                reader.MoveToContent();
                                if (reader.ReadToDescendant("media:keywords"))
                                {
                                    item.Keywords = reader.ReadElementContentAsString();
                                }

                                if (reader.ReadToNextSibling("media:thumbnail"))
                                {
                                    item.ThumbnailURL = reader.ReadElementContentAsString();
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }

                    reader.Close();
                }
            }