Exemplo n.º 1
0
        public TwitterSearchStream(TwitterProtocolManager protocolManager,
                                   GroupChatModel chat, string keyword,
                                   OAuthTokens tokens, WebProxy proxy)
        {
            if (protocolManager == null) {
                throw new ArgumentNullException("protocolManager");
            }
            if (chat == null) {
                throw new ArgumentNullException("chat");
            }
            if (keyword == null) {
                throw new ArgumentNullException("keyword");
            }
            if (tokens == null) {
                throw new ArgumentNullException("tokens");
            }

            ProtocolManager = protocolManager;
            Session = protocolManager.Session;
            Chat = chat;

            var options = new StreamOptions();
            options.Track.Add(keyword);

            Stream = new TwitterStream(tokens, null, options);
            Stream.Proxy = proxy;
            Stream.StartPublicStream(OnStreamStopped, OnStatusCreated, OnStatusDeleted, OnEvent);

            MessageRateLimiter = new RateLimiter(5, TimeSpan.FromSeconds(5));
        }
Exemplo n.º 2
0
        public void StartCaptureStreaming(string searchkey)
        {
            StreamOptions options = new StreamOptions();
            options.Track.Add(searchkey);

            _stream = new TwitterStream(tokens, "TwitterSky", options);

            _stream.StartPublicStream(
                StreamStopped,
                NewTweet,
                DeletedTweet,
                OtherEvent
            );
        }
        public void StartCaptureStreaming(SearchParameters parameters)
        {
            StreamOptions options = new StreamOptions();
            options.Track.Add(parameters.SearchKey);
            this._stopSearch = false;

            TwitterStream stream = new TwitterStream(tokens, "RTSearch (Dev)", options);

            IAsyncResult result = stream.StartPublicStream(
                StreamStopped,
                NewTweet,
                DeletedTweet,
                OtherEvent
            );

            while (!this._stopSearch)
            {

            }

            stream.EndStream(StopReasons.StoppedByRequest, "Stop by user");
        }
Exemplo n.º 4
0
        public static void startStream(StreamOptions options)
        {
            Console.BufferWidth = 100;
            Console.WindowWidth = 100;

            TwitterStream stream = new TwitterStream(
                tokens,
                "UofCResearch",
                options);

            Console.WriteLine("stream 1 is starting ...");
            stream.StartPublicStream(
                StreamStopped,
                NewTweet,
                DeletedTweet,
                OtherEvent,
                RawJson);

            Console.WriteLine("stream 1 has started. Press any key to stop.");
            Console.ReadKey();

            Console.WriteLine("Stopping the stream ...");
            stream.EndStream();
        }
Exemplo n.º 5
0
 public Column(TwitterStream stream, StartType s, string title)
 {
     if (back != null)
     {
         listView1.BackgroundImage = back;
     }
     InitializeComponent();
     listView1.SmallImageList = new ImageList();
     ts = stream;
     if (s == StartType.UserStream)
     {
         ts.StartUserStream(null, new StreamStoppedCallback((x) => { toolStripStatusLabel1.Text = "Stopped."; }), new StatusCreatedCallback(x => { Add(x); }), null, null, null, new EventCallback(x => { Event(x); }), null);
         var tt = TwitterTimeline.HomeTimeline(stream.Tokens);
         try
         {
             foreach (var tss in tt.ResponseObject)
             {
                 timeline.Add(tss);
             }
         }
         catch
         {
             MessageBox.Show(tt.ErrorMessage);
         }
     }
     else if (s == StartType.FilterStream)
     {
         string query = "";
         if (ts.StreamOptions.Track.Count != 0)
         {
             foreach (string ss in ts.StreamOptions.Track)
             {
                 query += ss + "+AND+";
             }
             query = query.Remove(query.Length - 5, 5);
         }
         ts.StartPublicStream(new StreamStoppedCallback((x) => { toolStripStatusLabel1.Text = "Stopped."; }), new StatusCreatedCallback(x => { Add(x); }), null, new EventCallback(x => { Event(x); }));
         var tt = TwitterSearch.Search(ts.Tokens, query, new SearchOptions() { ResultType = SearchOptionsResultType.Popular });
         try
         {
             foreach (var tss in tt.ResponseObject)
             {
                 timeline.Add(new TwitterStatus() { Text = tss.Text, User = new TwitterUser() { ScreenName = tss.FromUserScreenName } });
             }
         }
         catch
         {
             MessageBox.Show(tt.ErrorMessage);
         }
     }
     else if (s == StartType.Mentions)
     {
         ts.StreamOptions.Track.Add("@" + ExtendedOAuthTokens.Tokens.First<ExtendedOAuthTokens>((x) => { return x.OAuthTokens == ts.Tokens; }).UserName);
         ts.StartPublicStream(new StreamStoppedCallback((x) => { toolStripStatusLabel1.Text = "Stopped."; }), new StatusCreatedCallback(x => { Add(x); }), null, new EventCallback(x => { Event(x); }));
         var tt = TwitterTimeline.Mentions(stream.Tokens);
         try
         {
             foreach (var tss in tt.ResponseObject)
             {
                 timeline.Add(tss);
             }
         }
         catch
         {
             MessageBox.Show(tt.ErrorMessage);
         }
     }
     st = s;
     this.Text = title;
     Columns.Add(this);
     ShowF();
 }
Exemplo n.º 6
0
        public void PublicStream(StreamOptions streamOptions, Action<TwitterStream> streamStarted,
			Action<StopReasons> streamErrorCallback,
			Action<TwitterStatus> statusCreatedCallback, Action<TwitterStreamDeletedEvent> statusDeletedCallback,
			Action<TwitterStreamEvent> eventCallback, Action<string> rawJsonCallback = null)
        {
            var stream = new TwitterStream(OAuthTokens, "MeetCurses", streamOptions);
            new Task(() => {
                stream.StartPublicStream((stopreason) => {
                    callbacks.Send(() => streamErrorCallback(stopreason));
                }, (status) => {
                    callbacks.Send(() => statusCreatedCallback(status));
                }, (status) => {
                    callbacks.Send(() => statusDeletedCallback(status));
                }, (twitterStreamEvent) => {
                    callbacks.Send(() => eventCallback(twitterStreamEvent));
                }, (rawJson) => {
                    callbacks.Send(() => {
                        if (rawJsonCallback != null) {
                            rawJsonCallback(rawJson);
                        }
                    });
                });
            }).Start(TaskScheduler);
        }