/// <summary>
        /// Gets current user (defined by access token) home timeline
        /// </summary>
        /// <param name="messageCount">Message count</param>
        /// <returns>Message list</returns>
        public List <Message> GetUserHomeTimeLine(int messageCount)
        {
            try
            {
                Twitterizer.OAuthTokens tokens = GetOAuthTokens();

                Twitterizer.UserTimelineOptions options = new Twitterizer.UserTimelineOptions();
                options.Count           = messageCount;
                options.IncludeRetweets = true;

                TwitterResponse <TwitterStatusCollection> statusResponse = TwitterTimeline.HomeTimeline(tokens, options);

                if (statusResponse.Result == RequestResult.Success)
                {
                    return(MapMessage(statusResponse.ResponseObject));
                }

                else
                {
                    throw CreateException(statusResponse.Result, statusResponse.ErrorMessage);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw;
            }
        }
        /// <summary>
        /// Gets tweets posted by specified user
        /// </summary>
        /// <param name="messageCount">Message count</param>
        /// <returns>Message list</returns>
        public List <Message> GetUserTweets(decimal?userID, string screenName, int messageCount)
        {
            try
            {
                Twitterizer.OAuthTokens tokens = GetOAuthTokens();

                Twitterizer.UserTimelineOptions options = new Twitterizer.UserTimelineOptions();
                options.ScreenName = screenName;
                if (userID.HasValue)
                {
                    options.UserId = userID.Value;
                }
                options.IncludeRetweets = true;
                options.Count           = messageCount;

                TwitterResponse <TwitterStatusCollection> statusResponse = TwitterTimeline.UserTimeline(tokens, options);

                if (statusResponse.Result == RequestResult.Success)
                {
                    return(MapMessage(statusResponse.ResponseObject));
                }

                else
                {
                    throw CreateException(statusResponse.Result, statusResponse.ErrorMessage);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw;
            }
        }
示例#3
0
        public static ValueTask Execute(TwitterTimeline timeline)
        {
            ArgumentNullException.ThrowIfNull(timeline);

            if (timeline.Settings.Donated)
            {
                return(default);
        public static void Friends()
        {
            OAuthTokens tokens = Configuration.GetTokens();

#pragma warning disable 618
            TwitterResponse <TwitterStatusCollection> response = TwitterTimeline.FriendTimeline(tokens, new TimelineOptions {
                Count = 2
            });
#pragma warning restore 618

            Assert.IsNotNull(response);
            Assert.That(response.Result == RequestResult.Success);
            Assert.IsNotNull(response.ResponseObject);
            Assert.That(response.ResponseObject.Count > 0);

            decimal firstId = response.ResponseObject[0].Id;

#pragma warning disable 618
            response = TwitterTimeline.FriendTimeline(tokens, new TimelineOptions {
                Page = ++response.ResponseObject.Page
            });
#pragma warning restore 618
            Assert.IsNotNull(response);
            Assert.That(response.Result == RequestResult.Success);
            Assert.IsNotNull(response.ResponseObject);
            Assert.That(response.ResponseObject.Count > 0);
            Assert.AreNotEqual(response.ResponseObject[0].Id, firstId);
        }
示例#5
0
        public void Button1_Click(object sender, EventArgs e)
        {
            string Input  = TextBox1.Text;
            string method = Input.Split('(')[0];
            int    x      = Input.Length - 1 - (Input.IndexOf('(') + 1);
            string value  = Input.Substring(Input.IndexOf('(') + 1, x);

            UserTimelineOptions userOptions = new UserTimelineOptions();

            userOptions.APIBaseAddress = "https://api.twitter.com/1.1/";                                            // <-- needed for API 1.1
            userOptions.Count          = 5;
            userOptions.UseSSL         = true;                                                                      // <-- needed for API 1.1
            userOptions.ScreenName     = value;                                                                     //<-- replace with yours
            TwitterResponse <TwitterStatusCollection> timeline = TwitterTimeline.UserTimeline(tokens, userOptions); // collects first 20 tweets from our account
            int i = 1;
            //TwitterResponse<TwitterTrendCollection> timelineres = TwitterTrend.Trends(tokens,1);

            TwitterResponse <TwitterUser> followers = TwitterUser.Show(tokens, value);

            if (followers.Result == RequestResult.Success)
            {
                TextBox2.Text = "Number of followers for " + followers.ResponseObject.ScreenName + " is " + followers.ResponseObject.NumberOfFollowers + Environment.NewLine;
            }

            //if (showUserResponse.Result == RequestResult.Success)
            //    {
            //    string screenName = showUserResponse.ResponseObject.ScreenName;
            //    Response.Write(screenName);
            //    Response.Write("<br>");
            //    Response.Write(showUserResponse.ResponseObject.NumberOfFollowers);
            //    }
            //FollowersOptions options = new FollowersOptions();
            //options.ScreenName = value;
            //options.UserId = 212250358;
            //options.UseSSL = true;
            //TwitterResponse<TwitterUserCollection> Followernames = TwitterFriendship.Followers(tokens, options);
            //TwitterResponse<TwitterUserCollection> followers = TwitterFriendship.Followers(options);
            //foreach (var follower in followers.ResponseObject.)
            //{
            //    TextBox2.Text += i + ")" + follower + Environment.NewLine;
            //    i++;
            //}
            foreach (TwitterStatus status in timeline.ResponseObject)
            {
                TextBox2.Text += i + ")" + status.Text + Environment.NewLine;
                i++;
            }

            //Getting trends from a location
            LocalTrendsOptions trendoptions = new LocalTrendsOptions();

            trendoptions.UseSSL = true;


            //  TwitterResponse<TwitterTrendCollection> tr = TwitterTrend.Trends(1);
            //foreach (TwitterTrend tnds in tr.ResponseObject)
            //{
            //    TextBox2.Text += tnds.ToString() + Environment.NewLine;
            //}
        }
示例#6
0
        public void DisplayTweets(string value)
        {
            if (value != "")
            {
                UserTimelineOptions userOptions = new UserTimelineOptions();
                userOptions.APIBaseAddress = "https://api.twitter.com/1.1/";                                            // <-- needed for API 1.1
                userOptions.Count          = 20;
                userOptions.UseSSL         = true;                                                                      // <-- needed for API 1.1
                userOptions.ScreenName     = value;                                                                     //<-- replace with yours
                TwitterResponse <TwitterStatusCollection> timeline = TwitterTimeline.UserTimeline(tokens, userOptions); // collects first 20 tweets from our account
                int i = 1;

                foreach (TwitterStatus status in timeline.ResponseObject)
                {
                    TextBox2.Text += i + ")" + status.Text + Environment.NewLine;
                    i++;
                }

                TextBox2.Text += "-----------------------------------------------------------------------" + Environment.NewLine;
            }
            else
            {
                TextBox2.Text += "Invalid Screen Name";
            }
        }
示例#7
0
        //
        // GET: /Home/

        public string AjaxSaveToDB()
        {
            if (Session["LoggedASP"] != null)
            {
                TimelineOptions options = new TimelineOptions();

                options.Count           = 200;
                options.IncludeRetweets = true;

                OAuthTokens token = new OAuthTokens();
                token.ConsumerKey       = ConfigurationManager.AppSettings["consumerKey"];
                token.ConsumerSecret    = ConfigurationManager.AppSettings["consumerSecret"];
                token.AccessToken       = ((User)Session["LoggedUser"]).TwitterToken;
                token.AccessTokenSecret = ((User)Session["LoggedUser"]).TwitterTokenSecret;

                TwitterResponse <TwitterStatusCollection> truc = TwitterTimeline.HomeTimeline(token, options);

                TweetEntity tweetEntity = new TweetEntity();

                tweetEntity.RemoveTweetFromOwner(((User)Session["LoggedUser"]).ID);

                foreach (var item in truc.ResponseObject)
                {
                    //int lol = ;

                    tweetEntity.AddTweet(item.Id, item.Text, item.User.ScreenName, item.User.ProfileImageLocation, ((User)Session["LoggedUser"]).ID, ((int)((TimeSpan)(item.CreatedDate - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime())).TotalSeconds));
                }
                return("Success");
            }
            else
            {
                return("Fail");
            }
        }
示例#8
0
        private TwitterResponse <TwitterStatusCollection> GetTwitterStatus()
        {
            TwitterResponse <TwitterStatusCollection> userInfo = new TwitterResponse <TwitterStatusCollection>();

            //use cache here
            if (Page.Cache[string.Format("TweetWrite-{0}", this.ScreenName)] == null)
            {
                //create a authorization token of the user
                OAuthTokens tokens = new OAuthTokens();
                tokens.ConsumerKey       = this.ConsumerKey;
                tokens.ConsumerSecret    = this.ConsumerSecret;
                tokens.AccessToken       = this.AccessToken;
                tokens.AccessTokenSecret = this.AccessTokenSecret;

                //Set the query options

                UserTimelineOptions Useroptions = new UserTimelineOptions();
                Useroptions.ScreenName = this.ScreenName;

                //Get the account info
                userInfo = TwitterTimeline.UserTimeline(tokens, Useroptions);
                HttpContext.Current.Cache.Insert(string.Format("TweetWrite-{0}", this.ScreenName), userInfo, null, DateTime.Now.AddMinutes(Common.CACHEDURATION), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal, null);
            }
            else
            {
                userInfo = Page.Cache[string.Format("TweetWrite-{0}", this.ScreenName)] as TwitterResponse <TwitterStatusCollection>;
            }

            return(userInfo);
        }
示例#9
0
        public static ValueTask Execute(IEnumerable <TwitterStatus> statuses, TwitterTimeline timeline)
        {
            // Build a hashset for faster lookups.
            var statusesNoNags = timeline.StatusCollection.Where(status => status.Id.IsNotEqualTo(DonateNagStatus.DonateNagStatusId));
            var hashSet        = new HashSet <TwitterStatus>(statusesNoNags);

            foreach (var status in statuses.OrderBy(status => status.OriginatingStatus.CreatedDate))
            {
                if (hashSet.TryGetValue(status, out var statusToUpdate))
                {
                    statusToUpdate.UpdateFromStatus(status);
                }
                else if (!timeline.AlreadyAdded.Contains(status.Id))
                {
                    var clonedStatus = Clone(status);
                    timeline.AlreadyAdded.Add(clonedStatus.Id);
                    clonedStatus.UpdateAboutMeProperties(timeline.Settings.ScreenName);

                    if (timeline.IsScrolled)
                    {
                        timeline.PendingStatusCollection.Add(clonedStatus);
                        timeline.PendingStatusesAvailable = true;
                    }
                    else
                    {
                        timeline.StatusCollection.Insert(0, clonedStatus);
                    }
                }
            }

            return(default);
示例#10
0
        private async ValueTask GetAndUpdateStatusesAsync(TwitterTimeline timeline)
        {
            var mentions = await GetMentionsAsync().ConfigureAwait(true);

            var statuses = await TwitterService.GetHomeTimeline().ConfigureAwait(true);

            await UpdateStatuses.Execute(statuses.Concat(mentions), timeline).ConfigureAwait(true);
        }
        public static void RetweetedByMe()
        {
            OAuthTokens tokens = Configuration.GetTokens();

            TwitterResponse <TwitterStatusCollection> timelineResponse = TwitterTimeline.RetweetedByMe(tokens);

            PerformCommonTimelineTests(timelineResponse);
        }
示例#12
0
        public static ValueTask Execute(TwitterTimeline timeline)
        {
            foreach (var status in timeline.StatusCollection)
            {
                TwitterNamesService.Add(status.OriginatingStatus);
            }

            return(default);
示例#13
0
        public static ValueTask Execute(TwitterTimeline timeline)
        {
            foreach (var status in timeline.StatusCollection)
            {
                status.InvokeUpdateTimeStamp();
            }

            return(default);
示例#14
0
        void CheckAlert()
        {
            UserTimelineOptions userOptions = new UserTimelineOptions();

            userOptions.APIBaseAddress = "https://api.twitter.com/1.1/";
            userOptions.Count          = 10;
            userOptions.UseSSL         = true;
            userOptions.ScreenName     = "WarframeAlerts";
            TwitterResponse <TwitterStatusCollection> timeline = null;

            try
            {
                timeline = TwitterTimeline.UserTimeline(tokens, userOptions);
            }
            catch (Exception) { }

            if (timeline == null || timeline.Content == null)
            {
                if (status != ConnectionStatus.Issue)
                {
                    configWindow.Log("Having trouble reaching Twitter. Will retry every 60 seconds.");
                }
                status = ConnectionStatus.Issue;
                return;
            }

            if (status == ConnectionStatus.Connecting)
            {
                configWindow.Log("Connected. Scanning for alerts matching your filter...");
            }
            if (status == ConnectionStatus.Issue)
            {
                configWindow.Log("Reconnected.");
            }
            status = ConnectionStatus.Connected;

            for (int i = 9; i >= 0; i--)
            {
                dynamic  tweet     = JArray.Parse(timeline.Content)[i];
                string   createdAt = tweet.created_at;
                DateTime dt        = DateTime.ParseExact(createdAt, "ddd MMM dd HH:mm:ss \"+0000\" yyyy", CultureInfo.InvariantCulture).ToLocalTime();
                if (dt <= lastTweetTime)
                {
                    continue;
                }
                lastTweetTime = dt;
                string text = tweet.text;
                try
                {
                    NewAlert(text, dt);
                }
                catch (Exception e)
                {
                    configWindow.Log("Trouble parsing: " + text);
                    configWindow.Log(e.ToString());
                }
            }
        }
        public static void PublicTimeline()
        {
            TwitterStatusCollection timeline = TwitterTimeline.PublicTimeline().ResponseObject;

            Assert.IsNotNull(timeline);
            Assert.IsNotEmpty(timeline);

            Assert.That(timeline.Count > 0 && timeline.Count <= 20, "Timeline should contain between 0 and 20 items.");
        }
示例#16
0
        public void PublicTimeline()
        {
            var response = TwitterTimeline.PublicTimeline();

            Assert.IsNotNull(response.ResponseObject, response.ErrorMessage);
            Assert.AreNotEqual(0, response.ResponseObject.Count, response.ErrorMessage);

            Assert.IsTrue(response.ResponseObject.Count > 0 && response.ResponseObject.Count <= 20, "Timeline should contain between 0 and 20 items.");
        }
        public static void FriendTimeline()
        {
            OAuthTokens tokens = Configuration.GetTokens();

#pragma warning disable 618
            TwitterResponse <TwitterStatusCollection> timelineResponse = TwitterTimeline.FriendTimeline(tokens);
#pragma warning restore 618
            PerformCommonTimelineTests(timelineResponse);
        }
示例#18
0
        public static ValueTask Execute(TwitterTimeline timeline)
        {
            const int maxNumberOfStatuses = 500;

            while (timeline.StatusCollection.Count > maxNumberOfStatuses)
            {
                timeline.StatusCollection.RemoveAt(timeline.StatusCollection.Count - 1);
            }

            return(default);
示例#19
0
        public static ValueTask Execute(TwitterTimeline timeline)
        {
            if (timeline is null)
            {
                throw new System.ArgumentNullException(nameof(timeline));
            }

            if (timeline.Settings.Donated)
            {
                return(default);
示例#20
0
        public void TweetTimechart(string value)
        {
            if (value != "")
            {
                Chart1.Visible = true;
                UserTimelineOptions userOptions = new UserTimelineOptions();
                userOptions.APIBaseAddress = "https://api.twitter.com/1.1/";                                            // <-- needed for API 1.1
                userOptions.Count          = 20;
                userOptions.UseSSL         = true;                                                                      // <-- needed for API 1.1
                userOptions.ScreenName     = value;                                                                     //<-- replace with yours
                TwitterResponse <TwitterStatusCollection> timeline = TwitterTimeline.UserTimeline(tokens, userOptions); // collects first 20 tweets from our account
                int i = 1, Mrng = 0, Afternoon = 0, evening = 0, night = 0;
                int timeinhrs;

                foreach (TwitterStatus status in timeline.ResponseObject)
                {
                    //TextBox2.Text += i + ")" + status.CreatedDate + Environment.NewLine;
                    timeinhrs = status.CreatedDate.Hour;
                    if (timeinhrs > 0 && timeinhrs <= 5)
                    {
                        night++;
                    }
                    else if (timeinhrs > 5 && timeinhrs <= 12)
                    {
                        Mrng++;
                    }
                    else if (timeinhrs > 12 && timeinhrs <= 18)
                    {
                        Afternoon++;
                    }
                    else if (timeinhrs > 18 && timeinhrs <= 22)
                    {
                        evening++;
                    }
                    else if (timeinhrs > 22 && timeinhrs <= 24)
                    {
                        night++;
                    }

                    //i++;
                }

                Chart1.Series["Time"].Points.AddXY("Morning", Mrng);
                Chart1.Series["Time"].Points.AddXY("Afternoon", Afternoon);
                Chart1.Series["Time"].Points.AddXY("Evening", evening);
                Chart1.Series["Time"].Points.AddXY("Night", night);
            }
            else
            {
                TextBox2.Text += "Invalid Screen Name";
            }
        }
示例#21
0
        public static ValueTask Execute(TwitterTimeline timeline)
        {
            if (timeline is null)
            {
                throw new ArgumentNullException(nameof(timeline));
            }

            foreach (var status in timeline.StatusCollection)
            {
                status.InvokeUpdateTimeStamp();
            }

            return(default);
        public static ValueTask Execute(TwitterTimeline timeline)
        {
            if (timeline is null)
            {
                throw new System.ArgumentNullException(nameof(timeline));
            }

            const int maxNumberOfStatuses = 500;

            while (timeline.StatusCollection.Count > maxNumberOfStatuses)
            {
                timeline.StatusCollection.RemoveAt(timeline.StatusCollection.Count - 1);
            }

            return(default);
示例#23
0
        private void listboxTimeline_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListBox     list  = sender as ListBox;
            ListBoxItem twitt = list.SelectedItem as ListBoxItem;

            if (twitt != null)
            {
                UserTimelineOptions options = new UserTimelineOptions();
                //options.ScreenName = twitt.Name;
                options.UserId = decimal.Parse(twitt.Uid);
                TwitterResponse <TwitterStatusCollection> userTimeline = TwitterTimeline.UserTimeline(_authToken, options);
                showUserTimeline(userTimeline);
            }
            list.SelectedItem = null;
        }
        public async void MakeRequestForTwitterTimeline()
        {
            var credentials = TestSettings.GetToken <Twitter, OAuth1Credentials>();

            if (credentials.IsTokenExpired)
            {
                throw new Exception("Expired credentials!!!");
            }

            var request  = new TwitterTimeline();
            var response = await new OAuthRequester(credentials)
                           .MakeOAuthRequestAsync <TwitterTimeline, TwitterTimelineResponse>(request)
                           .ConfigureAwait(false);

            Assert.NotNull(response);
        }
示例#25
0
        public static ValueTask Execute(TwitterTimeline timeline)
        {
            const int maxNumberOfStatuses = 500;
            var       truncated           = timeline.StatusCollection.Count > maxNumberOfStatuses;

            while (timeline.StatusCollection.Count > maxNumberOfStatuses)
            {
                timeline.StatusCollection.RemoveAtNoNotify(timeline.StatusCollection.Count - 1);
            }

            if (truncated)
            {
                timeline.StatusCollection.NotifyCollectionChanged();
            }

            return(default);
        public static void SinceID()
        {
            OAuthTokens tokens = Configuration.GetTokens();

            TwitterResponse <TwitterStatusCollection> timelineResponse = TwitterTimeline.Mentions(tokens);

            PerformCommonTimelineTests(timelineResponse);

            decimal mostRecentId = timelineResponse.ResponseObject[0].Id;

            TwitterResponse <TwitterStatusCollection> timeline2 = TwitterTimeline.Mentions(tokens, new TimelineOptions
            {
                SinceStatusId = mostRecentId
            });

            PerformCommonTimelineTests(timeline2);
        }
        public List <Tweet> GetTweetsForUser(string user, decimal?sinceId)
        {
            try
            {
                UserTimelineOptions uto = new UserTimelineOptions();
                uto.Count           = 1000;
                uto.IncludeRetweets = true;
                uto.ScreenName      = user;
                if (sinceId == null)
                {
                    uto.SinceStatusId = 0;
                }
                else
                {
                    uto.SinceStatusId = sinceId.Value;
                }
                TwitterResponse <TwitterStatusCollection> twitterResponse = TwitterTimeline.UserTimeline(tokens, uto); // TwitterAccount.VerifyCredentials(tokens);
                List <Tweet> tweets = new List <Tweet>();

                if (twitterResponse.Result == RequestResult.Success)
                {
                    log.Info("Successfully retrieved results for user \"" + user + "\".");
                    foreach (TwitterStatus status in twitterResponse.ResponseObject)
                    {
                        Tweet t = GetTweetFromStatus(status);
                        if (t != null && t.language != null)
                        {
                            tweets.Add(t);
                        }
                    }
                }
                else
                {
                    log.Warn("Cannot retrieve results for user \"" + user + "\".");
                }
                return(tweets);
            }
            catch (Exception ex)
            {
                log.Warn("Communication error! Cannot retrieve results for user \"" + user + "\".", ex);
                return(new List <Tweet>());
            }
        }
示例#28
0
        public void SSL()
        {
            TwitterResponse <TwitterUser> sslUser = TwitterUser.Show("twitterapi", new OptionalProperties {
                UseSSL = true
            });

            Assert.IsTrue(sslUser.RequestUrl.StartsWith("https://"), "sslUser connection should be SSL");

            TwitterResponse <TwitterUser> user = TwitterUser.Show("twitterapi", new OptionalProperties {
                UseSSL = false
            });

            Assert.IsTrue(user.RequestUrl.StartsWith("http://"), "user connection should not be SSL");

            TwitterResponse <TwitterStatusCollection> timeline = TwitterTimeline.HomeTimeline(Configuration.GetTokens(), new TimelineOptions {
                UseSSL = true
            });

            Assert.IsTrue(timeline.RequestUrl.StartsWith("https://"), "timeline connection should be SSL");
        }
示例#29
0
        public void DetectEntities()
        {
            // Get the public timeline
            var timelineResult = TwitterTimeline.PublicTimeline();

            Assert.IsNotNull(timelineResult, "timelineResult is null");
            Assert.IsNotNull(timelineResult.ResponseObject, timelineResult.ErrorMessage);
            Assert.AreNotEqual(0, timelineResult.ResponseObject.Count, timelineResult.ErrorMessage);

            // Get the first tweet with entities
            TwitterStatus tweet = timelineResult.ResponseObject.Where(x => x.Entities != null && x.Entities.OfType <TwitterMentionEntity>().Count() > 0).First();

            // Make sure that we got the tweet successfully
            Assert.IsNotNull(tweet);

            // Get the hashtags
            //var hashTags = from entities in tweet.Entities.OfType<TwitterHashTagEntity>()
            //                select entities;

            // Get the mentions (@screenname within the text)
            var mentions = from entities in tweet.Entities.OfType <TwitterMentionEntity>()
                           select entities;

            // Get urls
            //var urls = from entities in tweet.Entities.OfType<TwitterUrlEntity>()
            //            select entities;

            // Get the tweet text to be modified
            string modifiedTweetText = tweet.Text;

            // Loop through the mentions from the back of the text to the beginning (to retain the index)
            foreach (TwitterMentionEntity mention in mentions.OrderBy(m => m.StartIndex).Reverse())
            {
                string linkText = string.Format("<a href=\"http://twitter.com/{0}\">@{0}</a>", mention.ScreenName);

                modifiedTweetText = string.Concat(
                    modifiedTweetText.Substring(0, mention.StartIndex),
                    linkText,
                    modifiedTweetText.Substring(mention.EndIndex));
            }
        }
示例#30
0
        public static void SSL()
        {
            TwitterResponse <TwitterUser> sslUser = TwitterUser.Show("twitterapi", new OptionalProperties {
                UseSSL = true
            });

            Assert.That(sslUser.RequestUrl.StartsWith("https://"));

            TwitterResponse <TwitterUser> user = TwitterUser.Show("twitterapi", new OptionalProperties {
                UseSSL = false
            });

            Assert.That(user.RequestUrl.StartsWith("http://"));

            TwitterResponse <TwitterStatusCollection> timeline = TwitterTimeline.HomeTimeline(Configuration.GetTokens(), new TimelineOptions {
                UseSSL = true
            });

            Assert.That(timeline.RequestUrl.StartsWith("https://"));
            Assert.That(user.RequestUrl.StartsWith("https://"));
        }
示例#31
0
        private void GetTimelineSince(Int64 sinceID, Action<List<AnimatableMessage>> handler)
        {
            TwitterClient client = new TwitterClient();

            client.GetTimelineSinceCompleted += (o, a) =>
            {
                if (a.Error == null)
                {
                    XElement element = XElement.Parse(a.Result);
                    TwitterTimeline timeline = new TwitterTimeline(element);
                    List<AnimatableMessage> list = new List<AnimatableMessage>();
                    var x = from m in timeline
                            select new AnimatableMessage { TwitterMessage = m };
                    handler(x.ToList());
                }
            };
            client.GetTimelineSinceAsync(sinceID);
        }
示例#32
0
        private void GetTimeline_Click(object sender, RoutedEventArgs e)
        {
            animatemessages = new ObservableCollection<AnimatableMessage>();
            mainBoard.Stop();
            mainBoard.Children.Clear();
            var currentID = 12345L;
            if (IsolatedStorageSettings.ApplicationSettings.Contains("CurrentMessage"))
            {
                currentID = (Int64)IsolatedStorageSettings.ApplicationSettings["CurrentMessage"];
            }
            TwitterClient twitter = new TwitterClient();
            twitter.GetTimelineSinceCompleted += (o, a) =>
                {
                    if (a.Error == null)
                    {
                        XElement element = XElement.Parse(a.Result);
                        TwitterTimeline timeline = new TwitterTimeline(element);
                        int zorder = timeline.Count;
                        foreach (var tmess in timeline)
                        {
                            var mess = new AnimatableMessage { TwitterMessage = tmess };
                            animatemessages.Insert(0, mess);
                            //animatemessages.Add(mess);
                        }
                        listbox.ItemsSource = null;
                        listbox.ItemsSource = animatemessages;

                        frontmost = animatemessages.Count - 1;
                        //CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
                        BuildStoryboards(animatemessages);
                        currentItem = animatemessages.Count - 1;
                        var curmess = animatemessages.FirstOrDefault(m => m.TwitterMessage.Id == currentID);
                        if (curmess != null)
                        {
                            currentItem = animatemessages.IndexOf(curmess);
                        }
                        MoveToMessage(currentItem);
                    }
                };
            twitter.GetTimelineSinceAsync(12345L);
        }