Ejemplo n.º 1
0
        /// <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);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Saves the feed sources.
        /// </summary>
        /// <param name="feedSourcesUrl">The feed sources URL.</param>
        public void SaveFeedSources(string feedSourcesUrl)
        {
            var serializer = XmlHelper.SerializerCache.GetSerializer(typeof(SerializableFeedSources));
            var sources    = new SerializableFeedSources();

            sources.LastID = lastUsedKey;

            if (_feedSources != null && _feedSources.Count > 0)
            {
                foreach (var f in _feedSources.Values)
                {
                    sources.List.Add(f);
                    f.Properties = BuildProperties(f);
                }
            }

            using (var stream = new MemoryStream())
            {
                serializer.Serialize(stream, sources);
                FileHelper.WriteStreamWithBackup(feedSourcesUrl, stream);
            }
        }