Ejemplo n.º 1
0
        /// <summary>
        /// Parses the xml document in order to retrieve the RSS items.
        /// </summary>
        private List <Rss.Items> ParseRssItems(XmlDocument xmlDoc)
        {
            var rssItems = new List <Rss.Items>();

            rssItems.Clear();
            XmlNodeList nodes = xmlDoc.SelectNodes("rss/channel/item");

            if (nodes != null)
            {
                foreach (XmlNode node in nodes)
                {
                    var item = new Rss.Items();
                    ParseDocElements(node, "title", ref item.Title);
                    ParseDocElements(node, "description", ref item.Description);
                    ParseDocElements(node, "link", ref item.Link);

                    string date = null;
                    ParseDocElements(node, "pubDate", ref date);
                    DateTime.TryParse(date, out item.Date);

                    rssItems.Add(item);
                }
            }
            return(rssItems);
        }
Ejemplo n.º 2
0
        private bool AcceptedByFilter(Rss.Items rssItem)
        {
            var filterDict = _currentUser.FilterDict;

            if (filterDict.ContainsKey("exclude"))
            {
                var excludes = filterDict["exclude"].Split('|');
                foreach (var exclude in excludes)
                {
                    var  excludeElems = exclude.Split('&');
                    bool isSet        = excludeElems.All(elem => rssItem.Description.Contains(elem));
                    if (isSet)
                    {
                        return(false);
                    }
                    isSet = excludeElems.All(elem => rssItem.Title.Contains(elem));
                    if (isSet)
                    {
                        return(false);
                    }
                }
            }
            if (filterDict.ContainsKey("include"))
            {
                var includes = filterDict["include"].Split('|');
                foreach (var include in includes)
                {
                    var  includeElems = include.Split('&');
                    bool isSet        = includeElems.All(elem => rssItem.Description.Contains(elem));
                    if (isSet)
                    {
                        return(true);
                    }
                    isSet = includeElems.All(elem => rssItem.Title.Contains(elem));
                    if (isSet)
                    {
                        return(true);
                    }
                }
                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
 private void GetFilteredFeed()
 {
     while (!_isFinished || _unfilteredRssItems.Count != 0)
     {
         Rss.Items rssItem = null;
         lock (readerLock)
         {
             if (_unfilteredRssItems.Count != 0)
             {
                 rssItem = _unfilteredRssItems[0];
                 _unfilteredRssItems.RemoveAt(0);
             }
         }
         if (rssItem != null && AcceptedByFilter(rssItem))
         {
             lock (filterLock)
             {
                 _rssItems.Add(rssItem);
             }
         }
     }
 }