示例#1
0
        public async Task UpdateFeedCache()
        {
            foreach (var subscription in await this.feedRepository.GetAll())
            {
                var rssFeed = await RssFeed.CreateFromUrl(subscription.Feed.FeedUrl);

                var entries = rssFeed.Entries;
                foreach (var entry in entries)
                {
                    entry.FeedId = subscription.Feed.Id;
                }
                await this.feedRepository.UpdateFeedEntries(entries);
            }
        }
示例#2
0
        public async Task <FeedSubscription> Subscribe(string feedUrl)
        {
            if (feedUrl == null)
            {
                throw new ArgumentNullException(nameof(feedUrl));
            }

            if (!await RssFeed.IsValid(feedUrl))
            {
                throw new FeedException("Invalid feed url or feed content is not supported");
            }

            var feed = await RssFeed.CreateFromUrl(feedUrl);

            var subscription = feed.SubscribeTo();

            await feedRepository.AddSubscription(subscription);

            return(subscription);
        }
示例#3
0
        private static void UpdateDatabase(IApplicationBuilder app)
        {
            using (var serviceScope = app.ApplicationServices
                                      .GetRequiredService <IServiceScopeFactory>()
                                      .CreateScope())
            {
                using (var context = serviceScope.ServiceProvider.GetService <AppDbContext>())
                {
                    context.Database.Migrate();
                    if (context.FeedSubscriptions.Any())
                    {
                        return;
                    }

                    var feed1 = RssFeed.CreateFromUrl("http://newsrss.bbc.co.uk/rss/newsonline_world_edition/americas/rss.xml").GetAwaiter().GetResult().SubscribeTo();
                    var feed2 = RssFeed.CreateFromUrl("https://www.ed.gov/feed").GetAwaiter().GetResult().SubscribeTo();
                    var feed3 = RssFeed.CreateFromUrl("http://feeds1.nytimes.com/nyt/rss/Sports").GetAwaiter().GetResult().SubscribeTo();
                    context.FeedSubscriptions.AddRange(new[] { feed1, feed2, feed3 });
                    context.SaveChanges();
                }
            }
        }