コード例 #1
0
ファイル: FeedSourceManager.cs プロジェクト: romesc/RssBandit
        /// <summary>
        /// Adds a new source with the specified name and properties.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="type">The type.</param>
        /// <param name="properties">The properties.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">If name is null</exception>
        /// <exception cref="ArgumentOutOfRangeException">If name is empty</exception>
        /// <exception cref="InvalidOperationException">If source with provided name yet exists</exception>
        public FeedSourceEntry Add(string name, FeedSourceType type, IDictionary properties)
        {
            name.ExceptionIfNullOrEmpty("name");

            if (Contains(name))
            {
                throw new InvalidOperationException("Entry with name '" + name + "' already exists");
            }

            int        id     = UniqueKey;
            FeedSource source = FeedSource.CreateFeedSource(id, type,
                                                            CreateSubscriptionLocation(id, type, properties));
            FeedSourceEntry fse = new FeedSourceEntry(id, source, name, _feedSources.Count);

            //fse.Properties =
            _feedSources.Add(fse.ID, fse);
            return(fse);
        }
コード例 #2
0
ファイル: FeedSourceManager.cs プロジェクト: romesc/RssBandit
        /// <summary>
        /// Loads the feed sources.
        /// </summary>
        /// <param name="feedSources">The feed sources stream.</param>
        public void LoadFeedSources(Stream feedSources)
        {
            if (feedSources == null)
            {
                return;
            }

            try
            {
                XmlParserContext context =
                    new XmlParserContext(null, new RssBanditXmlNamespaceResolver(), null, XmlSpace.None);
                XmlReader reader = new RssBanditXmlReader(feedSources, XmlNodeType.Document, context);

                //convert XML to objects
                XmlSerializer serializer =
                    XmlHelper.SerializerCache.GetSerializer(typeof(SerializableFeedSources));
                SerializableFeedSources mySources = (SerializableFeedSources)serializer.Deserialize(reader);

                _feedSources.Clear();

                lastUsedKey = mySources.LastID;
                int maxUsedKey = 0;
                foreach (FeedSourceEntry fs in mySources.List)
                {
                    if (maxUsedKey < fs.ID)
                    {
                        maxUsedKey = fs.ID;
                    }
                    _feedSources.Add(fs.ID, fs);
                    fs.Source = FeedSource.CreateFeedSource(fs.ID, fs.SourceType,
                                                            CreateSubscriptionLocation(fs.ID, fs.SourceType, fs.Properties));
                }
                if (maxUsedKey > lastUsedKey)
                {
                    lastUsedKey = maxUsedKey;
                }
            }
            catch (Exception e)
            {
                _log.Error("Error on deserializing feed source", e);
            }
        }