private async static Task StartListening(Tweetinvi.Streaming.V2.ISampleStreamV2 tweetStream) { tweetStream.TweetReceived += (sender, args) => { try { List <string> urls = new List <string>(); List <string> hashtags = new List <string>(); urls = args.Tweet.Entities?.Urls?.Select(u => u.UnwoundUrl).ToList(); hashtags = args.Tweet.Entities?.Hashtags?.Select(h => h.Tag).ToList(); TCC.Common.TweetSummary summary = new Common.TweetSummary(args.Tweet.Text, urls, hashtags); TweetQueue.Add(summary); tweetsReceived++; System.Console.WriteLine($"Tweets Received: {tweetsReceived}: Contains emojis? {summary.ContainsEmojis}"); if (cancelled) { System.Console.WriteLine("--HALTING WATCHER--"); tweetStream.StopStream(); return; } } catch (Exception ex) { System.Console.WriteLine($"Exception: {ex.Message}"); //throw; } }; await tweetStream.StartAsync(); }
/// <summary> /// Consumes the (sample) stream. /// </summary> /// <param name="sampleStream">The sample stream.</param> public async Task ConsumeStream(Tweetinvi.Streaming.V2.ISampleStreamV2 sampleStream) { // Consume the sample twitter stream ... while (true) { try { sampleStream.TweetReceived += (sender, args) => { var tweet = args.Tweet; if (tweet != null) { this.PersistTweet(tweet); } }; await sampleStream.StartAsync(); } catch (Exception e) { } } }