Example #1
0
        /////////////////////////////////////////////////////////////////////////////


        //////////////////////////////////////////////////////////////////////
        /// <summary>runs a test on the YouTube factory object</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void YouTubeRequestActivitiesTest()
        {
            Tracing.TraceMsg("Entering YouTubeRequestActivitiesTest");

            YouTubeRequestSettings settings = new YouTubeRequestSettings("NETUnittests", this.ytDevKey, this.ytUser, this.ytPwd);
            // settings.PageSize = 15;
            YouTubeRequest f = new YouTubeRequest(settings);

            // this returns the server default answer
            Feed <Activity> feed = f.GetActivities();

            foreach (Activity a in feed.Entries)
            {
                Assert.IsTrue(a.VideoId != null, "There should be a VideoId");
            }

            // now let's find all that happened in the last 24 hours

            DateTime t = DateTime.Now.AddDays(-1);

            // this returns the all activities for the last 24 hours  default answer
            try
            {
                Feed <Activity> yesterday = f.GetActivities(t);

                foreach (Activity a in yesterday.Entries)
                {
                    Assert.IsTrue(a.VideoId != null, "There should be a VideoId");
                }
            }
            catch (GDataNotModifiedException e)
            {
                Assert.IsTrue(e != null);
            }

            t = DateTime.Now.AddMinutes(-1);


            // this returns the all activities for the last 1 minute, should be empty or throw a not modified

            try
            {
                Feed <Activity> lastmin = f.GetActivities(t);
                int             iCount  = 0;

                foreach (Activity a in lastmin.Entries)
                {
                    iCount++;
                }
                Assert.IsTrue(iCount == 0, "There should be no activity for the last minute");
            }
            catch (GDataNotModifiedException e)
            {
                Assert.IsTrue(e != null);
            }
        }
Example #2
0
        public void YouTubeUserActivitiesTest()
        {
            Tracing.TraceMsg("Entering YouTubeUserActivitiesTest");

            YouTubeRequestSettings settings = new YouTubeRequestSettings("NETUnittests", this.ytDevKey);
            YouTubeRequest         f        = new YouTubeRequest(settings);

            List <string> users = new List <string>();

            users.Add("whiskeytonsils");
            users.Add("joelandberry");

            // this returns the server default answer
            Feed <Activity> feed = f.GetActivities(users);

            foreach (Activity a in feed.Entries)
            {
                VerifyActivity(a);
            }

            // now let's find all that happened in the last 24 hours

            DateTime t = DateTime.Now.AddDays(-1);

            // this returns the all activities for the last 24 hours
            try {
                Feed <Activity> yesterday = f.GetActivities(users, t);

                foreach (Activity a in yesterday.Entries)
                {
                    VerifyActivity(a);
                }
            } catch (GDataNotModifiedException e) {
                Assert.IsTrue(e != null);
            }

            t = DateTime.Now.AddMinutes(-1);

            // this returns all activities for the last 1 minute, should be empty or throw a not modified

            try {
                Feed <Activity> lastmin = f.GetActivities(users, t);
                int             iCount  = 0;

                foreach (Activity a in lastmin.Entries)
                {
                    iCount++;
                }
                Assert.IsTrue(iCount == 0, "There should be no activity for the last minute");
            } catch (GDataNotModifiedException e) {
                Assert.IsTrue(e != null);
            }
        }
Example #3
0
        private void UpdateActivities()
        {

            this.refreshTimer.Enabled = false;

            DateTime since = DateTime.MinValue;

            if (this.allActivities.Count == 0)
            {
                // first call, do a modified-since query
                since = DateTime.Now.AddHours(-1 * this.initialPullinHours);
            
            }


            int iCounter = 0;
            this.nIcon.BalloonTipText = "";
          
            List<string> users = GetUserNames();

            if (users.Count > 0 && String.IsNullOrEmpty(users[0]) != true)
            {

                // let's see if we get a valid authtoken back for the passed in credentials....
                YouTubeRequestSettings settings = new YouTubeRequestSettings("YouTubeNotifier",
                                    YTCLIENTID,
                                    YTDEVKEY);
                // settings.PageSize = 15;
                YouTubeRequest r = new YouTubeRequest(settings);
                Feed<Activity> pf = r.GetActivities(users, since);
                iCounter += ProcessFeed(pf, since); 
            }



            if (this.authToken != null)
            {
                Feed<Activity> f = this.ytRequest.GetActivities(since);

                iCounter += ProcessFeed(f, since);
            }


            // now redo the layout in the right order of controls:
            this.linkList.SuspendLayout();
            this.linkList.Controls.Clear();
            foreach (Activity act in this.allActivities)
            {
                LinkLabel l = new LinkLabel();
                string when = act.Updated.ToShortDateString();

                if (act.Updated.Date == DateTime.Now.Date)
                {
                    // it happened today
                    when = act.Updated.ToShortTimeString();
                }

                if (act.Updated.Date == DateTime.Now.AddDays(-1).Date)
                {
                    when = "yesterday, at " + act.Updated.ToShortTimeString();
                }

                l.Text = act.Author + " has ";

                bool noLink = false;
                int len = 5; 
                switch (act.Type)
                {
                    case ActivityType.Commented:
                        l.Text += "commented on ";
                        len = AddVideoText(l, act.VideoId);
                        break;
                    case ActivityType.Favorited:
                        l.Text += "favorited ";
                        len = AddVideoText(l, act.VideoId);
                        break;

                    case ActivityType.FriendAdded:
                        l.Text += "added a friend - " + act.Username ;
                        noLink = true;
                        break;
                    case ActivityType.Rated:
                        l.Text += "rated ";
                        len = AddVideoText(l, act.VideoId);
                        break;
                    case ActivityType.Shared:
                        l.Text += "shared ";
                        len = AddVideoText(l, act.VideoId);
                        break;
                    case ActivityType.SubscriptionAdded:
                        l.Text += "subscriped to " + act.Username;
                        noLink = true;
                        break;
                    case ActivityType.Uploaded:
                        l.Text += "uploaded ";
                        len = AddVideoText(l, act.VideoId);
                        break;
                }

                l.AutoSize = true;
                if (noLink == false)
                {
                    l.Links[0].Start = l.Text.Length - len;
                    l.Links[0].Length = len;
                    l.Links[0].LinkData = YouTubeQuery.CreateVideoWatchUri(act.VideoId);
                    l.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.Label_LinkClicked);
                }
                else
                {
                    // create a link for the user
                    l.Links[0].Start = l.Text.Length - act.Username.Length;
                    l.Links[0].Length = act.Username.Length;
                    l.Links[0].LinkData = "http://www.youtube.com/user/" + act.Username;
                    l.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.Label_LinkClicked);

                }
                l.Text += " (" + when + ")";

                this.linkList.Controls.Add(l);

            }
            this.linkList.ResumeLayout();

            if (iCounter > 0)
            {
                this.nIcon.BalloonTipTitle = "YouTube activities for " + this.userName.Text + " friends";
                this.nIcon.ShowBalloonTip(this.notificationDuration * 1000);
            }
            UpdateTitle();
            this.refreshTimer.Enabled = true;
            this.lastUpdate = DateTime.Now;
        }
        private void UpdateActivities()
        {
            this.refreshTimer.Enabled = false;

            DateTime since = DateTime.MinValue;

            if (this.allActivities.Count == 0)
            {
                // first call, do a modified-since query
                since = DateTime.Now.AddHours(-1 * this.initialPullinHours);
            }


            int iCounter = 0;

            this.nIcon.BalloonTipText = "";

            List <string> users = GetUserNames();

            if (users.Count > 0 && String.IsNullOrEmpty(users[0]) != true)
            {
                // let's see if we get a valid authtoken back for the passed in credentials....
                YouTubeRequestSettings settings = new YouTubeRequestSettings("YouTubeNotifier",
                                                                             YTDEVKEY);
                // settings.PageSize = 15;
                YouTubeRequest  r  = new YouTubeRequest(settings);
                Feed <Activity> pf = r.GetActivities(users, since);
                iCounter += ProcessFeed(pf, since);
            }



            if (this.authToken != null)
            {
                Feed <Activity> f = this.ytRequest.GetActivities(since);

                iCounter += ProcessFeed(f, since);
            }


            // now redo the layout in the right order of controls:
            this.linkList.SuspendLayout();
            this.linkList.Controls.Clear();
            foreach (Activity act in this.allActivities)
            {
                LinkLabel l    = new LinkLabel();
                string    when = act.Updated.ToShortDateString();

                if (act.Updated.Date == DateTime.Now.Date)
                {
                    // it happened today
                    when = act.Updated.ToShortTimeString();
                }

                if (act.Updated.Date == DateTime.Now.AddDays(-1).Date)
                {
                    when = "yesterday, at " + act.Updated.ToShortTimeString();
                }

                l.Text = act.Author + " has ";

                bool noLink = false;
                int  len    = 5;
                switch (act.Type)
                {
                case ActivityType.Commented:
                    l.Text += "commented on ";
                    len     = AddVideoText(l, act.VideoId);
                    break;

                case ActivityType.Favorited:
                    l.Text += "favorited ";
                    len     = AddVideoText(l, act.VideoId);
                    break;

                case ActivityType.FriendAdded:
                    l.Text += "added a friend - " + act.Username;
                    noLink  = true;
                    break;

                case ActivityType.Rated:
                    l.Text += "rated ";
                    len     = AddVideoText(l, act.VideoId);
                    break;

                case ActivityType.Shared:
                    l.Text += "shared ";
                    len     = AddVideoText(l, act.VideoId);
                    break;

                case ActivityType.SubscriptionAdded:
                    l.Text += "subscriped to " + act.Username;
                    noLink  = true;
                    break;

                case ActivityType.Uploaded:
                    l.Text += "uploaded ";
                    len     = AddVideoText(l, act.VideoId);
                    break;
                }

                l.AutoSize = true;
                if (noLink == false)
                {
                    l.Links[0].Start    = l.Text.Length - len;
                    l.Links[0].Length   = len;
                    l.Links[0].LinkData = YouTubeQuery.CreateVideoWatchUri(act.VideoId);
                    l.LinkClicked      += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.Label_LinkClicked);
                }
                else
                {
                    // create a link for the user
                    l.Links[0].Start    = l.Text.Length - act.Username.Length;
                    l.Links[0].Length   = act.Username.Length;
                    l.Links[0].LinkData = "http://www.youtube.com/user/" + act.Username;
                    l.LinkClicked      += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.Label_LinkClicked);
                }
                l.Text += " (" + when + ")";

                this.linkList.Controls.Add(l);
            }
            this.linkList.ResumeLayout();

            if (iCounter > 0)
            {
                this.nIcon.BalloonTipTitle = "YouTube activities for " + this.userName.Text + " friends";
                this.nIcon.ShowBalloonTip(this.notificationDuration * 1000);
            }
            UpdateTitle();
            this.refreshTimer.Enabled = true;
            this.lastUpdate           = DateTime.Now;
        }
        public void YouTubeUserActivitiesTest()
        {
            Tracing.TraceMsg("Entering YouTubeUserActivitiesTest");

            YouTubeRequestSettings settings = new YouTubeRequestSettings("NETUnittests", this.ytClient, this.ytDevKey);
            // settings.PageSize = 15;
            YouTubeRequest f = new YouTubeRequest(settings);

            List<string> users = new List<string>();

            users.Add("whiskeytonsils");
            users.Add("joelandberry");

            // this returns the server default answer
            Feed<Activity> feed = f.GetActivities(users);

            foreach (Activity a in feed.Entries)
            {
                VerifyActivity(a);
            }

            // now let's find all that happened in the last 24 hours

            DateTime t = DateTime.Now.AddDays(-1);

            // this returns the all activities for the last 24 hours  default answer
            try
            {
                Feed<Activity> yesterday = f.GetActivities(users, t);

                foreach (Activity a in yesterday.Entries)
                {
                    VerifyActivity(a);
                }
            }
            catch (GDataNotModifiedException e)
            {
                Assert.IsTrue(e != null);
            }

            t = DateTime.Now.AddMinutes(-1);


            // this returns the all activities for the last 1 minute, should be empty or throw a not modified

            try
            {

                Feed<Activity> lastmin = f.GetActivities(users, t);
                int iCount = 0;

                foreach (Activity a in lastmin.Entries)
                {
                    iCount++;
                }
                Assert.IsTrue(iCount == 0, "There should be no activity for the last minute");
            }
            catch (GDataNotModifiedException e)
            {
                Assert.IsTrue(e != null);
            }
        }
        public void YouTubeRequestActivitiesTest() {
            Tracing.TraceMsg("Entering YouTubeRequestActivitiesTest");

            YouTubeRequestSettings settings = new YouTubeRequestSettings("NETUnittests", this.ytDevKey, this.ytUser, this.ytPwd);
            YouTubeRequest f = new YouTubeRequest(settings);

            // this returns the server default answer
            Feed<Activity> feed = f.GetActivities();

            foreach (Activity a in feed.Entries) {
                Assert.IsTrue(a.VideoId != null, "There should be a VideoId");
            }

            // now let's find all that happened in the last 24 hours

            DateTime t = DateTime.Now.AddDays(-1);

            // this returns the all activities for the last 24 hours
            try {
                Feed<Activity> yesterday = f.GetActivities(t);

                foreach (Activity a in yesterday.Entries) {
                    Assert.IsTrue(a.VideoId != null, "There should be a VideoId");
                }
            } catch (GDataNotModifiedException e) {
                Assert.IsTrue(e != null);
            }

            t = DateTime.Now.AddMinutes(-1);

            // this returns the all activities for the last 1 minute, should be empty or throw a not modified

            try {
                Feed<Activity> lastmin = f.GetActivities(t);
                int iCount = 0;

                foreach (Activity a in lastmin.Entries) {
                    iCount++;
                }

                Assert.IsTrue(iCount == 0, "There should be no activity for the last minute");
            } catch (GDataNotModifiedException e) {
                Assert.IsTrue(e != null);
            }
        }