コード例 #1
0
        private void Stream_MatchingTweetReceived(object sender, Tweetinvi.Events.MatchedTweetReceivedEventArgs e)
        {
            _logger.WriteLine($"Got a tweet from {e.Tweet.CreatedBy} [{e.Tweet.CreatedBy.ScreenName}]");
            var user = User.GetUserFromId(e.Tweet.CreatedBy.Id);

            OnTweetReceived?.Invoke(this, new TweetReceivedEventArgs(e.Tweet, e.Json, user));
        }
コード例 #2
0
        public async Task StartStreamAsync(string url)
        {
            Func<ITwitterQuery> generateTwitterQuery = delegate
            {
                var queryBuilder = new StringBuilder(url);
                AddBaseParametersToQuery(queryBuilder);

                return _twitterQueryFactory.Create(queryBuilder.ToString(), HttpMethod.GET, Credentials);
            };

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

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

                var detectedTracksAndActions = _streamTrackManager.GetMatchingTracksAndActions(tweet.FullText);
                var detectedTracks = detectedTracksAndActions.Select(x => x.Item1);

                var eventArgs = new MatchedTweetReceivedEventArgs(tweet)
                {
                    MatchingTracks = detectedTracks.ToArray(),
                };

                if (detectedTracksAndActions.Any())
                {
                    eventArgs.MatchOn = MatchOn.TweetText;

                    RaiseTweetReceived(eventArgs);
                    RaiseMatchingTweetReceived(eventArgs);
                }
                else
                {
                    RaiseTweetReceived(eventArgs);
                    RaiseNonMatchingTweetReceived(new TweetEventArgs(tweet));
                }
            };

            await _streamResultGenerator.StartStreamAsync(generateTweetDelegate, generateTwitterQuery);
        }
コード例 #3
0
 protected void RaiseMatchingTweetReceived(MatchedTweetReceivedEventArgs eventArgs)
 {
     this.Raise(MatchingTweetReceived, eventArgs);
 }