Inheritance: TwitterStream, IUserStream
Ejemplo n.º 1
0
        private void ConnectUserStreams()
        {
            // All tweets to the HomeTimeLine
            UserStream.Tweets.Subscribe(AddToHomeTimeLine);

            // MAGIC HAPPENS HERE
            // there is no specific "catch" for mentions in the Userstream, but here we can fake it!
            // Using LINQ, we can ask RX to show us incoming tweets that contain the screen name of the current user
            // then push this into the "Mentions" Observable
            UserStream.Tweets.Where(t => t.Text.ToLower().Contains(TwitterCredentials.ScreenName.ToLower())).Subscribe(_mentions.OnNext);

            // specifically grab the Retweets in the timeline and show them
            // obviously this can be added at a higher level, too.
            UserStream.Tweets.Where(t => t.RetweetedStatus != null).Subscribe(_retweetsOnTimeline.OnNext);

            // Treat Direct Messages separately
            UserStream.DirectMessages.Subscribe(_directmessages.OnNext);

            // Pull out my tweets, and publish separately
            UserStream.Tweets.Where(t => t.User.UserId == TwitterCredentials.UserID).Subscribe(_mytweets.OnNext);

            // also grab the delete events and publish
            UserStream.DeleteEvents.Subscribe(de => _streamdeleteevent.OnNext(de.DeleteEventStatus));

            UserStream.Start();
            _userStreamConnected.OnNext(StreamSignal.Started);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Start UserStreaming
        /// </summary>
        public void StartUserStreaming()
        {
            UserStream = UserSession.UserStreamBuilder();

            // Separate stream events start
            ConnectStreamEvents();

            ConnectUserStreams();

            // MORE MAGIC HAPPENS HERE
            // The Userstreams only get tweets/direct messages from the point the connection is opened.
            // Historical tweets/direct messages have to be gathered using the traditional paging/cursoring APIs
            // (Request/Response REST).
            // but the higher level client doesnt want to worry about all that complexity.
            // in the BackfillPump, we gather these tweets/direct messages and pump them into the correct Observable
            Task.Factory.StartNew(ProcessBackfillPump);

            // If the UserStream disconnects, the userStreamConnected will fire & we'll reconnect
            // TODO if stream connection doesnt connect, fail over to UserStream.UserStreamActive.Where(status => status.IsFalse()).Subscribe(StartPollingUpdates);
            // TODO if cancellation requested externally, dont reconnect

            UserStream.StreamActive.Where(status => status == StreamSignal.Stopped).Subscribe(_ =>
            {
                UserStream.Start();
            });
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Stop UserStreaming
 /// </summary>
 public void StopUserStreaming()
 {
     UserStream.Stop();
     _userStreamConnected.OnNext(StreamSignal.Stopped);
 }