Ejemplo n.º 1
0
 static void streamReader_OnActivityReceived(object sender, Activity activity)
 {
     Console.WriteLine("message received: " + streamReader.ActivityCount() + " id: " + activity.id);
     if (activity.twitter_entities.media != null)
     {
         Console.WriteLine(" Media:" + activity.twitter_entities.media[0].expanded_url);
     }
 }
Ejemplo n.º 2
0
        private void activityStream_Received(object sender, Activity activity)
        {
            // Debug.WriteLine(activity.body);
            var newRow = dsStream.Tables["Stream"].NewRow();

            foreach (var fieldName in from DataGridViewColumn column in dgvStream.Columns select column.Tag.ToString())
            {
                switch (fieldName)
                {
                    #region activity fields
                case "activity.id":
                {
                    newRow[fieldName] = activity.id;
                    break;
                }

                case "activity.verb":
                {
                    newRow[fieldName] = activity.verb;
                    break;
                }

                case "activity.link":
                {
                    newRow[fieldName] = activity.link;
                    break;
                }

                case "activity.body":
                {
                    newRow[fieldName] = activity.body;
                    break;
                }

                case "activity.postedTime":
                {
                    newRow[fieldName] = activity.postedTime.ToLocalTime();
                    break;
                }

                case "activity.favoritesCount":
                {
                    newRow[fieldName] = activity.favoritesCount;
                    break;
                }

                case "activity.twitter_filter_level":
                {
                    newRow[fieldName] = activity.twitter_filter_level;
                    break;
                }

                case "activity.twitter_lang":
                {
                    newRow[fieldName] = activity.twitter_lang;
                    break;
                }

                case "activity.object":
                {
                    newRow[fieldName] = activity.activityObject;
                    break;
                }

                    #endregion
                    #region actor fields
                case "actor.id":
                {
                    newRow[fieldName] = activity.actor.id;
                    break;
                }

                case "actor.link":
                {
                    newRow[fieldName] = activity.actor.link;
                    break;
                }

                case "actor.displayName":
                {
                    newRow[fieldName] = activity.actor.displayName;
                    break;
                }

                case "actor.postedTime":
                {
                    newRow[fieldName] = activity.actor.postedTime;
                    break;
                }

                case "actor.objectType":
                {
                    newRow[fieldName] = activity.actor.objectType;
                    break;
                }

                    #endregion
                    #region generator fields
                case "generator.displayName":
                {
                    newRow[fieldName] = activity.generator.displayName;
                    break;
                }

                case "generator.link":
                {
                    newRow[fieldName] = activity.generator.link;
                    break;
                }
                    #endregion
                    #region gnip fields

                case "gnip.matching_rules":
                {
                    newRow[fieldName] = activity.gnip.Matching_Rules();
                    break;
                }

                case "gnip.language":
                {
                    newRow[fieldName] = activity.gnip.language;
                    break;
                }

                case "gnip.klout_score":
                {
                    newRow[fieldName] = activity.gnip.klout_score;
                    break;
                }

                    #endregion
                    #region twitter entities
                case "twitter_entities.hashtags":
                {
                    newRow[fieldName] = activity.twitter_entities.Hashtags();
                    break;
                }

                case "twitter_entities.user_mentions":
                {
                    newRow[fieldName] = activity.twitter_entities.User_Mentions();
                    break;
                }

                case "twitter_entities.urls":
                {
                    newRow[fieldName] = activity.twitter_entities.Urls();
                    break;
                }
                    #endregion
                }
                // show number of tweets received
                Invoke((MethodInvoker) delegate { tsStatus.Text = activityStream.ActivityCount().ToString(); });
            }

            Invoke((MethodInvoker) delegate
            {
                dsStream.Tables["Stream"].Rows.Add(newRow);

                if (dsStream.Tables["Stream"].Rows.Count > ROWS)
                {
                    dsStream.Tables["Stream"].Rows[0].Delete();
                }

                dgvStream.Refresh(); // runs on UI thread
            });
        }