PrintTwitterErrors() public static method

public static PrintTwitterErrors ( TwitterControlMessage tcm ) : void
tcm BoxKite.Twitter.Models.TwitterControlMessage
return void
        public async Task <bool> DoTimelineTest(IUserSession session, List <int> testSeq)
        {
            var successStatus = true;

            try
            {
                // 1
                if (testSeq.Contains(1))
                {
                    ConsoleOutput.PrintMessage("7.1 Timeline\\GetMentions", ConsoleColor.Gray);
                    var timeline1 = await session.GetMentions(count : 100);

                    if (timeline1.OK)
                    {
                        foreach (var tweet in timeline1)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("From: {0} // Message: {1}", tweet.User.ScreenName, tweet.Text));
                        }
                    }
                    else
                    {
                        successStatus = false;
                    }
                }

                // 2
                if (testSeq.Contains(2))
                {
                    ConsoleOutput.PrintMessage("7.2 Timeline\\GetUserTimeline", ConsoleColor.Gray);
                    var timeline2 = await session.GetUserTimeline(screenName : "shiftkey", count : 20);

                    if (timeline2.OK)
                    {
                        foreach (var tweet in timeline2)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("From: {0} // Message: {1}", tweet.User.ScreenName, tweet.Text));
                        }
                    }
                    else
                    {
                        successStatus = false;
                    }
                }


                // 3
                if (testSeq.Contains(3))
                {
                    ConsoleOutput.PrintMessage("7.3 Timeline\\GetHomeTimeline", ConsoleColor.Gray);
                    var timeline3 = await session.GetHomeTimeline(count : 30);

                    if (timeline3.OK)
                    {
                        foreach (var tweet in timeline3)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("From: {0} // Message: {1}", tweet.User.ScreenName, tweet.Text));
                        }
                    }
                    else
                    {
                        successStatus = false;
                    }
                }


                // 4
                if (testSeq.Contains(4))
                {
                    ConsoleOutput.PrintMessage(
                        "7.4 Timeline\\GetHomeTimeline - Paging Forward, getting new tweets, with ID mechanism",
                        ConsoleColor.Gray);
                    var timeline4 = await session.GetHomeTimeline(count : 10);

                    long largestid  = 0;
                    long smallestid = 0;

                    if (timeline4.OK)
                    {
                        smallestid = timeline4.ToList()[0].Id;
                        foreach (var tweet in timeline4)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("ID: {0} // From: {1} // Message: {2}", tweet.Id, tweet.User.ScreenName,
                                              tweet.Text));
                            if (tweet.Id > largestid)
                            {
                                largestid = tweet.Id;
                            }
                            if (tweet.Id < smallestid)
                            {
                                smallestid = tweet.Id;
                            }
                        }
                        ConsoleOutput.PrintMessage(
                            String.Format(" LargestID: {0} // SmallestID: {1}", largestid, smallestid));

                        ConsoleOutput.PrintMessage("Waiting 20 seconds");
                        await Task.Delay(TimeSpan.FromSeconds(20));

                        ConsoleOutput.PrintMessage("Now Updating Home Timeline, should add newer messages");
                        var timeline41 = await session.GetHomeTimeline(sinceId : largestid, count : 10);

                        if (timeline41.OK)
                        {
                            foreach (var tweet in timeline41)
                            {
                                ConsoleOutput.PrintMessage(
                                    String.Format("ID: {0} // From: {1} // Message: {2}", tweet.Id,
                                                  tweet.User.ScreenName, tweet.Text));
                                if (tweet.Id > largestid)
                                {
                                    largestid = tweet.Id;
                                }
                                if (tweet.Id < smallestid)
                                {
                                    smallestid = tweet.Id;
                                }
                            }
                        }

                        ConsoleOutput.PrintMessage(
                            String.Format(" LargestID: {0} // SmallestID: {1}", largestid, smallestid));


                        ConsoleOutput.PrintMessage("Now Updating Home Timeline, should show older messages");
                        var timeline42 = await session.GetHomeTimeline(maxId : smallestid, count : 10);

                        if (timeline42.OK)
                        {
                            foreach (var tweet in timeline42)
                            {
                                ConsoleOutput.PrintMessage(
                                    String.Format("ID: {0} // From: {1} // Message: {2}", tweet.Id,
                                                  tweet.User.ScreenName, tweet.Text));
                                if (tweet.Id > largestid)
                                {
                                    largestid = tweet.Id;
                                }
                                if (tweet.Id < smallestid)
                                {
                                    smallestid = tweet.Id;
                                }
                            }
                        }

                        else
                        {
                            successStatus = false;
                        }
                    }
                }
                // 5
                if (testSeq.Contains(5))
                {
                    ConsoleOutput.PrintMessage("7.5 Timeline\\GetRetweetsOfMe", ConsoleColor.Gray);
                    var timeline5 = await session.GetRetweetsOfMe(count : 30);

                    if (timeline5.OK)
                    {
                        foreach (var tweet in timeline5)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("From: {0} // Message: {1}", tweet.User.ScreenName, tweet.Text));
                        }
                    }

                    else
                    {
                        successStatus = false;
                    }
                }


                // 6
                if (testSeq.Contains(6))
                {
                    ConsoleOutput.PrintMessage(
                        "7.6 Timeline\\GetHomeTimeline - Paging Backward, getting older tweets with ID mechanism",
                        ConsoleColor.Gray);

                    long smallestid   = 0;
                    long largestid    = 0;
                    int  howManyToGet = 100;
                    int  pagingSize   = 10;

                    do
                    {
                        var timeline6 = await session.GetHomeTimeline(count : pagingSize, maxId : smallestid);

                        if (timeline6.OK)
                        {
                            smallestid = timeline6.ToList()[0].Id; // grab the first for comparator
                            foreach (var tweet in timeline6)
                            {
                                ConsoleOutput.PrintMessage(
                                    String.Format("ID: {0} // From: {1} // Message: {2}", tweet.Id,
                                                  tweet.User.ScreenName,
                                                  tweet.Text));
                                if (tweet.Id < smallestid)
                                {
                                    smallestid = tweet.Id;
                                }
                                if (tweet.Id > largestid)
                                {
                                    largestid = tweet.Id;
                                }
                                howManyToGet--;
                            }
                            ConsoleOutput.PrintMessage(
                                String.Format("SmallestID: {0}", smallestid),
                                ConsoleColor.Cyan);
                        }
                        else
                        {
                            successStatus = false;
                            TwitterLiveFireUserAuth.PrintTwitterErrors(timeline6.twitterControlMessage);
                            break;
                        }
                    } while (howManyToGet > 0);
                }
            }
            catch (Exception e)
            {
                ConsoleOutput.PrintError(e.ToString());
                return(false);
            }
            return(successStatus);
        }
Esempio n. 2
0
        public async Task <bool> DoListsTest(IUserSession session, List <int> testSeq)
        {
            var successStatus = true;
            var twList        = new TwitterList();

            try
            {
                // 1
                if (testSeq.Contains(1))
                {
                    ConsoleOutput.PrintMessage("10.1 Lists\\GetLists", ConsoleColor.Gray);

                    var lists1 = await session.GetLists(screenName : "NickHodgeMSFT");

                    if (lists1.OK)
                    {
                        foreach (var lst in lists1)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("ID: {5} // Slug: {0} // Name: {1} // {2} // {3} // {4}", lst.Slug, lst.Name, lst.CreatedTime, lst.MemberCount, lst.Mode, lst.Id));
                            twList = lst;
                        }
                    }
                    else
                    {
                        TwitterLiveFireUserAuth.PrintTwitterErrors(lists1.twitterControlMessage);
                        successStatus = false;
                    }
                }

                // 2
                if (testSeq.Contains(2))
                {
                    ConsoleOutput.PrintMessage("10.2 Lists\\GetListTimeline", ConsoleColor.Gray);

                    var lists2 = await session.GetListTimeline(listId : twList.Id, slug : twList.Slug);

                    if (lists2.OK)
                    {
                        foreach (var tweet in lists2)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("From: {0} // Message: {1}", tweet.User.ScreenName, tweet.Text));
                        }
                    }
                    else
                    {
                        TwitterLiveFireUserAuth.PrintTwitterErrors(lists2.twitterControlMessage);
                        successStatus = false;
                    }
                }

                // 3
                if (testSeq.Contains(3))
                {
                    ConsoleOutput.PrintMessage("10.3 Lists\\GetMyListsUserIsMemberOf - Cursored", ConsoleColor.Gray);

                    long nextcursor = -1;
                    var  listCount  = 0;

                    do
                    {
                        var lists3 =
                            await session.GetMyListsUserIsMemberOf(screenName : "shiftkey", cursor : nextcursor);

                        if (lists3.twitterFaulted)
                        {
                            TwitterLiveFireUserAuth.PrintTwitterErrors(lists3.twitterControlMessage);
                            successStatus = false;
                            break;
                        }
                        nextcursor = lists3.next_cursor;
                        ConsoleOutput.PrintMessage(String.Format("Previous cursor: {0} Next cursor: {1}",
                                                                 lists3.previous_cursor, lists3.next_cursor), ConsoleColor.Magenta);
                        foreach (var lst in lists3.lists)
                        {
                            listCount++;
                            ConsoleOutput.PrintMessage(
                                String.Format("ID: {5} // Slug: {0} // Name: {1} // {2} // {3} // {4}", lst.Slug, lst.Name, lst.CreatedTime, lst.MemberCount, lst.Mode, lst.Id));
                        }
                    } while (nextcursor != 0);

                    ConsoleOutput.PrintMessage(String.Format("List Membership Count: {0}",
                                                             listCount));
                }


                // 4
                if (testSeq.Contains(4))
                {
                    ConsoleOutput.PrintMessage("10.4 Lists\\GetMembersOnList - Cursored", ConsoleColor.Gray);

                    long nextcursor = -1;

                    do
                    {
                        var lists4 =
                            await session.GetMembersOnList(listId : 52908745, slug : "autechheads", ownerId : 800364, ownerScreenName : "NickHodgeMSFT", cursor : nextcursor);

                        if (lists4.twitterFaulted)
                        {
                            successStatus = false;
                            TwitterLiveFireUserAuth.PrintTwitterErrors(lists4.twitterControlMessage);
                            break;
                        }
                        nextcursor = lists4.next_cursor;
                        ConsoleOutput.PrintMessage(String.Format("Previous cursor: {0} Next cursor: {1}",
                                                                 lists4.previous_cursor, lists4.next_cursor), ConsoleColor.Magenta);
                        foreach (var lusr in lists4.users)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("UserID: {0} // ScreenName: {1}", lusr.UserId, lusr.ScreenName));
                        }
                    } while (nextcursor != 0);
                }


                // 5
                if (testSeq.Contains(5))
                {
                    ConsoleOutput.PrintMessage("10.5 Lists\\IsUserOnList", ConsoleColor.Gray);
                    var testScreenName = "coatsy";
                    var lists5         =
                        await session.IsUserOnList(screenName : testScreenName, listId : 52908745, ownerId : 800364, ownerScreenName : "NickHodgeMSFT");

                    if (lists5.OK)
                    {
                        if (lists5.ScreenName == null)
                        {
                            ConsoleOutput.PrintMessage(String.Format("UserID: {0} is NOT ON the list", testScreenName));
                        }
                        else
                        {
                            ConsoleOutput.PrintMessage(String.Format("ScreenName: {0} is on the list", lists5.ScreenName));
                        }
                    }
                    else
                    {
                        TwitterLiveFireUserAuth.PrintTwitterErrors(lists5.twitterControlMessage);
                        successStatus = false;
                    }
                }

                // 6
                if (testSeq.Contains(6))
                {
                    ConsoleOutput.PrintMessage("10.6 Lists\\AddUserToMyList", ConsoleColor.Gray);
                    var testScreenName = "shiftkey";
                    var lists6         =
                        await session.AddUserToMyList(listId : 52908745, userIdToAdd : 14671135, screenNameToAdd : "shiftkey");

                    if (lists6.Status)
                    {
                        ConsoleOutput.PrintMessage(String.Format("ScreenName: {0} is added the list", testScreenName));
                    }
                }


                // 7
                if (testSeq.Contains(7))
                {
                    ConsoleOutput.PrintMessage("10.7 Lists\\DeleteUsersFromList", ConsoleColor.Gray);
                    var testScreenName  = "coatsy";
                    var testScreenNames = new List <string> {
                        testScreenName
                    };

                    var lists7 =
                        await session.DeleteUsersFromList(listId : 52908745, ownerId : 800364, ownerScreenName : "NickHodgeMSFT", screenNames : testScreenNames);

                    if (lists7.Status)
                    {
                        ConsoleOutput.PrintMessage(String.Format("ScreenName: {0} is added the list", testScreenName));
                    }
                    else
                    {
                        TwitterLiveFireUserAuth.PrintTwitterErrors(lists7.twitterControlMessage);
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleOutput.PrintError(e.ToString());
                return(false);
            }
            return(successStatus);
        }
        public async Task <bool> DoTweetTest(IUserSession session, List <int> testSeq)
        {
            var successStatus = true;

            try
            {
                // 1
                long tweetid = 0;
                if (testSeq.Contains(1))
                {
                    ConsoleOutput.PrintMessage("4.1 Tweets\\SendTweet", ConsoleColor.Gray);
                    var tweets1 = await session.SendTweet("Live Fire Test only, please ignore");

                    if (tweets1.OK)
                    {
                        tweetid = tweets1.Id;
                        ConsoleOutput.PrintMessage(
                            String.Format("From: {0} // Message: {1}", tweets1.User.ScreenName, tweets1.Text));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }

                var tweets2 = new Tweet();

                // 2
                if (testSeq.Contains(2))
                {
                    ConsoleOutput.PrintMessage("4.2 Tweets\\GetTweet", ConsoleColor.Gray);
                    tweets2 = await session.GetTweet(336377569098207233);

                    if (tweets2.OK)
                    {
                        ConsoleOutput.PrintMessage(
                            String.Format("From: {0} // Message: {1}", tweets2.User.ScreenName, tweets2.Text));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }

                // 3
                if (testSeq.Contains(3))
                {
                    ConsoleOutput.PrintMessage("4.3 Tweets\\GetRetweets", ConsoleColor.Gray);
                    var tweets3 = await session.GetRetweets(tweets2);

                    if (tweets3.OK)
                    {
                        foreach (var t in tweets3)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("From: {0} // Message: {1}", t.User.ScreenName, t.Text));
                        }
                    }
                    else
                    {
                        successStatus = false;
                    }
                }

                // 4
                if (testSeq.Contains(4))
                {
                    ConsoleOutput.PrintMessage("4.4 Tweets\\SendTweetWithImage", ConsoleColor.Gray);

                    var sr = FilesHelper.FromFile("sampleimage\\Boxkite-Logo-github.jpg");

                    using (var fs = new FileStream(sr, FileMode.Open, FileAccess.Read))
                    {
                        var tweets4 =
                            await
                            session.SendTweetWithImage("Live Fire Test only, please ignore", Path.GetFileName(sr), fs);

                        if (tweets4.OK)
                        {
                            tweetid = tweets4.Id;
                            ConsoleOutput.PrintMessage(
                                String.Format("From: {0} // Message: {1}", tweets4.User.ScreenName, tweets4.Text));
                        }
                        else
                        {
                            TwitterLiveFireUserAuth.PrintTwitterErrors(tweets4.twitterControlMessage);
                            successStatus = false;
                        }
                    }
                }

                // 5
                if (testSeq.Contains(5))
                {
                    ConsoleOutput.PrintMessage("4.5 Tweets\\GetTweet - with Extended Entities", ConsoleColor.Gray);
                    var tweets5 = await session.GetTweet(560049149836808192);

                    if (tweets5.OK)
                    {
                        ConsoleOutput.PrintMessage(
                            String.Format("From: {0} // Message: {1}", tweets5.User.ScreenName, tweets5.Text));
                        ConsoleOutput.PrintMessage(
                            String.Format("Extended Entities Count: {0}", tweets5.ExtendedEntities.Urls.Count()));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleOutput.PrintError(e.ToString());
                return(false);
            }
            return(successStatus);
        }