Ejemplo n.º 1
0
        public override void SetupEvent()
        {
            TwitterConnector twitterConnector = this.InParameters["twitter"].GetValue() as TwitterConnector;

            this.stream = twitterConnector.Client.Streams.CreateFilteredStream();
            stream.MatchingTweetReceived += Stream_MatchingTweetReceived;

            var twitterUser = twitterConnector.Client.Users.GetUserAsync(this.InParameters["user"].GetValue().ToString());

            twitterUser.Wait();
            stream.AddFollow(twitterUser.Result);

            stream.StartMatchingAllConditionsAsync();
        }
Ejemplo n.º 2
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            var consumerKey    = Environment.GetEnvironmentVariable("TwitterConsumerKey");
            var consumerSecret = Environment.GetEnvironmentVariable("TwitterConsumerSecret");
            var accessKey      = Environment.GetEnvironmentVariable("TwitterAccessKey");
            var accessSecret   = Environment.GetEnvironmentVariable("TwitterAccessSecret");

            var userClient = new TwitterClient(consumerKey, consumerSecret, accessKey, accessSecret);

            _filteredStream = userClient.Streams.CreateFilteredStream();

            if (!string.IsNullOrEmpty(_attribute.Filter))
            {
                _filteredStream.AddTrack(_attribute.Filter);
            }

            if (!string.IsNullOrWhiteSpace(_attribute.User))
            {
                var user = await userClient.Users.GetUserAsync(_attribute.User);

                _filteredStream.AddFollow(user);
            }

            _filteredStream.MatchingTweetReceived += async(obj, tweetEvent) =>
            {
                var triggerData = new TriggeredFunctionData
                {
                    TriggerValue = tweetEvent
                };
                await Executor.TryExecuteAsync(triggerData, CancellationToken.None);
            };

            _filteredStream.DisconnectMessageReceived += (obj, disconnectEvent) =>
            {
                _filteredStream.Stop();
            };

            await _filteredStream.StartMatchingAllConditionsAsync();
        }