private static void StreamFilterExample(IToken token)
        {
            FilteredStream stream = new FilteredStream();

            // Adding Tracks filters
            stream.AddTrack("Tweetinvi Linvi");
            // stream.AddTrack("Linvi");

            stream.StartStream(token, x => ProcessTweet(x));
        }
        async void StartTwitterStream(IToken token)
        {
            var stream = new FilteredStream();

            CrawlingLog.Log.Info("Init TwitterUpdateStrategy with Hashtag '{0}'".FormatWith(HashtagTrigger));
            Log.Info("Init TwitterUpdateStrategy with Hashtag '{0}'".FormatWith(HashtagTrigger), this);

            stream.AddTrack(HashtagTrigger);

            stream.StreamStarted += (sender, args) => CrawlingLog.Log.Info("Twitter stream started");

            // The following call blocks
            stream.StartStream(token, x => HandleTweet(x));
        }
Beispiel #3
0
        async void StartTwitterStream(IToken token)
        {
            var stream = new FilteredStream();

            CrawlingLog.Log.Info("Init TwitterUpdateStrategy with Hashtag '{0}'".FormatWith(HashtagTrigger));
            Log.Info("Init TwitterUpdateStrategy with Hashtag '{0}'".FormatWith(HashtagTrigger), this);

            stream.AddTrack(HashtagTrigger);

            stream.StreamStarted += (sender, args) => CrawlingLog.Log.Info("Twitter stream started");

            // The following call blocks
            stream.StartStream(token, x => HandleTweet(x));
        }
Beispiel #4
0
        public static void SearchTwitterStreaming()
        {
            var token = new TwitterToken.Token(_accessToken, _accessTokenSecret, _consumerKey, _consumerSecret);

            // Create the stream
            var myStream = new FilteredStream();

            myStream.AddTrack("#apple");
            myStream.AddTrack("#google");
            myStream.AddTrack("#twitter");
            myStream.AddTrack("#tesla");
            myStream.AddTrack("#ford");
            myStream.AddTrack("#shell");
            myStream.AddTrack("#bks");


            // Starting the stream by specifying credentials thanks to the Token and a delegate specifying what you want to do when you receive a tweet
            using (var conn = new SqlCeConnection(_sqlConnection))
            {
                conn.Open();
                var insert = new SqlCeCommand("INSERT INTO Tweets(Text, UserFollowers, RetweetCount, CreatedAt) Values(@Text, @UserFollowers, @RetweetCount, @CreatedAt)", conn);
                try
                {
                    myStream.StartStream(token, tweet =>
                    {
                        insert.Parameters.Clear();
                        insert.Parameters.AddWithValue("@Text", tweet.Text);
                        insert.Parameters.AddWithValue("@UserFollowers", tweet.Creator.FollowersCount);
                        insert.Parameters.AddWithValue("@RetweetCount", tweet.RetweetCount);
                        insert.Parameters.AddWithValue("@CreatedAt", tweet.CreatedAt);
                        var status = insert.ExecuteNonQuery();
                        //Console.WriteLine("{0}: {1}", status, tweet.Text);
                    });
                }
                catch
                {
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Beispiel #5
0
        public void StartStreamTrackRandomUniqueWord()
        {
            // Arrange
            var  randomWord      = String.Format("Tweetinvi{0}", new Random().Next());
            var  expectedMessage = String.Format("Hello {0}", randomWord);
            bool result          = false;

            Thread t = new Thread(() =>
            {
                IFilteredStream stream = new FilteredStream();

                stream.AddTrack(randomWord);

                Func <ITweet, bool> listen = delegate(ITweet tweet)
                {
                    if (tweet != null)
                    {
                        result = tweet.Text == expectedMessage;
                    }

                    // End the stream
                    return(false);
                };

                stream.StartStream(TokenSingleton.Token, listen);
            });

            t.Start();

            // Act
            ITweet newTweet = new Tweet(expectedMessage, TokenTestSingleton.Instance);

            newTweet.Publish();

            Thread.Sleep(500);
            t.Join();

            // Assert
            Assert.AreEqual(result, true);

            // Cleanup
            newTweet.Destroy();
        }
Beispiel #6
0
        public void StartStreamTrackWord1ORWord2InTheSameTweet()
        {
            // Arrange
            var randomWord1 = String.Format("Tweetinvi{0}", new Random().Next());
            var randomWord2 = String.Format("Tweetinvi2{0}", new Random().Next());

            var expectedMessage1 = String.Format("Hello {0}", randomWord1);
            var expectedMessage2 = String.Format("Hello {0}", randomWord2);
            var expectedMessage3 = String.Format("Hello {0} {1}", randomWord1, randomWord2);

            int i = 0;

            Thread t = new Thread(() =>
            {
                IFilteredStream stream = new FilteredStream();

                stream.AddTrack(randomWord1);
                stream.AddTrack(randomWord2);

                Func <ITweet, bool> listen = delegate(ITweet tweet)
                {
                    if (tweet != null)
                    {
                        bool result = tweet.Text == expectedMessage1 ||
                                      tweet.Text == expectedMessage2 ||
                                      tweet.Text == expectedMessage3;

                        if (result)
                        {
                            Debug.WriteLine(tweet.Text);
                            ++i;
                        }
                    }

                    // End the stream
                    return(true);
                };

                Timer timer    = new Timer(5000);
                timer.Elapsed += (sender, args) =>
                {
                    timer.Stop();
                    stream.StopStream();
                };

                timer.Start();

                stream.StartStream(TokenSingleton.Token, listen);
            });

            t.Start();

            // Act
            ITweet newTweet1 = new Tweet(expectedMessage1, TokenTestSingleton.Instance);

            newTweet1.Publish();

            ITweet newTweet2 = new Tweet(expectedMessage2, TokenTestSingleton.Instance);

            newTweet2.Publish();

            ITweet newTweet3 = new Tweet(expectedMessage3, TokenTestSingleton.Instance);

            newTweet3.Publish();

            t.Join();

            // Cleanup
            newTweet1.Destroy();
            newTweet2.Destroy();
            newTweet3.Destroy();

            // Assert
            Assert.AreEqual(i, 3);
        }