Beispiel #1
0
        private static async Task <TwitterTimelineResult> InvokeSut(string oAuthToken, string handle, bool includeRaw = false)
        {
            string responseData = GetTestFileContent();

            var messageResponse = FakeHttpMessageHandler.GetStringHttpResponseMessage(responseData);

            var fakeMessageHandler = new FakeHttpMessageHandler(new HttpMessageOptions()
            {
                HttpResponseMessage = messageResponse
            });

            var sut = new TwitterTimelineCrawler(fakeMessageHandler)
            {
                OAuthToken = oAuthToken
            };

            var config = new TwitterTimelineCrawlerConfig
            {
                Handle            = handle,
                IncludeRawContent = includeRaw
            };

            var result = await sut.DoWorkAsync(config);

            return(result);
        }
        private static async Task <TwitterTimelineCrawlerResult> InvokeSut(string oAuthToken, string handle)
        {
            string responseData = GetTestFileContent();

            var messageResponse = FakeHttpMessageHandler.GetStringHttpResponseMessage(responseData);

            var fakeMessageHandler = new FakeHttpMessageHandler("*", messageResponse);

            var sut = new TwitterTimelineCrawler(fakeMessageHandler);

            sut.OAuthToken = oAuthToken;

            var config = new TwitterTimelineCrawlerConfig();

            config.Handle = handle;

            var result = await sut.DoWorkAsync(config);

            return(result);
        }
Beispiel #3
0
        public async Task <CrawlerRun> RunAllCrawlers()
        {
            var watch = new System.Diagnostics.Stopwatch();

            watch.Start();

            var crawlerRunResult = new CrawlerRun();

            if (_config.Crawler == null)
            {
                return(crawlerRunResult);
            }

            // Feeds
            if (_config.Crawler.FeedsToCrawl.Any())
            {
                foreach (var feed in _config.Crawler.FeedsToCrawl)
                {
                    var feedCrawler = new FeedCrawler();
                    var feedResult  = await feedCrawler.DoWorkAsync(feed);

                    crawlerRunResult.Results.Add(feedResult);
                }
            }

            // Tweets
            if (_config.Secrets.IsTwitterConsumerConfigured)
            {
                ITwitterOAuthTokenService oAuthTokenLoader = new TwitterOAuthTokenService();
                var oauth = await oAuthTokenLoader.GetAsync(_config.Secrets.TwitterConsumerKey, _config.Secrets.TwitterConsumerSecret);

                if (string.IsNullOrWhiteSpace(oauth) == false)
                {
                    if (_config.Crawler.TwitterTimelinesToCrawl.Any())
                    {
                        foreach (var handle in _config.Crawler.TwitterTimelinesToCrawl)
                        {
                            var twitterTimelineCrawler = new TwitterTimelineCrawler();
                            twitterTimelineCrawler.OAuthToken = oauth;

                            var twitterTimelineResult = await twitterTimelineCrawler.DoWorkAsync(handle);

                            crawlerRunResult.Results.Add(twitterTimelineResult);
                        }
                    }

                    if (_config.Crawler.TwitterUsersToCrawl.Any())
                    {
                        foreach (var handle in _config.Crawler.TwitterUsersToCrawl)
                        {
                            var twitterUserCrawler = new TwitterUserCrawler();
                            twitterUserCrawler.OAuthToken = oauth;

                            var twitterUserResult = await twitterUserCrawler.DoWorkAsync(handle);

                            crawlerRunResult.Results.Add(twitterUserResult);
                        }
                    }
                }
            }

            watch.Stop();
            crawlerRunResult.RunDurationInMilliseconds = watch.ElapsedMilliseconds;
            crawlerRunResult.RunOn = DateTime.UtcNow;

            return(crawlerRunResult);
        }
Beispiel #4
0
        /// <summary>
        /// Will run through all applied crawlers.
        /// </summary>
        public async Task <CrawlerRun> RunAllCrawlers()
        {
            Trace.TraceInformation($"{nameof(RunAllCrawlers)} invoked.");
            var watch = new Stopwatch();

            watch.Start();

            var crawlerRunResult = new CrawlerRun();

            if (_config.Crawler == null)
            {
                return(crawlerRunResult);
            }

            // Feeds
            if (_config.Crawler.FeedsToCrawl.Any())
            {
                foreach (var feedConfig in _config.Crawler.FeedsToCrawl)
                {
                    var feedCrawler = new FeedCrawler();
                    var feedResult  = await feedCrawler.DoWorkAsync(feedConfig);

                    crawlerRunResult.AddResultDataPair(feedConfig.Key, feedResult);
                }
            }

            // GitHubEvents
            if (_config.Crawler.GitHubEventsToCrawl.Any())
            {
                foreach (var githubEventConfig in _config.Crawler.GitHubEventsToCrawl)
                {
                    var eventCrawler = new GitHubEventCrawler();
                    var eventResult  = await eventCrawler.DoWorkAsync(githubEventConfig);

                    crawlerRunResult.AddResultDataPair(githubEventConfig.Key, eventResult);
                }
            }

            // GitHubIssues
            if (_config.Crawler.GitHubIssuesToCrawl.Any())
            {
                foreach (var githubIssueConfig in _config.Crawler.GitHubIssuesToCrawl)
                {
                    var issueCrawler = new GitHubIssueCrawler();
                    var issueResult  = await issueCrawler.DoWorkAsync(githubIssueConfig);

                    crawlerRunResult.AddResultDataPair(githubIssueConfig.Key, issueResult);
                }
            }

            // Tweets
            if (_config.Secrets.IsTwitterConsumerConfigured)
            {
                ITwitterOAuthTokenService oAuthTokenLoader = new TwitterOAuthTokenService();
                var oauth = await oAuthTokenLoader.GetAsync(_config.Secrets.TwitterConsumerKey, _config.Secrets.TwitterConsumerSecret);

                if (string.IsNullOrWhiteSpace(oauth) == false)
                {
                    if (_config.Crawler.TwitterTimelinesToCrawl.Any())
                    {
                        foreach (var twitterConfig in _config.Crawler.TwitterTimelinesToCrawl)
                        {
                            var twitterTimelineCrawler = new TwitterTimelineCrawler {
                                OAuthToken = oauth
                            };

                            var twitterTimelineResult = await twitterTimelineCrawler.DoWorkAsync(twitterConfig);

                            crawlerRunResult.AddResultDataPair(twitterConfig.Key, twitterTimelineResult);
                        }
                    }

                    if (_config.Crawler.TwitterUsersToCrawl.Any())
                    {
                        foreach (var twitterConfig in _config.Crawler.TwitterUsersToCrawl)
                        {
                            var twitterUserCrawler = new TwitterUserCrawler {
                                OAuthToken = oauth
                            };

                            var twitterUserResult = await twitterUserCrawler.DoWorkAsync(twitterConfig);

                            crawlerRunResult.AddResultDataPair(twitterConfig.Key, twitterUserResult);
                        }
                    }
                }
            }

            watch.Stop();
            crawlerRunResult.RunDurationInMilliseconds = watch.ElapsedMilliseconds;
            crawlerRunResult.RunOn = DateTime.UtcNow;

            Trace.TraceInformation($"{nameof(RunAllCrawlers)} done.");

            return(crawlerRunResult);
        }