Exemplo n.º 1
0
        async Task LoadTweets(Data.Model.TwitterUser twitterUser)
        {
            var lastTweetId = await _twitterRepository
                              .GetLastMessageIdAsync(twitterUser.TwitterId);

            var result = new List <Data.Model.Tweet>();

            var lastTweetIdToFilter = lastTweetId > 0 ? lastTweetId : (long?)null;

            IEnumerable <TwitterStatus> tweets = null;

            tweets = _twitterService.ListTweetsOnUserTimeline(CreateTimeLineOptions(twitterUser.TwitterId, lastTweetIdToFilter, null));

            result.AddRange(tweets
                            .Select(i => ParseFromTwitterStatus(twitterUser.Id, i)));

            // Paginate if there are more tweets to load
            while (tweets.Count() > 1)
            {
                var lastId = tweets
                             .Min(i => i.Id);

                tweets = _twitterService.ListTweetsOnUserTimeline(CreateTimeLineOptions(twitterUser.TwitterId, lastTweetIdToFilter, lastId));

                result.AddRange(tweets
                                .Select(i => ParseFromTwitterStatus(twitterUser.Id, i)));
            }

            await _twitterRepository.AddAsync(result);
        }
Exemplo n.º 2
0
        async Task <Data.Model.TwitterUser> GetUser(long userId)
        {
            Data.Model.TwitterUser user = null;
            var existingUser            = await _twitterRepository.GetUserFrom(userId);

            if (existingUser == null)
            {
                var userFromApi = _twitterService.GetUserProfileFor(new GetUserProfileForOptions {
                    UserId = userId
                });
                user = new Data.Model.TwitterUser
                {
                    TwitterId       = userId,
                    TwitterUsername = userFromApi.ScreenName
                };

                await _twitterRepository.AddAsync(user);
            }
            else
            {
                user = existingUser;
            }

            return(user);
        }