Beispiel #1
0
        public bool GenerateAndSaveData()
        {
            List <Feed> feeds = _feedBuilder.Build();

            if (feeds.IsNullOrEmpty())
            {
                return(false);
            }

            var numberOfGeneratedFeeds = feeds.Count;

            foreach (var feed in feeds)
            {
                var feedData = new FeedData
                {
                    CreatedUtc = feed.Updated,
                    Link       = feed.Link
                };

                using (var ms = new MemoryStream())
                {
                    var serializer = new XmlSerializer(typeof(Feed), Ns);
                    serializer.Serialize(ms, feed);
                    feedData.FeedBytes = ms.ToArray();
                }

                _feedRepository.Save(feedData);
            }

            // we only need to keep one version of each feed - remove older ones to avoid filling up the database
            _feedRepository.RemoveOldVersions(numberOfGeneratedFeeds);

            return(true);
        }