Inheritance: TwitterStream, ISearchStream
コード例 #1
0
        public static ISearchStream StartSearchStream(this IUserSession session, IEnumerable<string> track = null, IEnumerable<string> follow = null, IEnumerable<string> locations = null)
        {
            var searchStream = new SearchStream();
            searchStream.SearchParameters = searchStream.ChangeSearchParameters(track, follow, locations);
            Func<Task<HttpResponseMessage>> startConnection = () =>
            {
                if (searchStream.SearchParameters.EnsureOneOf(new[] { "track", "follow", "locations" }).IsFalse())
                    return null;
                var request = session.CreatePost(TwitterApi.SearchStreaming("/1.1/statuses/filter.json"),
                    searchStream.SearchParameters);
                var c = new HttpClient() { Timeout = TimeSpan.FromDays(1) };
                return c.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, searchStream.CancelStream.Token);

            };
            searchStream.CreateOpenConnection = startConnection;
            return searchStream;
        }
コード例 #2
0
 /// <summary>
 /// Start a SearchStream
 /// </summary>
 /// <param name="textToSearch">text string to begin search</param>
 public void StartSearchStreaming(string textToSearch)
 {
     _twitterSearchCommunicationToken = new CancellationTokenSource();
     // when the searchstream gets disconnected, revert to polling (REST) searches
     _searchStreamDisconnected.Where(status => status.Equals(true)).Subscribe(StartPollingSearch);
     _currentSearchText = textToSearch;
     //
     if (UserSession.IsActive)
     {
         SearchStream = UserSession.StartSearchStream(track: textToSearch);
         SearchStream.FoundTweets.Subscribe(_searchtimeline.OnNext);
         SearchStream.Start();
         SearchStream.StreamActive.Subscribe(t => ManageSearchStreamDisconnect());
     }
     else
     {
         // cannot get usersession, fall back
         _searchStreamDisconnected.OnNext(true);
     }
     // and get "backfills"; tweets that pre-date the current stream/polling connection
     Task.Factory.StartNew(ProcessSearchBackFill_Pump);
 }
コード例 #3
0
        public static ISearchStream StartSearchStream(this IUserSession session, IEnumerable <string> track = null, IEnumerable <string> follow = null, IEnumerable <string> locations = null)
        {
            var searchStream = new SearchStream();

            searchStream.SearchParameters = searchStream.ChangeSearchParameters(track, follow, locations);
            Func <Task <HttpResponseMessage> > startConnection = () =>
            {
                if (searchStream.SearchParameters.EnsureOneOf(new[] { "track", "follow", "locations" }).IsFalse())
                {
                    return(null);
                }
                var request = session.CreatePost(TwitterApi.SearchStreaming("/1.1/statuses/filter.json"),
                                                 searchStream.SearchParameters);
                var c = new HttpClient()
                {
                    Timeout = TimeSpan.FromDays(1)
                };
                return(c.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, searchStream.CancelStream.Token));
            };

            searchStream.CreateOpenConnection = startConnection;
            return(searchStream);
        }
コード例 #4
0
 /// <summary>
 /// Stop SearchStreaming
 /// </summary>
 public void StopSearchStreaming()
 {
     _twitterSearchCommunicationToken.Cancel();
     SearchStream.Stop();
 }