Example #1
0
        private static void SqlInsert(ITweet passed)
        {
            String comment = passed.ToString();
            String id      = passed.Id.ToString();

            foreach (String word in comment.Split(' '))
            {
                if (word.Length > 0 && word.Substring(0, 1) == "@")
                {
                    comment = comment.Replace(word, "@");
                }
            }

            try
            {
                using (var conn = new SqlConnection("Data Source=PHD-SERVER;Initial Catalog=RawComments;Integrated Security=False;User ID=sa;Password="******"InsertComment", conn)
                    {
                        CommandType = CommandType.StoredProcedure
                    })
                    {
                        command.Parameters.Add(new SqlParameter("@Id", id));
                        command.Parameters.Add(new SqlParameter("@Comment", comment));
                        command.Parameters.Add(new SqlParameter("@likeCount", passed.FavouriteCount));
                        command.Parameters.Add(new SqlParameter("@Source", "Twitter"));
                        conn.Open();

                        Int32 rdr = command.ExecuteNonQuery();
                    }
            }
            catch (Exception)
            { }
        }
        public async Task FilteredStream()
        {
            if (!EndToEndTestConfig.ShouldRunEndToEndTests)
            {
                return;
            }

            var stream = _tweetinviTestClient.Streams.CreateFilteredStream();

            stream.AddTrack("twitter");

            ITweet tweet = null;
            StreamStoppedEventArgs streamStoppedEventArgs = null;

            stream.MatchingTweetReceived += (sender, args) =>
            {
                tweet = args.Tweet;
                _logger.WriteLine($"Tweet matched via {args.MatchOn.ToString()}");
                _logger.WriteLine(tweet.ToString());
                stream.Stop();
            };

            stream.EventReceived += (sender, args) => { _logger.WriteLine(args.Json); };
            stream.StreamStopped += (sender, args) => { streamStoppedEventArgs = args; };

            var runStreamTask = Task.Run(async() =>
            {
                _logger.WriteLine("Before starting stream");
                await stream.StartMatchingAllConditionsAsync();
                _logger.WriteLine("Stream completed");
            });

            var delayTask = Task.Delay(TimeSpan.FromSeconds(15));

            var task = await Task.WhenAny(runStreamTask, delayTask);

            if (task != runStreamTask)
            {
                throw new TimeoutException();
            }

            _logger.WriteLine(streamStoppedEventArgs.Exception?.ToString() ?? "No exception");
            _logger.WriteLine(streamStoppedEventArgs.DisconnectMessage?.ToString() ?? "No disconnect message");

            Assert.Null(streamStoppedEventArgs.Exception);
            Assert.Null(streamStoppedEventArgs.DisconnectMessage);
            Assert.NotNull(tweet);

            await Task.Delay(TimeSpan.FromSeconds(10)); // this is for preventing Enhance Your Calm message from Twitter
        }
        public async Task TweetStream()
        {
            if (!EndToEndTestConfig.ShouldRunEndToEndTests)
            {
                return;
            }

            var stream = _tweetinviTestClient.Streams.CreateTweetStream();

            ITweet tweet = null;
            StreamStoppedEventArgs streamStoppedEventArgs = null;

            stream.TweetReceived += (sender, args) =>
            {
                tweet = args.Tweet;
                _logger.WriteLine(tweet.ToString());
                stream.Stop();
            };

            stream.EventReceived += (sender, args) => { _logger.WriteLine(args.Json); };
            stream.StreamStopped += (sender, args) => { streamStoppedEventArgs = args; };

            var runStreamTask = Task.Run(async() =>
            {
                _logger.WriteLine("Before starting stream");
                await stream.StartAsync("https://stream.twitter.com/1.1/statuses/sample.json");
                _logger.WriteLine("Stream completed");
            });

            var delayTask = Task.Delay(TimeSpan.FromSeconds(15));

            var task = await Task.WhenAny(runStreamTask, delayTask);

            if (task != runStreamTask)
            {
                throw new TimeoutException();
            }

            _logger.WriteLine(streamStoppedEventArgs.Exception?.ToString() ?? "No exception");
            _logger.WriteLine(streamStoppedEventArgs.DisconnectMessage?.ToString() ?? "No disconnect message");

            Assert.Null(streamStoppedEventArgs.Exception);
            Assert.Null(streamStoppedEventArgs.DisconnectMessage);
            Assert.NotNull(tweet);

            await Task.Delay(4000); // this is for preventing Enhance Your Calm message from Twitter
        }