Ejemplo n.º 1
0
        /// <summary>
        /// Helper, automates the loading of sources items from DB.
        /// </summary>
        /// <param name="source"></param>
        void LoadSourceItemsFromPersistence(EventSource source)
        {
            List <EventBase> items =
                _persistenceHelper.SelectDynamicType <EventBase>(new MatchExpression("SourceId", source.Id), null);

            Dictionary <string, List <EventBase> > itemsByChannel = new Dictionary <string, List <EventBase> >();

            foreach (RssNewsEvent item in items)
            {
                item.Channel = source.GetChannelByName(item.ChannelId, true);
                if (itemsByChannel.ContainsKey(item.ChannelId) == false)
                {
                    itemsByChannel.Add(item.ChannelId, new List <EventBase>());
                }

                itemsByChannel[item.ChannelId].Add(item);
            }

            foreach (string name in itemsByChannel.Keys)
            {
                // Handle the relation to persistence.
                EventSourceChannel channel = source.GetChannelByName(name, false);
                channel.AddItems(itemsByChannel[name]);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Helper. Not thread safe.
        /// </summary>
        void AddChannel(string name, string uri)
        {
            EventSourceChannel channel = new EventSourceChannel(name, true);

            channel.Initialize(this);
            channel.Address = uri;
            base.AddChannel(channel);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Intercept call to gaether locally items for filtering.
        /// </summary>
        protected override void channel_ItemsAddedEvent(EventSource source, EventSourceChannel channel, IEnumerable <EventBase> items)
        {
            foreach (RssNewsEvent item in items)
            {
                if ((DateTime.Now - item.DateTime) < TimeSpan.FromDays(7) &&
                    _latestNewsItemsTitles.ContainsKey(item.Title) == false)
                {// Gather items from the last 3 days.
                    lock (this)
                    {
                        _latestNewsItemsTitles.Add(item.Title, item);
                    }
                }
            }

            base.channel_ItemsAddedEvent(source, channel, items);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Result is new items found on page.
        /// Page corresponds to a channel.
        /// </summary>
        /// <param name="uri"></param>
        List <EventBase> ProcessPage(EventSourceChannel channel)
        {
            List <EventBase> result = new List <EventBase>();

            HtmlDocument document = GenerateDocument(channel.Address);

            if (document == null)
            {
                return(result);
            }

            foreach (HtmlNode node in document.DocumentNode.SelectNodes("//a[@class]"))
            {
                if (node.ParentNode.Name == "p" &&
                    node.ParentNode.Attributes["class"] != null &&
                    node.ParentNode.Attributes["class"].Value == "summ")
                {
                    string itemTitle = node.ChildNodes[0].InnerText;

                    lock (this)
                    {
                        if (_latestNewsItemsTitles.ContainsKey(itemTitle))
                        {// News already listed.
                            continue;
                        }

                        RssNewsEvent item = CreateNewsItem(node, true);
                        if (item != null)
                        {
                            _latestNewsItemsTitles.Add(itemTitle, item);
                            item.Initialize(channel);
                            result.Add(item);
                        }
                    }
                }
            }

            return(result);
        }