private static void Stream_TweetReceived(object sender, MatchedTweetReceivedEventArgs e) { if ( e.Tweet.InReplyToStatusId == null) { return; } ITweet r1 = Tweetinvi.Tweet.GetTweet((long)e.Tweet.InReplyToStatusId); if (r1 == null) return; Conversation c = new Conversation(); c.Tweets.Add(InviTweetToPTTweet(e.Tweet)); c.Tweets.Add(InviTweetToPTTweet(r1)); using (var model = new AnnotatorModel()) { Console.WriteLine(r1.Text); Console.WriteLine(e.Tweet.Text); model.Tweets.Add(InviTweetToPTTweet(r1)); model.Tweets.Add(InviTweetToPTTweet(e.Tweet)); model.Conversations.Add(c); model.SaveChanges(); } }
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.Text); 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); }
private void Receive(object sender, MatchedTweetReceivedEventArgs args) { Console.Write("."); //this._totalRecievedStream++; //if (this._totalRecievedStream % 10 == 0) //Logger.Log("Stream (" + this._model.Hashtag + ") total recieved: " + this._totalRecievedStream); this._tweetRepo.Add(args.Tweet); }
protected void RaiseMatchingTweetReceived(MatchedTweetReceivedEventArgs eventArgs) { this.Raise(MatchingTweetReceived, eventArgs); }