Exemplo n.º 1
0
        public async Task StartStreamAsync(string url)
        {
            Func <HttpWebRequest> generateWebRequest = delegate
            {
                var queryBuilder = new StringBuilder(url);
                AddBaseParametersToQuery(queryBuilder);

                var streamQuery = _twitterQueryFactory.Create(queryBuilder.ToString());
                return(_twitterRequestGenerator.GetQueryWebRequest(streamQuery));
            };

            Action <string> generateTweetDelegate = json =>
            {
                RaiseJsonObjectReceived(json);

                var tweet = _tweetFactory.GenerateTweetFromJson(json);
                if (tweet == null)
                {
                    TryInvokeGlobalStreamMessages(json);
                    return;
                }

                var detectedTracksAndActions = _streamTrackManager.GetMatchingTracksAndActions(tweet.Text);
                var detectedTracks           = detectedTracksAndActions.Select(x => x.Item1);
                if (detectedTracksAndActions.Any())
                {
                    this.Raise(MatchingTweetReceived, new MatchedTweetReceivedEventArgs(tweet, detectedTracks));
                }
            };

            await _streamResultGenerator.StartStreamAsync(generateTweetDelegate, generateWebRequest);
        }
Exemplo n.º 2
0
        public async Task StartStreamAsync(string url)
        {
            Func <HttpWebRequest> generateWebRequest = delegate
            {
                if (_filterLanguage != null)
                {
                    url = url.AddParameterToQuery("language", _filterLanguage);
                }

                return(_twitterRequestGenerator.GetQueryWebRequest(url, HttpMethod.GET));
            };

            Action <string> generateTweetDelegate = json =>
            {
                RaiseJsonObjectReceived(json);

                var tweet = _tweetFactory.GenerateTweetFromJson(json);
                if (tweet == null)
                {
                    TryInvokeGlobalStreamMessages(json);
                    return;
                }

                var detectedTracksAndActions = _streamTrackManager.GetMatchingTracksAndActions(tweet.Text);
                var detectedTracks           = detectedTracksAndActions.Select(x => x.Item1);
                if (detectedTracksAndActions.Any())
                {
                    this.Raise(MatchingTweetReceived, new MatchedTweetReceivedEventArgs(tweet, detectedTracks));
                }
            };

            await _streamResultGenerator.StartStreamAsync(generateTweetDelegate, generateWebRequest);
        }
Exemplo n.º 3
0
        public async Task StartStream(string url)
        {
            Func <HttpWebRequest> generateWebRequest = delegate
            {
                if (_filterLanguage != null)
                {
                    url = url.AddParameterToQuery("language", _filterLanguage);
                }

                return(_twitterRequestGenerator.GetQueryWebRequest(url, HttpMethod.GET));
            };

            Action <string> generateTweetDelegate = json =>
            {
                this.Raise(JsonObjectReceived, new JsonObjectEventArgs(json));

                var tweet = _tweetFactory.GenerateTweetFromJson(json);
                if (tweet == null)
                {
                    TryInvokeGlobalStreamMessages(json);
                    return;
                }

                this.Raise(TweetReceived, new TweetReceivedEventArgs(tweet));
            };

            await _streamResultGenerator.StartStreamAsync(generateTweetDelegate, generateWebRequest);
        }
Exemplo n.º 4
0
        public async Task StartStream(string url)
        {
            Func <HttpWebRequest> generateWebRequest = delegate
            {
                var queryBuilder = new StringBuilder(url);
                AddBaseParametersToQuery(queryBuilder);

                var streamQuery = _twitterQueryFactory.Create(queryBuilder.ToString());
                return(_twitterRequestGenerator.GetQueryWebRequest(streamQuery));
            };

            Action <string> generateTweetDelegate = json =>
            {
                this.Raise(JsonObjectReceived, new JsonObjectEventArgs(json));

                var tweet = _tweetFactory.GenerateTweetFromJson(json);
                if (tweet == null)
                {
                    TryInvokeGlobalStreamMessages(json);
                    return;
                }

                this.Raise(TweetReceived, new TweetReceivedEventArgs(tweet));
            };

            await _streamResultGenerator.StartStreamAsync(generateTweetDelegate, generateWebRequest);
        }
Exemplo n.º 5
0
        public string ExecuteQuery(string url, HttpMethod httpMethod, IEnumerable <IOAuthQueryParameter> headers = null)
        {
            var webRequest = _twitterRequestGenerator.GetQueryWebRequest(url, httpMethod, headers);

            return(_webRequestExecutor.ExecuteWebRequest(webRequest));
        }
Exemplo n.º 6
0
        public string ExecuteQuery(ITwitterQuery twitterQuery)
        {
            var webRequest = _twitterRequestGenerator.GetQueryWebRequest(twitterQuery);

            return(_webRequestExecutor.ExecuteWebRequest(webRequest));
        }