コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        public void Initialize(Platform platform)
        {
            SystemMonitor.CheckWarning(NewsSourcesUnsafe.Count == 0, "Manager already has assigned sources.");

            _platform = platform;

            _persistenceHelper = Platform.CreatePersistenceHelper(platform.Settings);

            _persistenceHelper.SetupTypeMapping(typeof(RssNewsItem), "RssNewsItems", null);
            _persistenceHelper.SetupTypeMapping(typeof(NewsSource), "NewsSources", null);
            _persistenceHelper.SetupTypeMapping(typeof(RssNewsSource), "NewsSources", null);

            _persistenceHelper.SetupTypeMapping(typeof(ForexNewsItem), "ForexNewsItems", null);
            _persistenceHelper.SetupTypeMapping(typeof(ForexNewsSource), "ForexNewsSources", null);


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

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

            foreach (NewsSource source in sources)
            {
                if (source.Enabled)
                {
                    List <RssNewsItem> items =
                        _persistenceHelper.Select <RssNewsItem>(new MatchExpression("NewsSourceId", source.Id), null);

                    foreach (RssNewsItem item in items)
                    {
                        item.Source = source;
                    }

                    // Handle the relation to persistence.
                    source.AddItems(items.ToArray());
                }

                base.AddSource(source);
            }


            GeneralHelper.FireAndForget(UpdateFeeds);
        }
コード例 #2
0
        /// <summary>
        /// Handle enable changed, to load items from DB for source (since it may not have any loaded;
        /// implementing an load "On demand" mechanism"); also store change of Enabled to DB.
        /// </summary>
        /// <param name="source"></param>
        protected override void source_EnabledChangedEvent(NewsSource source)
        {
            if (source.Enabled)
            {// Extract items from DB, since it may have none at this point.
                List <RssNewsItem> items =
                    _persistenceHelper.Select <RssNewsItem>(new MatchExpression("NewsSourceId", source.Id), null);
                foreach (RssNewsItem item in items)
                {
                    item.Source = source;
                }

                // Handle the relation to persistence.
                source.AddItems(items.ToArray());
            }

            // Update source to DB.
            source_PersistenceDataUpdatedEvent(source);

            base.source_EnabledChangedEvent(source);
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        public bool Initialize(PlatformSettings settings)
        {
            lock (this)
            {
                _persistenceHelper = Platform.CreatePersistenceHelper(settings);
                _persistenceHelper.SetupTypeMapping(typeof(DataStoreEntry), "DataStoreEntries", null);
                _dataStoreFilesFolder = settings.GetMappedFolder("DataStoreFolder");
            }

            GeneralHelper.FireAndForget(
                delegate()
            {
                try
                {    // Download online dataDelivery source entries.
                    WebRequest request = WebRequest.Create(settings.DataStoreOnlineSourcesXml);
                    request.Timeout    = (int)TimeSpan.FromSeconds(15).TotalMilliseconds;

                    TextReader reader = new StreamReader(request.GetResponse().GetResponseStream());

                    // If you get an error here in DEBUG MODE, just ignore it, it is a bug in VS 2008.
                    XmlSerializer serializer = new XmlSerializer(typeof(OnlineEntrySource[]));

                    OnlineEntrySource[] sources = (OnlineEntrySource[])serializer.Deserialize(reader);

                    lock (_onlineEntrySources)
                    {    // _onlineEntrySources contains serialized existing sources.
                        _onlineEntrySources.AddRange(sources);
                        sources = _onlineEntrySources.ToArray();
                    }

                    foreach (OnlineEntrySource source in sources)
                    {
                        if (OnlineEntrySourceAddedEvent != null)
                        {
                            OnlineEntrySourceAddedEvent(this, source);
                        }
                    }
                }
                catch (Exception ex)
                {
                    SystemMonitor.OperationError("Failed to obtain online data souces [" + ex.Message + "].", TracerItem.PriorityEnum.Low);
                }
            }
                );

            if (Directory.Exists(_dataStoreFilesFolder) == false)
            {
                if (Directory.CreateDirectory(_dataStoreFilesFolder) == null)
                {
                    SystemMonitor.OperationError("Failed to create Data Store folder [" + settings.GetMappedFolder("DataStoreFolder") + "]");
                    return(false);
                }
            }

            List <DataStoreEntry> entries = _persistenceHelper.Select <DataStoreEntry>(null, null);

            foreach (DataStoreEntry entry in entries)
            {
                DoAddEntry(entry);
            }

            ChangeOperationalState(OperationalStateEnum.Operational);

            return(true);
        }
コード例 #4
0
        /// <summary>
        /// 
        /// </summary>
        public bool Initialize(PlatformSettings settings)
        {
            lock (this)
            {
                _persistenceHelper = Platform.CreatePersistenceHelper(settings);
                _persistenceHelper.SetupTypeMapping(typeof(DataStoreEntry), "DataStoreEntries", null);
                _dataStoreFilesFolder = settings.GetMappedFolder("DataStoreFolder");
            }

            GeneralHelper.FireAndForget(
                delegate()
                {
                    try
                    {// Download online dataDelivery source entries.
                        WebRequest request = WebRequest.Create(settings.DataStoreOnlineSourcesXml);
                        request.Timeout = (int)TimeSpan.FromSeconds(15).TotalMilliseconds;

                        TextReader reader = new StreamReader(request.GetResponse().GetResponseStream());

                        // If you get an error here in DEBUG MODE, just ignore it, it is a bug in VS 2008.
                        XmlSerializer serializer = new XmlSerializer(typeof(OnlineEntrySource[]));

                        OnlineEntrySource[] sources = (OnlineEntrySource[])serializer.Deserialize(reader);

                        lock (_onlineEntrySources)
                        {// _onlineEntrySources contains serialized existing sources.
                            _onlineEntrySources.AddRange(sources);
                            sources = _onlineEntrySources.ToArray();
                        }

                        foreach (OnlineEntrySource source in sources)
                        {
                            if (OnlineEntrySourceAddedEvent != null)
                            {
                                OnlineEntrySourceAddedEvent(this, source);
                            }
                        }

                    }
                    catch (Exception ex)
                    {
                        SystemMonitor.OperationError("Failed to obtain online data souces [" + ex.Message + "].", TracerItem.PriorityEnum.Low);
                    }
                }
            );

            if (Directory.Exists(_dataStoreFilesFolder) == false)
            {
                if (Directory.CreateDirectory(_dataStoreFilesFolder) == null)
                {
                    SystemMonitor.OperationError("Failed to create Data Store folder [" + settings.GetMappedFolder("DataStoreFolder") + "]");
                    return false;
                }
            }

            List<DataStoreEntry> entries = _persistenceHelper.Select<DataStoreEntry>(null, null);
            foreach (DataStoreEntry entry in entries)
            {
                DoAddEntry(entry);
            }

            ChangeOperationalState(OperationalStateEnum.Operational);

            return true;
        }
コード例 #5
0
        /// <summary>
        /// 
        /// </summary>
        public void Initialize(Platform platform)
        {
            SystemMonitor.CheckWarning(NewsSourcesUnsafe.Count == 0, "Manager already has assigned sources.");

            _platform = platform;

            _persistenceHelper = Platform.CreatePersistenceHelper(platform.Settings);

            _persistenceHelper.SetupTypeMapping(typeof(RssNewsItem), "RssNewsItems", null);
            _persistenceHelper.SetupTypeMapping(typeof(NewsSource), "NewsSources", null);
            _persistenceHelper.SetupTypeMapping(typeof(RssNewsSource), "NewsSources", null);

            _persistenceHelper.SetupTypeMapping(typeof(ForexNewsItem), "ForexNewsItems", null);
            _persistenceHelper.SetupTypeMapping(typeof(ForexNewsSource), "ForexNewsSources", null);

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

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

            foreach (NewsSource source in sources)
            {
                if (source.Enabled)
                {
                    List<RssNewsItem> items =
                        _persistenceHelper.Select<RssNewsItem>(new MatchExpression("NewsSourceId", source.Id), null);

                    foreach (RssNewsItem item in items)
                    {
                        item.Source = source;
                    }

                    // Handle the relation to persistence.
                    source.AddItems(items.ToArray());
                }

                base.AddSource(source);
            }

            GeneralHelper.FireAndForget(UpdateFeeds);
        }