Esempio n. 1
0
        public RSSItem PopulateFeed(SyndicationItem item)
        {
            OriginalRssItems.Add(item);

            RSSItem rssItem = new RSSItem();

            rssItem.Title = item.Title.Text;
            if (item.Summary != null)
            {
                rssItem.Description = item.Summary.Text;
            }
            if (item.LastUpdatedTime != null && item.PublishDate != null)
            {
                rssItem.PubDate = (item.LastUpdatedTime.DateTime > item.PublishDate.DateTime) ? item.LastUpdatedTime.DateTime : item.PublishDate.DateTime;
            }
            else if (item.LastUpdatedTime != null)
            {
                rssItem.PubDate = item.LastUpdatedTime.DateTime;
            }
            else if (item.PublishDate != null)
            {
                rssItem.PubDate = item.PublishDate.DateTime;
            }

            Items.Add(rssItem);

            return(rssItem);
        }
Esempio n. 2
0
        public void LoadRSS(string heading, string url)
        {
            if (!string.IsNullOrEmpty(url))
            {
                try
                {
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

                    WebClient client = new WebClient();


                    Uri    uri = new Uri(url);
                    string xml = "";

                    using (StreamReader reader = new StreamReader(client.OpenRead(uri), System.Text.Encoding.GetEncoding(1252)))
                    {
                        xml = reader.ReadToEnd();
                    }

                    Items.Clear();
                    OriginalRssItems.Clear();

                    ParseRssXml(xml, false);
                    //ParseRssXml(xml1, false);
                    SetRssToTickerControl();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Esempio n. 3
0
        public void ParseRssXml(string xml, bool IsTop = false)
        {
            try
            {
                SyndicationFeed feed = new SyndicationFeed();

                byte[]       byteArray = Encoding.GetEncoding(1252).GetBytes(xml);
                MemoryStream stream    = new MemoryStream(byteArray);

                using (stream)
                {
                    XmlTextReader xmlReader = new XmlTextReader(stream);
                    feed = SyndicationFeed.Load(xmlReader);
                }


                Items.Clear();
                OriginalRssItems.Clear();

                if (!IsTop)
                {
                    foreach (SyndicationItem item in feed.Items)
                    {
                        PopulateFeed(item);

                        if (Items.Count == m_RSSMaxItems)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    PopulateFeed(feed.Items.First());
                }

                Source = new RSSSource();
                if (feed.Title != null)
                {
                    Source.Title = feed.Title.Text;
                }
                if (feed.Description != null)
                {
                    Source.Description = feed.Description.Text;
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }