Example #1
0
 public static bool ContainsItem(List<RssFeedItem> list, RssFeedItem item)
 {
     foreach (RssFeedItem Item in list)
     {
         if (Item.Link == item.Link && Item.Title == item.Title && item.Description == Item.Description && Item.PublishDate == item.PublishDate)
         {
             return true;
         }
     }
     return false;
 }
Example #2
0
 public static bool ContainsItem(List <RssFeedItem> list, RssFeedItem item)
 {
     foreach (RssFeedItem Item in list)
     {
         if (Item.Link == item.Link && Item.Title == item.Title && item.Description == Item.Description && Item.PublishDate == item.PublishDate)
         {
             return(true);
         }
     }
     return(false);
 }
Example #3
0
        /// <summary>
        /// Reads the relevant Rss feed and returns a list of RssFeedItems
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static List<RssFeedItem> ReadFeed(string url, Feed.Item item, string channel)
        {
            string temp = "No data were sent by server";
            try
            {
                //create a new list of the rss feed items to return
                List<RssFeedItem> rssFeedItems = new List<RssFeedItem>();

                //create a http request which will be used to retrieve the rss feed
                ServicePointManager.ServerCertificateValidationCallback = Validator;
                HttpWebRequest rssFeed = (HttpWebRequest)WebRequest.Create(url);

                XmlDocument rss = new XmlDocument();
                StreamReader xx = new StreamReader(rssFeed.GetResponse().GetResponseStream());
                temp = xx.ReadToEnd();
                rss.LoadXml(temp);

                if (url.StartsWith("http://bugzilla.wikimedia") || url.StartsWith("https://bugzilla.wikimedia"))
                {
                    if (rss.ChildNodes[1].Name.ToLower() == "feed")
                    {
                        foreach (XmlNode entry in rss.ChildNodes[1].ChildNodes)
                        {
                            if (entry.Name == "entry")
                            {
                                RssFeedItem curr = new RssFeedItem();
                                foreach (XmlNode data in entry.ChildNodes)
                                {
                                    switch (data.Name.ToLower())
                                    {
                                        case "title":
                                            curr.Title = data.InnerText;
                                            break;
                                        case "link":
                                            foreach (XmlAttribute attribute in data.Attributes)
                                            {
                                                if (attribute.Name == "href")
                                                {
                                                    curr.Link = attribute.Value;
                                                }
                                            }
                                            break;
                                        case "author":
                                            if (data.ChildNodes.Count > 0)
                                            {
                                                curr.Author = data.ChildNodes[0].InnerText;
                                            }
                                            break;
                                        case "summary":
                                            string html = System.Web.HttpUtility.HtmlDecode(data.InnerText);
                                            if (html.Contains("<table>"))
                                            {
                                                XmlDocument summary = new XmlDocument();
                                                summary.LoadXml(html);
                                                foreach (XmlNode tr in summary.ChildNodes[0].ChildNodes)
                                                {
                                                    bool type = true;
                                                    string st = "";
                                                    foreach (XmlNode td in tr.ChildNodes)
                                                    {
                                                        if (type)
                                                        {
                                                            st = td.InnerText;
                                                        }
                                                        else
                                                        {
                                                            switch (st.Replace(" ", ""))
                                                            {
                                                                case "Product":
                                                                    curr.bugzilla_product = td.InnerText;
                                                                    break;
                                                                case "Status":
                                                                    curr.bugzilla_status = td.InnerText;
                                                                    break;
                                                                case "Component":
                                                                    curr.bugzilla_component = td.InnerText;
                                                                    break;
                                                                case "Assignee":
                                                                    curr.bugzilla_assignee = td.InnerText;
                                                                    break;
                                                                case "Reporter":
                                                                    curr.bugzilla_reporter = td.InnerText;
                                                                    break;
                                                                case "Resolution":
                                                                    curr.bugzilla_reso = td.InnerText;
                                                                    break;
                                                                case "Priority":
                                                                    curr.bugzilla_priority = td.InnerText;
                                                                    break;
                                                                case "Severity":
                                                                    curr.bugzilla_severity = td.InnerText;
                                                                    break;
                                                            }
                                                        }
                                                        type = !type;
                                                    }
                                                }
                                            }
                                            break;
                                        case "guid":
                                            curr.ItemId = data.InnerText;
                                            break;
                                        case "channelid":
                                            curr.ChannelId = data.InnerText;
                                            break;
                                        case "date":
                                            curr.PublishDate = data.Value;
                                            break;
                                    }
                                }
                                rssFeedItems.Add(curr);
                            }
                        }

                        return rssFeedItems;
                    }
                }

                if (rss.ChildNodes[1].Name.ToLower() == "feed")
                {
                    foreach (XmlNode entry in rss.ChildNodes[1].ChildNodes)
                    {
                        if (entry.Name == "entry")
                        {
                            RssFeedItem curr = new RssFeedItem();
                            foreach (XmlNode data in entry.ChildNodes)
                            {
                                switch (data.Name.ToLower())
                                {
                                    case "title":
                                        curr.Title = data.InnerText;
                                        break;
                                    case "link":
                                        foreach (XmlAttribute attribute in data.Attributes)
                                        {
                                            if (attribute.Name == "href")
                                            {
                                                curr.Link = attribute.Value;
                                            }
                                        }
                                        break;
                                    case "author":
                                        if (data.ChildNodes.Count > 0)
                                        {
                                            curr.Author = data.ChildNodes[0].InnerText;
                                        }
                                        break;
                                    case "summary":
                                        curr.Description = data.InnerText;
                                        break;
                                    case "guid":
                                        curr.ItemId = data.InnerText;
                                        break;
                                    case "channelid":
                                        curr.ChannelId = data.InnerText;
                                        break;
                                    case "date":
                                        curr.PublishDate = data.Value;
                                        break;
                                }
                            }
                            rssFeedItems.Add(curr);
                        }
                    }

                    return rssFeedItems;
                }

                foreach (XmlNode node in rss.ChildNodes)
                {
                    if (node.Name.ToLower() == "rss" || node.Name.ToLower() == "channel")
                    {
                        foreach (XmlNode entry in node.ChildNodes[0].ChildNodes)
                        {
                            if (entry.Name == "item")
                            {
                                RssFeedItem curr = new RssFeedItem();
                                foreach (XmlNode data in entry.ChildNodes)
                                {
                                    switch (data.Name.ToLower())
                                    {
                                        case "title":
                                            curr.Title = data.InnerText;
                                            break;
                                        case "link":
                                            curr.Link = data.InnerText;
                                            break;
                                        case "description":
                                            curr.Description = data.InnerText;
                                            break;
                                        case "guid":
                                            curr.ItemId = data.InnerText;
                                            break;
                                        case "channelid":
                                            curr.ChannelId = data.InnerText;
                                            break;
                                        case "date":
                                            curr.PublishDate = data.Value;
                                            break;
                                    }
                                }
                                rssFeedItems.Add(curr);
                            }
                        }

                        return rssFeedItems;
                    }
                }
                if (item.retries < 1)
                {
                    item.disabled = true;
                    Core.irc.Queue.DeliverMessage("Unable to parse the feed from " + url + " this url is probably not a valid rss, the feed will be disabled, until you re-enable it by typing @rss+ " + item.name, channel);
                    return null;
                }
                item.retries--;
                return null;
            }
            catch (ThreadAbortException fail)
            {
                throw fail;
            }
            catch (Exception fail)
            {
                RSS.m.Log("Unable to parse feed from " + url + " I will try to do that again " + item.retries.ToString() + " times", true);
                RSS.m.HandleException(fail, "Feed");
                string dump = Path.GetTempFileName();
                File.WriteAllText(dump, temp);
                RSS.m.Log("Dumped the source to " + dump);
                if (item.retries < 1)
                {
                    item.disabled = true;
                    Core.irc.Queue.DeliverMessage("Unable to parse the feed from " + url + " this url is probably not a valid rss, the feed will be disabled, until you re-enable it by typing @rss+ " + item.name, channel);
                    return null;
                }
                item.retries--;
                return null;
            }
        }
Example #4
0
        /// <summary>
        /// Reads the relevant Rss feed and returns a list of RssFeedItems
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static List <RssFeedItem> ReadFeed(string url, Feed.Item item, string channel)
        {
            string temp = "No data were sent by server";

            try
            {
                //create a new list of the rss feed items to return
                List <RssFeedItem> rssFeedItems = new List <RssFeedItem>();

                //create a http request which will be used to retrieve the rss feed
                ServicePointManager.ServerCertificateValidationCallback = Validator;
                HttpWebRequest rssFeed = (HttpWebRequest)WebRequest.Create(url);

                XmlDocument  rss = new XmlDocument();
                StreamReader xx  = new StreamReader(rssFeed.GetResponse().GetResponseStream());
                temp = xx.ReadToEnd();
                rss.LoadXml(temp);

                if (url.StartsWith("http://bugzilla.wikimedia") || url.StartsWith("https://bugzilla.wikimedia"))
                {
                    if (rss.ChildNodes[1].Name.ToLower() == "feed")
                    {
                        foreach (XmlNode entry in rss.ChildNodes[1].ChildNodes)
                        {
                            if (entry.Name == "entry")
                            {
                                RssFeedItem curr = new RssFeedItem();
                                foreach (XmlNode data in entry.ChildNodes)
                                {
                                    switch (data.Name.ToLower())
                                    {
                                    case "title":
                                        curr.Title = data.InnerText;
                                        break;

                                    case "link":
                                        foreach (XmlAttribute attribute in data.Attributes)
                                        {
                                            if (attribute.Name == "href")
                                            {
                                                curr.Link = attribute.Value;
                                            }
                                        }
                                        break;

                                    case "author":
                                        if (data.ChildNodes.Count > 0)
                                        {
                                            curr.Author = data.ChildNodes[0].InnerText;
                                        }
                                        break;

                                    case "summary":
                                        string html = System.Web.HttpUtility.HtmlDecode(data.InnerText);
                                        if (html.Contains("<table>"))
                                        {
                                            XmlDocument summary = new XmlDocument();
                                            summary.LoadXml(html);
                                            foreach (XmlNode tr in summary.ChildNodes[0].ChildNodes)
                                            {
                                                bool   type = true;
                                                string st   = "";
                                                foreach (XmlNode td in tr.ChildNodes)
                                                {
                                                    if (type)
                                                    {
                                                        st = td.InnerText;
                                                    }
                                                    else
                                                    {
                                                        switch (st.Replace(" ", ""))
                                                        {
                                                        case "Product":
                                                            curr.bugzilla_product = td.InnerText;
                                                            break;

                                                        case "Status":
                                                            curr.bugzilla_status = td.InnerText;
                                                            break;

                                                        case "Component":
                                                            curr.bugzilla_component = td.InnerText;
                                                            break;

                                                        case "Assignee":
                                                            curr.bugzilla_assignee = td.InnerText;
                                                            break;

                                                        case "Reporter":
                                                            curr.bugzilla_reporter = td.InnerText;
                                                            break;

                                                        case "Resolution":
                                                            curr.bugzilla_reso = td.InnerText;
                                                            break;

                                                        case "Priority":
                                                            curr.bugzilla_priority = td.InnerText;
                                                            break;

                                                        case "Severity":
                                                            curr.bugzilla_severity = td.InnerText;
                                                            break;
                                                        }
                                                    }
                                                    type = !type;
                                                }
                                            }
                                        }
                                        break;

                                    case "guid":
                                        curr.ItemId = data.InnerText;
                                        break;

                                    case "channelid":
                                        curr.ChannelId = data.InnerText;
                                        break;

                                    case "date":
                                        curr.PublishDate = data.Value;
                                        break;
                                    }
                                }
                                rssFeedItems.Add(curr);
                            }
                        }

                        return(rssFeedItems);
                    }
                }

                if (rss.ChildNodes[1].Name.ToLower() == "feed")
                {
                    foreach (XmlNode entry in rss.ChildNodes[1].ChildNodes)
                    {
                        if (entry.Name == "entry")
                        {
                            RssFeedItem curr = new RssFeedItem();
                            foreach (XmlNode data in entry.ChildNodes)
                            {
                                switch (data.Name.ToLower())
                                {
                                case "title":
                                    curr.Title = data.InnerText;
                                    break;

                                case "link":
                                    foreach (XmlAttribute attribute in data.Attributes)
                                    {
                                        if (attribute.Name == "href")
                                        {
                                            curr.Link = attribute.Value;
                                        }
                                    }
                                    break;

                                case "author":
                                    if (data.ChildNodes.Count > 0)
                                    {
                                        curr.Author = data.ChildNodes[0].InnerText;
                                    }
                                    break;

                                case "summary":
                                    curr.Description = data.InnerText;
                                    break;

                                case "guid":
                                    curr.ItemId = data.InnerText;
                                    break;

                                case "channelid":
                                    curr.ChannelId = data.InnerText;
                                    break;

                                case "date":
                                    curr.PublishDate = data.Value;
                                    break;
                                }
                            }
                            rssFeedItems.Add(curr);
                        }
                    }

                    return(rssFeedItems);
                }

                foreach (XmlNode node in rss.ChildNodes)
                {
                    if (node.Name.ToLower() == "rss" || node.Name.ToLower() == "channel")
                    {
                        foreach (XmlNode entry in node.ChildNodes[0].ChildNodes)
                        {
                            if (entry.Name == "item")
                            {
                                RssFeedItem curr = new RssFeedItem();
                                foreach (XmlNode data in entry.ChildNodes)
                                {
                                    switch (data.Name.ToLower())
                                    {
                                    case "title":
                                        curr.Title = data.InnerText;
                                        break;

                                    case "link":
                                        curr.Link = data.InnerText;
                                        break;

                                    case "description":
                                        curr.Description = data.InnerText;
                                        break;

                                    case "guid":
                                        curr.ItemId = data.InnerText;
                                        break;

                                    case "channelid":
                                        curr.ChannelId = data.InnerText;
                                        break;

                                    case "date":
                                        curr.PublishDate = data.Value;
                                        break;
                                    }
                                }
                                rssFeedItems.Add(curr);
                            }
                        }

                        return(rssFeedItems);
                    }
                }
                if (item.retries < 1)
                {
                    item.disabled = true;
                    core.irc._SlowQueue.DeliverMessage("Unable to parse the feed from " + url + " this url is probably not a valid rss, the feed will be disabled, until you re-enable it by typing @rss+ " + item.name, channel);
                    return(null);
                }
                item.retries--;
                return(null);
            }
            catch (ThreadAbortException fail)
            {
                throw fail;
            }
            catch (Exception fail)
            {
                RSS.m.Log("Unable to parse feed from " + url + " I will try to do that again " + item.retries.ToString() + " times", true);
                RSS.m.handleException(fail, "Feed");
                string dump = Path.GetTempFileName();
                File.WriteAllText(dump, temp);
                RSS.m.Log("Dumped the source to " + dump);
                if (item.retries < 1)
                {
                    item.disabled = true;
                    core.irc._SlowQueue.DeliverMessage("Unable to parse the feed from " + url + " this url is probably not a valid rss, the feed will be disabled, until you re-enable it by typing @rss+ " + item.name, channel);
                    return(null);
                }
                item.retries--;
                return(null);
            }
        }