public async Task StartMatchingAnyConditionAsync() { _filterStreamTweetMatcher = _filterStreamTweetMatcherFactory.Create(StreamTrackManager, _locations, _followingUserIds); ITwitterRequest CreateTwitterRequest() { var queryBuilder = GenerateORFilterQuery(); AddBaseParametersToQuery(queryBuilder); var request = _client.CreateRequest(); request.Query.Url = queryBuilder.ToString(); request.Query.HttpMethod = HttpMethod.POST; return(request); } void OnJsonReceived(string json) { RaiseJsonObjectReceived(json); if (IsEvent(json)) { TryInvokeGlobalStreamMessages(json); return; } var tweet = _factories.CreateTweet(json); var matchingTracksEvenArgs = _filterStreamTweetMatcher.GetMatchingTweetEventArgsAndRaiseMatchingElements(tweet, json, MatchOn); var matchingTracks = matchingTracksEvenArgs.MatchingTracks; var matchingLocations = matchingTracksEvenArgs.MatchingLocations; var matchingFollowers = matchingTracksEvenArgs.MatchingFollowers; var isTweetMatching = matchingTracks.Length != 0 || matchingLocations.Length != 0 || matchingFollowers.Length != 0; var quotedTweetMatchingTracks = matchingTracksEvenArgs.QuotedTweetMatchingTracks; var quotedTweetMatchingLocations = matchingTracksEvenArgs.QuotedTweetMatchingLocations; var quotedTweetMatchingFollowers = matchingTracksEvenArgs.QuotedTweetMatchingFollowers; var isQuotedTweetMatching = quotedTweetMatchingTracks.Length != 0 || quotedTweetMatchingLocations.Length != 0 || quotedTweetMatchingFollowers.Length != 0; RaiseTweetReceived(matchingTracksEvenArgs); if (isTweetMatching || isQuotedTweetMatching) { RaiseMatchingTweetReceived(matchingTracksEvenArgs); } else { RaiseNonMatchingTweetReceived(new TweetEventArgs(tweet, json)); } } await _streamResultGenerator.StartAsync(OnJsonReceived, CreateTwitterRequest).ConfigureAwait(false); }
public async Task StartStreamMatchingAnyConditionAsync() { _filterStreamTweetMatcher = _filterStreamTweetMatcherFactory.Create(_streamTrackManager, _locations, _followingUserIds); Func <ITwitterQuery> generateWebRequest = () => { var queryBuilder = GenerateORFilterQuery(); AddBaseParametersToQuery(queryBuilder); return(_twitterQueryFactory.Create(queryBuilder.ToString(), HttpMethod.POST, Credentials)); }; Action <string> tweetReceived = json => { RaiseJsonObjectReceived(json); var tweet = _tweetFactory.GenerateTweetFromJson(json, TweetMode); if (tweet == null) { TryInvokeGlobalStreamMessages(json); return; } var matchingTracksEvenArgs = _filterStreamTweetMatcher.GetMatchingTweetEventArgsAndRaiseMatchingElements(tweet, json, MatchOn); var matchingTracks = matchingTracksEvenArgs.MatchingTracks; var matchingLocations = matchingTracksEvenArgs.MatchingLocations; var matchingFollowers = matchingTracksEvenArgs.MatchingFollowers; var isTweetMatching = matchingTracks.Length != 0 || matchingLocations.Length != 0 || matchingFollowers.Length != 0; var quotedTweetMatchingTracks = matchingTracksEvenArgs.QuotedTweetMatchingTracks; var quotedTweetMatchingLocations = matchingTracksEvenArgs.QuotedTweetMatchingLocations; var quotedTweetMatchingFollowers = matchingTracksEvenArgs.QuotedTweetMatchingFollowers; var isQuotedTweetMatching = quotedTweetMatchingTracks.Length != 0 || quotedTweetMatchingLocations.Length != 0 || quotedTweetMatchingFollowers.Length != 0; RaiseTweetReceived(matchingTracksEvenArgs); if (isTweetMatching || isQuotedTweetMatching) { RaiseMatchingTweetReceived(matchingTracksEvenArgs); } else { RaiseNonMatchingTweetReceived(new TweetEventArgs(tweet, json)); } }; await _streamResultGenerator.StartStreamAsync(tweetReceived, generateWebRequest); }