コード例 #1
0
 /// <summary>
 ///
 /// </summary>
 protected virtual void channel_ItemsUpdatedEvent(EventSource source, EventSourceChannel channel, IEnumerable <EventBase> items)
 {
     if (ItemsUpdatedEvent != null)
     {
         ItemsUpdatedEvent(source, items);
     }
 }
コード例 #2
0
        /// <summary>
        /// Actual updating of items happens here.
        /// </summary>
        void DoUpdateItems()
        {
            if (_feed == null)
            {
                return;
            }

            List <RssChannel> channels;

            lock (this)
            {
                channels = GeneralHelper.EnumerableToList <RssChannel>(_feed.Channels);
            }

            foreach (RssChannel channel in channels)
            {
                // Obtain or create channel.
                EventSourceChannel sourceChannel = base.GetChannelByName(channel.Title, true);
                sourceChannel.ItemsUpdateEnabled = false;
                sourceChannel.Address            = channel.Link.ToString();

                List <EventBase> newItems = new List <EventBase>();
                foreach (RssItem item in channel.Items)
                {
                    RssNewsEvent eventItem = new RssNewsEvent(item);
                    eventItem.Initialize(sourceChannel);
                    newItems.Add(eventItem);
                }

                // Add all by default to the "Default" channel, since RSS feeds never seem to bother with proper inner channels.
                sourceChannel.AddItems(newItems);
            }
        }
コード例 #3
0
        /// <summary>
        /// On update, update items.
        /// </summary>
        protected override void OnUpdate()
        {
            try
            {
                if (_feed == null)
                {
                    _feed = RssFeed.Read(base.Address);

                    if (_feed.Channels.Count == 1)
                    {
                        // Some feeds have those symbols in their names.
                        _name = _feed.Channels[0].Title.Replace("\r", "").Replace("\n", "").Trim();
                    }
                    else
                    {
                        _name = _feed.Url.ToString();
                    }

                    List<string> names = new List<string>();
                    foreach (RssChannel channel in _feed.Channels)
                    {
                        names.Add(channel.Title);
                    }

                    foreach (string name in names)
                    {
                        if (ChannelsNames.Contains(name) == false)
                        {
                            EventSourceChannel channel = new EventSourceChannel(name, true);
                            channel.Initialize(this);
                            base.AddChannel(channel);
                        }
                    }

                }
                else
                {
                    _feed = RssFeed.Read(_feed);
                }

                //OperationalStateEnum newState = OperationalStateEnum.Operational;
            }
            catch (WebException we)
            {// Feed not found or some other problem.
                SystemMonitor.OperationWarning("Failed to initialize feed [" + Address + ", " + we.Message + "]");
                ChangeOperationalState(OperationalStateEnum.NotOperational);
            }
            catch (Exception ex)
            {// RssFeed class launches IOExceptions too, so get safe here.
                SystemMonitor.OperationWarning("Failed to initialize feed [" + Address + ", " + ex.Message + "]");
                ChangeOperationalState(OperationalStateEnum.NotOperational);
            }

            DoUpdateItems();

            //RaisePersistenceDataUpdatedEvent();
        }
コード例 #4
0
        /// <summary>
        /// On update, update items.
        /// </summary>
        protected override void OnUpdate()
        {
            try
            {
                if (_feed == null)
                {
                    _feed = RssFeed.Read(base.Address);

                    if (_feed.Channels.Count == 1)
                    {
                        // Some feeds have those symbols in their names.
                        _name = _feed.Channels[0].Title.Replace("\r", "").Replace("\n", "").Trim();
                    }
                    else
                    {
                        _name = _feed.Url.ToString();
                    }

                    List <string> names = new List <string>();
                    foreach (RssChannel channel in _feed.Channels)
                    {
                        names.Add(channel.Title);
                    }

                    foreach (string name in names)
                    {
                        if (ChannelsNames.Contains(name) == false)
                        {
                            EventSourceChannel channel = new EventSourceChannel(name, true);
                            channel.Initialize(this);
                            base.AddChannel(channel);
                        }
                    }
                }
                else
                {
                    _feed = RssFeed.Read(_feed);
                }

                //OperationalStateEnum newState = OperationalStateEnum.Operational;
            }
            catch (WebException we)
            {// Feed not found or some other problem.
                SystemMonitor.OperationWarning("Failed to initialize feed [" + Address + ", " + we.Message + "]");
                ChangeOperationalState(OperationalStateEnum.NotOperational);
            }
            catch (Exception ex)
            {// RssFeed class launches IOExceptions too, so get safe here.
                SystemMonitor.OperationWarning("Failed to initialize feed [" + Address + ", " + ex.Message + "]");
                ChangeOperationalState(OperationalStateEnum.NotOperational);
            }

            DoUpdateItems();

            //RaisePersistenceDataUpdatedEvent();
        }
コード例 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="channel"></param>
 protected void RemoveChannel(EventSourceChannel channel)
 {
     lock (_channels)
     {
         if (_channels.Remove(channel.Name))
         {
             channel.ItemsAddedEvent -= new EventSourceChannel.ItemsUpdateDelegate(channel_ItemsAddedEvent);
         }
     }
 }
コード例 #6
0
        /// <summary>
        /// Add a new channel to this source.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="enabled"></param>
        protected void AddChannel(EventSourceChannel channel)
        {
            lock (_channels)
            {
                _channels[channel.Name] = channel;
            }

            channel.ItemsAddedEvent   += new EventSourceChannel.ItemsUpdateDelegate(channel_ItemsAddedEvent);
            channel.ItemsUpdatedEvent += new EventSourceChannel.ItemsUpdateDelegate(channel_ItemsUpdatedEvent);
        }
コード例 #7
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);
        }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public EventSourceChannel GetChannelByName(string name, bool create)
        {
            lock (_channels)
            {
                if (_channels.ContainsKey(name) == false)
                {
                    if (create)
                    {
                        EventSourceChannel channel = new EventSourceChannel(name, true);
                        channel.Initialize(this);

                        _channels.Add(name, channel);
                    }
                    else
                    {
                        return(null);
                    }
                }

                return(_channels[name]);
            }
        }
コード例 #9
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;
        }
コード例 #10
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);
 }
コード例 #11
0
 /// <summary>
 /// Initialize item to be part of this channel.
 /// </summary>
 /// <param name="source"></param>
 public void Initialize(EventSourceChannel channel)
 {
     _channel   = channel;
     _channelId = channel.Name;
 }
コード例 #12
0
 /// <summary>
 /// Initialize item to be part of this channel.
 /// </summary>
 /// <param name="source"></param>
 public void Initialize(EventSourceChannel channel)
 {
     _channel = channel;
     _channelId = channel.Name;
 }