public async Task StartMatchingAllConditionsAsync() { _filterStreamTweetMatcher = _filterStreamTweetMatcherFactory.Create(StreamTrackManager, _locations, _followingUserIds); ITwitterRequest CreateTwitterRequest() { var queryBuilder = GenerateANDFilterQuery(); AddBaseParametersToQuery(queryBuilder); var twitterRequest = _client.CreateRequest(); twitterRequest.Query.Url = queryBuilder.ToString(); twitterRequest.Query.HttpMethod = HttpMethod.POST; return(twitterRequest); } void JsonReceived(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 retweetMatchingTracks = matchingTracksEvenArgs.RetweetMatchingTracks; var retweetMatchingLocations = matchingTracksEvenArgs.RetweetMatchingLocations; var retweetMatchingFollowers = matchingTracksEvenArgs.RetweetMatchingFollowers; var quotedTweetMatchingTracks = matchingTracksEvenArgs.QuotedTweetMatchingTracks; var quotedTweetMatchingLocations = matchingTracksEvenArgs.QuotedTweetMatchingLocations; var quotedTweetMatchingFollowers = matchingTracksEvenArgs.QuotedTweetMatchingFollowers; RaiseTweetReceived(matchingTracksEvenArgs); if (DoestTheTweetMatchAllConditions(tweet, matchingTracks, matchingLocations, matchingFollowers) || DoestTheTweetMatchAllConditions(tweet, retweetMatchingTracks, retweetMatchingLocations, retweetMatchingFollowers) || DoestTheTweetMatchAllConditions(tweet, quotedTweetMatchingTracks, quotedTweetMatchingLocations, quotedTweetMatchingFollowers)) { RaiseMatchingTweetReceived(matchingTracksEvenArgs); } else { RaiseNonMatchingTweetReceived(new TweetEventArgs(tweet, json)); } } await _streamResultGenerator.StartAsync(JsonReceived, 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); }