Ejemplo n.º 1
0
        public void Poll(string url)
        {
            RssPoller   poller  = new RssPoller();
            RssFeedData channel = new RssFeedData();

            Action <object> action = (object obj) =>
            {
                RssParser parser = new RssParser();

                string response = poller.GetReponse(url);
                channel = parser.ParseRSS(response);
            };

            Task t1 = Task.Factory.StartNew(action, "alpha");

            try
            {
                t1.Wait();
            }
            catch (System.Exception ex)
            {
                throw new Exception(ex.Message);
            }

            this.OnRaiseCustomEvent(new PollFinishedEventArgs(channel));
        }
Ejemplo n.º 2
0
        public RssFeedData ParseRSS(string feed)
        {
            this.reader = XmlReader.Create(new StringReader(feed));

            if (!this.ValidateRssFeed())
            {
                throw new Exception("Invalid RSS feed");
            }

            this.reader.ReadToFollowing("channel");

            RssFeedData channel = new RssFeedData();

            channel.Items = new List <RssItem>();

            bool header = true;

            while (header)
            {
                this.reader.Read();
                if (this.reader.IsStartElement())
                {
                    switch (this.reader.Name)
                    {
                    case "title":
                        channel.Title = this.reader.ReadElementContentAsString();
                        break;

                    case "link":
                        channel.Link = this.reader.ReadElementContentAsString();
                        break;

                    case "description":
                        channel.Description = this.reader.ReadElementContentAsString();
                        break;

                    case "item":
                        header = false;
                        break;
                    }
                }
            }

            RssItem item = new RssItem();

            while (this.reader.Read())
            {
                switch (this.reader.Name)
                {
                case "title":
                    if (this.reader.IsStartElement())
                    {
                        item.Title = this.reader.ReadElementContentAsString();
                    }

                    break;

                case "link":
                    if (this.reader.IsStartElement())
                    {
                        item.Link = this.reader.ReadElementContentAsString();
                    }

                    break;

                case "description":
                    if (this.reader.IsStartElement())
                    {
                        item.Description = this.reader.ReadElementContentAsString();
                    }

                    break;

                case "item":
                    if (!this.reader.IsStartElement())
                    {
                        channel.Items.Add(item);
                    }

                    break;
                }
            }

            return(channel);
        }
Ejemplo n.º 3
0
 // the event to send out
 public PollFinishedEventArgs(RssFeedData channelToPublish)
 {
     // constructor for the event
     this.channel = channelToPublish;
 }