예제 #1
0
        public void TestInitialize()
        {
            this.mockRepository = new MockRepository(MockBehavior.Loose);
            expectedResult      = "some result";
            //this.mockHttpClientFactory = this.mockRepository.Create<IHttpClientFactory>();
            this.mockHttpClientProvider  = this.mockRepository.Create <IHttpClientProvider>();
            incommingTweetQueue          = new IncommingTweetQueue(new CloudStorageAccountHandler());
            this.mockRuntimeStatsService = this.mockRepository.Create <IRuntimeStatsService>();
            this.mockStreamService       = this.mockRepository.Create <IStreamService>();

            var binDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location).TrimEnd(@"\bin".ToArray());
            var dataFilePath = Path.GetFullPath(Path.Combine(binDirectory, Constants.AppSettingsJson));

            configuration = new ConfigurationBuilder()
                            .AddJsonFile(dataFilePath, optional: true)
                            .Build();

            this.mockStreamReaderHandler = this.mockRepository.Create <IStreamReaderHandler>();

            this.mockStreamService.Setup(o => o.ReciveTweets(this.mockHttpClientProvider.Object, It.IsAny <TwitterConfiguration>(),
                                                             It.IsAny <IIncommingTweetQueue>(), It.IsAny <IStreamReaderHandler>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(expectedResult));
            this.mockStreamService.SetupAllProperties();
            this.mockRuntimeStatsService.SetupAllProperties();
            this.mockHttpClientProvider.SetupAllProperties();
        }
예제 #2
0
        public async Task <string> ReciveTweets(IHttpClientProvider client, TwitterConfiguration twitterConfiguration
                                                , IIncommingTweetQueue incommingTweetQueue, IStreamReaderHandler streamReaderHandler, CancellationToken cancellationToken)
        {
            int      tweetCount = 0;
            var      tasks      = new List <Task>();
            DateTime startRun   = DateTime.UtcNow;

            try
            {
                client.BaseAddress = new Uri(twitterConfiguration.BaseUrl);

                if (client != null)
                {
                    client.DefaultRequestHeaders.Add("Authorization", "Bearer " + twitterConfiguration.OAuthToken);
                    var stream = await client.GetStreamAsync(twitterConfiguration.SampleStreamUrl);

                    try
                    {
                        using (var reader = streamReaderHandler.GetStreamReader(stream))
                        {
                            do
                            {
                                var rawTweetData = await reader.ReadLineAsync();

                                RawTweetModel messageWithData = new RawTweetModel()
                                {
                                    TweetCount = tweetCount, RawTweetData = rawTweetData
                                };
                                // send new tweet onto queue for processing
                                tasks.Add(Task.Run(() => incommingTweetQueue.SendMessageOntoQueue(JsonConvert.SerializeObject(messageWithData))));
                                tweetCount++;
                                cancellationToken.ThrowIfCancellationRequested();
                            } while (true);
                        }
                        //
                    }
                    catch (OperationCanceledException)
                    {
                        // canceled
                    }
                    catch (Exception exc)
                    {
                        throw exc;
                    }
                }
            }
            catch (Exception exc)
            {
                throw exc;
            }
            Task.WaitAll(tasks.ToArray());

            return("Done Collecting Tweets... ");
        }
        public IncommingTweets(IHttpClientFactory httpClientFactory, IProcessedIncommingQueue processedIncommingQueue, 
                                IIncommingTweetQueue incommingTweetQueue, ITweetScrapingService tweetProcessingService,
                                IIncommingTweetQueuePoison incommingTweetQueuePoison, ITweetAggregationService tweetAggregationService)
        {
           
            var binDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location).TrimEnd(@"\bin".ToArray());
            var emojiFilePath = Path.GetFullPath(Path.Combine(binDirectory, Constants.EmojiCodesFileName));             
            _knownEmojis = File.ReadAllText(emojiFilePath);

            _httpClientFactory         = httpClientFactory;
            _processedIncommingQueue   = processedIncommingQueue;
            _incommingTweetQueue       = incommingTweetQueue;
            _incommingTweetQueuePoison = incommingTweetQueuePoison;
            _tweetProcessingService    = tweetProcessingService;
            _tweetAggregationService   = tweetAggregationService;
        }
예제 #4
0
        public QueueHub(IHttpClientProvider httpClientProvider, IIncommingTweetQueue incommingTweetQueue, IConfiguration configuration,
                        IRuntimeStatsService runtimeStatsService, IStreamService streamService, IStreamReaderHandler streamReaderHandler)
        {
            _httpClientProvider  = httpClientProvider;
            _incommingTweetQueue = incommingTweetQueue;
            _runtimeStatsService = runtimeStatsService;
            _streamService       = streamService;
            _streamReaderHandler = streamReaderHandler;

            _twitterConfiguration = new TwitterConfiguration()
            {
                BaseUrl         = configuration.GetValue <string>(Constants.TwitterBaseUrlName).ToString(),
                OAuthToken      = configuration.GetValue <string>(Constants.TwitterOAuthTokenName).ToString(),
                SampleStreamUrl = configuration.GetValue <string>(Constants.TwitterSampleStreamUrlName).ToString()
            };
        }