Пример #1
0
        public void IsFeedActive_Unordered_True()
        {
            var feed = new Feed
            {
                Items = new List <FeedItem>
                {
                    new FeedItem {
                        PublishingDate = new DateTime(1, 1, 1)
                    },
                    new FeedItem {
                        PublishingDate = new DateTime(1, 3, 1)
                    },                                                       // Most recent, but not last in list
                    new FeedItem {
                        PublishingDate = new DateTime(1, 2, 1)
                    },
                }
            };
            var days    = 50;
            var refDate = new DateTime(year: 1, month: 4, day: 1); // one month since last item

            var rssReader = new RSSFeedReader();
            var isActive  = rssReader.IsFeedActive(feed, days, refDate);

            Assert.True(isActive);
        }
Пример #2
0
        public void IsFeedActive_True()
        {
            var feed = new Feed
            {
                Items = new List <FeedItem>
                {
                    new FeedItem {
                        PublishingDate = new DateTime(1, 1, 1)
                    },
                    new FeedItem {
                        PublishingDate = new DateTime(1, 2, 1)
                    },
                    new FeedItem {
                        PublishingDate = new DateTime(1, 3, 1)
                    },
                }
            };
            var days    = 50;
            var refDate = new DateTime(year: 1, month: 4, day: 1);

            var rssReader = new RSSFeedReader();
            var isActive  = rssReader.IsFeedActive(feed, days, refDate);

            Assert.True(isActive);
        }
Пример #3
0
        public void IsFeedActive_FeedNull_False()
        {
            Feed feed    = null;
            var  days    = 0;
            var  refDate = new DateTime(year: 1, month: 1, day: 1);

            var rssReader = new RSSFeedReader();
            var isActive  = rssReader.IsFeedActive(feed, days, refDate);

            Assert.False(isActive);
        }
Пример #4
0
        public void IsFeedActive_FeedEmpty_False()
        {
            var feed = new Feed
            {
                Items = new List <FeedItem>(),
            };
            var days    = 0;
            var refDate = new DateTime(year: 1, month: 1, day: 1);

            var rssReader = new RSSFeedReader();
            var isActive  = rssReader.IsFeedActive(feed, days, refDate);

            Assert.False(isActive);
        }
Пример #5
0
        public void When_getting_feed_data_for_a_single_url()
        {
            var    reader             = new RSSFeedReader();
            string url                = "https://martinfowler.com/feed.atom";
            List <BlogItemModel> feed = reader.GetFeedData(url);

            BlogItemModel item = feed.FirstOrDefault();

            Assert.That(feed != null);
            Assert.That(item.Description != null);
            Assert.That(item.Title != null);
            Assert.That(item.Author != null);
            Assert.That(item.Link != null);
            Assert.That(item.Updated != null);
        }
Пример #6
0
        public void When_getting_trying_to_use_non_feed_url()
        {
            var reader = new RSSFeedReader();
            var urls   = new List <string>()
            {
                "https://emmersionlearning.com"
            };
            List <BlogItemModel> items = new List <BlogItemModel>();

            urls.ForEach(url =>
            {
                items.AddRange(reader.GetFeedData(url));
            });

            Assert.That(items.Count == 0);
        }
Пример #7
0
        public void When_getting_feed_data_for_multiple_urls()
        {
            var reader = new RSSFeedReader();
            var urls   = new List <string>()
            {
                "https://martinfowler.com/feed.atom", "https://www.codingblocks.net/podcast-feed.xml"
            };
            List <BlogItemModel> items = new List <BlogItemModel>();

            urls.ForEach(url =>
            {
                items.AddRange(reader.GetFeedData(url));
            });

            Assert.That(items.Count > 0);
        }
Пример #8
0
        private static String UploadRssFeeds(Configuration config, CosmosDbClient client, AzureStorageUtility storageUtility)
        {
            /////////////////////////////////////////////////////////////////////////////////////////////////
            // Looop through each of the RSS feeds, collect the articles, then upload them.
            /////////////////////////////////////////////////////////////////////////////////////////////////
            foreach (RssFeedInfo feed in config.Feeds)
            {
                Console.WriteLine("Processing feed : " + feed.RSSFeed);
                using (RSSFeedReader rssReader = new RSSFeedReader(feed.RSSFeed))
                {
                    /////////////////////////////////////////////////////////////////////////////////////////
                    // The the batch of articles.....
                    /////////////////////////////////////////////////////////////////////////////////////////
                    int feedItemCount            = 0;
                    List <RSSFeedItem> feedItems = rssReader.ReadFeed();
                    Console.WriteLine("Feed : " + feed.RSSFeed + " has " + feedItems.Count + " items");

                    /////////////////////////////////////////////////////////////////////////////////////////
                    // For each article, upload it's image(s) and content.
                    /////////////////////////////////////////////////////////////////////////////////////////
                    foreach (RSSFeedItem item in feedItems)
                    {
                        Console.WriteLine("Inserting : " + item.Title);

                        Article        mainArticle  = new Article();
                        List <Article> imageContent = new List <Article>();

                        // Set up the images
                        foreach (RSSImageItem image in item.Images)
                        {
                            String blobUri = storageUtility.UploadBlob(image.Path, feed.AzureStorageContainer).Result;
                            if (!String.IsNullOrEmpty(blobUri))
                            {
                                Article media = new Article();
                                media.ArtifactType     = "image";
                                media.AssetHash        = image.Hash;
                                media.UniqueIdentifier = image.Id;
                                media.SetProperty(ArticleProperties.RetrievalDate, DateTime.Now.ToString("O"));
                                media.SetProperty(ArticleProperties.OriginalUri, image.Uri);
                                media.SetProperty(ArticleProperties.InternalUri, blobUri);
                                imageContent.Add(media);
                            }
                        }

                        // Now set up the article iteself
                        mainArticle.SetProperty(ArticleProperties.OriginalUri, item.Uri);
                        mainArticle.SetProperty(ArticleProperties.RetrievalDate, DateTime.Now.ToString("O"));
                        mainArticle.SetProperty(ArticleProperties.PostDate, item.PublishedDate);
                        mainArticle.SetProperty(ArticleProperties.Title, Program.CleanInput(item.Title));
                        mainArticle.SetProperty(ArticleProperties.Body, Program.CleanInput(item.Summary));

                        List <Dictionary <string, string> > childFiles = new List <Dictionary <string, string> >();
                        foreach (Article file in imageContent)
                        {
                            Dictionary <String, String> obj = new Dictionary <string, string>();
                            obj.Add(Article.MEDIA_ID, file.UniqueIdentifier);
                            obj.Add(Article.MEDIA_ORIG_URI, file.GetProperty(ArticleProperties.OriginalUri).ToString());
                            obj.Add(Article.MEDIA_INTERNAL_URI, file.GetProperty(ArticleProperties.InternalUri).ToString());
                            childFiles.Add(obj);
                        }
                        mainArticle.SetProperty(ArticleProperties.ChildImages, childFiles);

                        mainArticle.SetProperty(ArticleProperties.ChildVideos, null);
                        mainArticle.SetProperty(ArticleProperties.Author, null);
                        mainArticle.SetProperty(ArticleProperties.HeroImage, null);

                        // Insert the media files first
                        foreach (Article imageArticle in imageContent)
                        {
                            try
                            {
                                bool imageResult = client.CreateDocument(config.CosmosDatabase, config.CosmosIngestCollection, imageArticle).Result;
                                Console.WriteLine("Image Insert: " + imageResult.ToString());
                            }
                            catch (Exception ex) { }
                        }

                        // Wait briefly....
                        System.Threading.Thread.Sleep(500);

                        bool articleResult = client.CreateDocument(config.CosmosDatabase, config.CosmosIngestCollection, mainArticle).Result;
                        Console.WriteLine("Article Insert: " + articleResult.ToString());

                        // Only allow one for each feed for now
                        if (++feedItemCount > 5)
                        {
                            break;
                        }
                    }
                }
            }

            return("Finished uploading current articles.");
        }