Beispiel #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]);
            }
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        public void Initialize(Platform platform)
        {
            SystemMonitor.CheckWarning(NewsSourcesUnsafe.Count == 0, "Manager already has assigned sources.");

            _platform = platform;

            _persistenceHelper = CreatePersistenceHelper(platform.Settings);
            if (_persistenceHelper == null)
            {
                SystemMonitor.Error("Failed to initialize the persistence helper for Platform News Manager.");
                return;
            }

            // Make sure this load is before the accept events, so that they do not cause adding failure.
            List <EventSource> sources = _persistenceHelper.SelectDynamicType <EventSource>(null, null);

            base.SourceAddedEvent   += new NewsSourceUpdateDelegate(PlatformNewsManager_SourceAddedEvent);
            base.SourceRemovedEvent += new NewsSourceUpdateDelegate(PlatformNewsManager_SourceRemovedEvent);

            if (sources != null)
            {
                foreach (EventSource source in sources)
                {                // Add the source to subscribe to it, than load items.
                    base.AddSource(source);

                    if (source.Enabled)
                    {
                        LoadSourceItemsFromPersistence(source);
                    }
                }
            }

            if (platform != null)
            {// Load the default sources.
                foreach (string feedAddress in platform.Settings.DefaultRSSFeeds)
                {
                    if (GetSourceByAddress(feedAddress) == null)
                    {
                        RssNewsSource newSource = new RssNewsSource();
                        newSource.Initialize(feedAddress);

                        AddSource(newSource);
                    }
                }
            }


            GeneralHelper.FireAndForget(UpdateFeeds);
        }
        /// <summary>
        /// 
        /// </summary>
        public void Initialize(Platform platform)
        {
            SystemMonitor.CheckWarning(NewsSourcesUnsafe.Count == 0, "Manager already has assigned sources.");

            _platform = platform;

            _persistenceHelper = CreatePersistenceHelper(platform.Settings);
            if (_persistenceHelper == null)
            {
                SystemMonitor.Error("Failed to initialize the persistence helper for Platform News Manager.");
                return;
            }

            // Make sure this load is before the accept events, so that they do not cause adding failure.
            List<EventSource> sources = _persistenceHelper.SelectDynamicType<EventSource>(null, null);

            base.SourceAddedEvent += new NewsSourceUpdateDelegate(PlatformNewsManager_SourceAddedEvent);
            base.SourceRemovedEvent += new NewsSourceUpdateDelegate(PlatformNewsManager_SourceRemovedEvent);

            if (sources != null)
            {
                foreach (EventSource source in sources)
                {// Add the source to subscribe to it, than load items.
                    base.AddSource(source);

                    if (source.Enabled)
                    {
                        LoadSourceItemsFromPersistence(source);
                    }
                }
            }

            if (platform != null)
            {// Load the default sources.
                foreach (string feedAddress in platform.Settings.DefaultRSSFeeds)
                {
                    if (GetSourceByAddress(feedAddress) == null)
                    {
                        RssNewsSource newSource = new RssNewsSource();
                        newSource.Initialize(feedAddress);

                        AddSource(newSource);
                    }
                }
            }

            GeneralHelper.FireAndForget(UpdateFeeds);
        }