示例#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));
        }
        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");
        }
示例#3
0
 private void toolStripDropDownButton2_Click(object sender, EventArgs e)
 {
     toolStripStatusLabel1.Text = "Restarting...";
     ts.EndStream();
     timeline.Clear();
     if (st == 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(ts.Tokens);
         try
         {
             foreach (var tss in tt.ResponseObject)
             {
                 timeline.Add(tss);
             }
             toolStripStatusLabel1.Text = "Restarted.";
         }
         catch
         {
             MessageBox.Show(tt.ErrorMessage);
         }
     }
     else if (st == 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
                     }
                 });
             }
             toolStripStatusLabel1.Text = "Restarted.";
         }
         catch
         {
             MessageBox.Show(tt.ErrorMessage);
         }
     }
     else if (st == 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(ts.Tokens);
         try
         {
             foreach (var tss in tt.ResponseObject)
             {
                 timeline.Add(tss);
             }
             toolStripStatusLabel1.Text = "Restarted.";
         }
         catch
         {
             MessageBox.Show(tt.ErrorMessage);
         }
     }
     ShowF();
 }
示例#4
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();
 }