当前位置: 首页>>代码示例>>C#>>正文


C# List.AddRange方法代码示例

本文整理汇总了C#中LinqToTwitter.List.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# List.AddRange方法的具体用法?C# List.AddRange怎么用?C# List.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LinqToTwitter.List的用法示例。


在下文中一共展示了List.AddRange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Load

        private static IList<Status> Load(IQueryBuilder queryBuilder, ulong maxId, int count = 2000)
        {
            var statuses = new List<Status>();
            //todo limit exception System.AggregateException, message: Rate limit exceeded - Please visit the LINQ to Twitter FAQ (at the HelpLink) for help on resolving this error.
            var tweetQuery = queryBuilder.BuildTaskByMinId(maxId + 1).ToList();

            statuses.AddRange(tweetQuery);

            if (statuses.Count < 150)
            {
                return statuses;
            }

            while (statuses.Count < count)
            {
                tweetQuery = queryBuilder.BuildTaskByMinIdAndMaxId(maxId + 1, statuses[statuses.Count - 1].StatusID - 1).ToList();

                statuses.AddRange(tweetQuery);
                if (tweetQuery.Count < 150)
                {
                    break;
                }
            }
            return statuses;
        }
开发者ID:Stelmashenko-A,项目名称:CourseWork,代码行数:25,代码来源:UpDater.cs

示例2: ShowFriends

        public static async Task<List<User>> ShowFriends(IAuthorizer auth, string login)
        {
            var users = new List<User>();
            var twitterCtx = new TwitterContext(auth);

            Friendship friendship;
            long cursor = -1;
            do
            {
                friendship = await twitterCtx.Friendship.Where(x =>
                   x.Type == FriendshipType.FriendsList
                   && x.ScreenName == login
                   && x.Cursor == cursor
                   && x.Count == 200
                   && x.IncludeUserEntities == false)
                    .SingleOrDefaultAsync();

                if (friendship != null
                    && friendship.Users != null
                    && friendship.CursorMovement != null)
                {
                    cursor = friendship.CursorMovement.Next;
                    users.AddRange(friendship.Users);
                }
            } while (cursor != 0);
            return users;
        }
开发者ID:tarbii,项目名称:Collager,代码行数:27,代码来源:Twitter.cs

示例3: GetTopTags

        public static List<string> GetTopTags(List<ListRank> llr)
        {
            //so in here we choose which results to return based ontheir rank and number
            // faster to return them before going though every search but can build in the skip later.
            List<string> r = new List<string>();
            foreach (ListRank lr in llr)
            {
                // logic goes in here once we have it.
                r.AddRange(lr.result);

            }

            return r;
        }
开发者ID:HarryMcCarney,项目名称:Tweet-Tagger,代码行数:14,代码来源:Twitter.cs

示例4: GetAllFollowersQueryDemo

        /// <summary>
        /// shows how to query all followers
        /// </summary>
        /// <remarks>
        /// uses the Page property because Twitter doesn't
        /// return all followers in a single call; you
        /// must page through results until you get all
        /// </remarks>
        /// <param name="twitterCtx">TwitterContext</param>
        private static void GetAllFollowersQueryDemo(TwitterContext twitterCtx)
        {
            //
            // Paging has been deprecated for Friends and Followers
            // Please use cursors instead
            //

            var followerList = new List<User>();

            List<User> followers = new List<User>();
            int pageNumber = 1;

            do
            {
                followers.Clear();

                followers =
                    (from follower in twitterCtx.User
                     where follower.Type == UserType.Followers &&
                           follower.ScreenName == "JoeMayo" &&
                           follower.Page == pageNumber
                     select follower)
                     .ToList();

                pageNumber++;
                followerList.AddRange(followers);
            }
            while (followers.Count > 0);

            Console.WriteLine("\nFollowers: \n");

            foreach (var user in followerList)
            {
                var status =
                    user.Protected || user.Status == null ?
                        "Status Unavailable" :
                        user.Status.Text;

                Console.WriteLine(
                        "Name: {0}, Last Tweet: {1}\n",
                        user.Name, status);
            }

            Console.WriteLine("\nFollower Count: {0}\n", followerList.Count);
        }
开发者ID:giggio,项目名称:tweetercloud,代码行数:54,代码来源:UserDemos.cs

示例5: TwitterModule

        public TwitterModule() : base("/infoscreen/tweets")
        {
            Get["/{q}"] = args =>
            {
                string query = args.q.HasValue ? args.q : "#sølvberget";

                var auth = new SingleUserAuthorizer
                {
                    Credentials = new InMemoryCredentials
                    {
                        ConsumerKey = "a8SsPWed3GyxkFjnUh8vMA",
                        ConsumerSecret = "oN5p9jfXzVKVl107Txb2miOCebmX9pcERLssmxjM",
                        AccessToken = "4utDqnqoIBXIPi0TAtud1648QF2uC3hV5VRs6mNfYCyPT", // access token secret
                        OAuthToken = "14460916-ENyyzjPyZF4RfrtV3GK2Z44w9AE5ttLKWQs582SS1" // access token
                    }
                };

                var twitter = new TwitterContext(auth);


                var searchResponse = (from search in twitter.Search
                            where search.Type == SearchType.Search && search.Query == query
                            select search).FirstOrDefault();

                var tweets = new List<TweetDto>();

                if (searchResponse != null)
                {
                    tweets.AddRange(searchResponse.Statuses.Where(t => !t.PossiblySensitive).Select(tweet => new TweetDto
                    {
                        Text = tweet.Text, Username = tweet.User.Name, UserProfileImageUrl = tweet.User.ProfileImageUrl,
                        MediaUrl = tweet.Entities.MediaEntities.Count > 0 ? tweet.Entities.MediaEntities.First().MediaUrl + ":large" : null
                    }));

                }

                return Response.AsJson(tweets);
            };
        }
开发者ID:khellang,项目名称:Solvberget,代码行数:39,代码来源:TwitterModule.cs

示例6: GetSearchTweetsAsync

        //Gets tweets asynchronously
        public static async Task GetSearchTweetsAsync(string twitterAccountToDisplay, ulong sinceID)
        {
            try
            {
                var twitterCtx = GetContext();
                //string twitterAccountToDisplay = "Linq2Twitr"; 
                int count = 5;
                int maxStatuses = 30;
                int lastStatusCount = 0;
                //last tweet processed on previous query set
                //ulong sinceID = 544516702412723892;
                ulong maxID;
                var statusList = new List<Status>();

                //only count
                var searchResponse =
                    await
                    (from search in twitterCtx.Search
                     where search.Type == SearchType.Search &&
                         search.Query == "from:@" + twitterAccountToDisplay + " -retweets" && // -filter:retweets // -RT until:2012-10-26
                         search.Count == count
                     select search)
                    .SingleOrDefaultAsync();

                if (searchResponse != null && searchResponse.Statuses != null)
                {
                    List<Status> newStatuses = searchResponse.Statuses;
                    // first tweet processed on current query
                    maxID = newStatuses.Min(status => status.StatusID) - 1;
                    statusList.AddRange(newStatuses);

                    //adding if condition to fix Error : LinqToTwitter.TwitterQueryException: Missing or invalid url parameter 
                    //as SinceID is greater than MaxID, which is wrong according to the query.
                    if (sinceID < maxID)
                    {

                        do
                        {
                            // now add sinceID and maxID
                            searchResponse =
                                await
                                (from search in twitterCtx.Search
                                 where search.Type == SearchType.Search &&
                                       search.Query == "from:@" + twitterAccountToDisplay + " -retweets" && // -filter:retweets // -RT
                                       search.Count == count &&
                                     //search.Until == new DateTime(2014,12,1) &&
                                       search.SinceID == sinceID &&
                                       search.MaxID == maxID
                                 select search)
                                .SingleOrDefaultAsync(); //.ToList();

                            if (searchResponse == null)
                                break;

                            if (searchResponse.Count > 0 && searchResponse.Statuses.Count > 0)
                            {
                                newStatuses = searchResponse.Statuses;
                                // first tweet processed on current query
                                maxID = newStatuses.Min(status => status.StatusID) - 1;
                                statusList.AddRange(newStatuses);

                                lastStatusCount = newStatuses.Count;
                            }
                            if (searchResponse.Count > 0 && searchResponse.Statuses.Count == 0)
                            {
                                lastStatusCount = 0;
                            }
                        }
                        while (lastStatusCount != 0 && statusList.Count < maxStatuses); //(searchResponse.Count != 0 && statusList.Count < 30);
                    }

                    //searchResponse.Statuses.ForEach(tweet => Console.WriteLine( "User: {0}, Tweet: {1}", tweet.User.ScreenNameResponse, tweet.Text));

                    var tweetsOnlyList = from status in statusList //searchResponse.Statuses
                                         //Exclude replies and retweets
                                         where status.InReplyToScreenName == null && status.IncludeMyRetweet == false
                                         select new Status()
                                         {
                                             Text = status.Text,
                                             ScreenName = status.User.ScreenNameResponse,
                                             StatusID = status.StatusID,
                                             CreatedAt = status.CreatedAt
                                             //ProfileImageUrlHttps = status.ProfileImageUrlHttps
                                         };

                    //To display Tweets
                    //foreach (var tweet in tweetsOnlyList)
                    //{
                    //    Console.WriteLine("User: {0},\n Tweet: {1},\n maxID: {2},\n CreatedAt: {3}\n",
                    //                       tweet.ScreenNameResponse,
                    //                       tweet.Text,
                    //                       tweet.StatusID,
                    //                       tweet.CreatedAt);
                    //}

                    //Set Tweets to Database
                    SetTweetsOnly(tweetsOnlyList);
                }
            }
//.........这里部分代码省略.........
开发者ID:SravanBogu,项目名称:CustomSharePointSolutions,代码行数:101,代码来源:TwDbHelper.cs

示例7: Get

        public static List<Tweet> Get(string screenname, ulong maxStatusID)
        {
            int fetchMultiplier = int.Parse(
                !string.IsNullOrEmpty(ConfigurationManager.AppSettings["FetchMultiplier"]) ?
                    ConfigurationManager.AppSettings["FetchMultiplier"] : "10");

            List<string> screenNames = new List<string>();
            screenNames.AddRange(TwitterModel.Instance.GetRelevantScreenNames(screenname));

            List<Tweet> tweets = new List<Tweet>();
            screenNames.ForEach(name =>
            {
                var t = Repository<Tweet>.Instance.Query(name + TwitterModel.TWEETS);
                if (t != null) tweets.AddRange(t);
            });
            if (tweets != null)
                tweets = tweets.OrderByDescending(t => t.Status.CreatedAt).ToList();
            if (tweets == null ||
                tweets.Count() < 5 ||
                !tweets.Select(t => t.Status.CreatedAt).IsWithinAverageRecurrenceInterval(multiplier: fetchMultiplier))
            {

                var lastStatusID = (tweets != null && tweets.Count() > 0) ? ulong.Parse(tweets.First().Status.StatusID) : 0;
                var user = UsersCollection.Single(screenname) ?? UsersCollection.PrimaryUser();
                if (user.CanAuthorize)
                {
                    try
                    {
                        Expression<Func<Status, bool>> where;
                        if (maxStatusID > 0 && lastStatusID > 0)
                            where = (s => s.MaxID == maxStatusID &&
                                s.SinceID == lastStatusID &&
                                s.ScreenName == screenname &&
                                s.IncludeEntities == true &&
                                s.Type == StatusType.User &&
                                s.Count == 50);
                        else if (lastStatusID > 0)
                            where = (s => s.SinceID == lastStatusID &&
                                s.ScreenName == screenname &&
                                s.IncludeEntities == true &&
                                s.Type == StatusType.Home &&
                                s.Count == 200);
                        else
                            where = (s => s.ScreenName == screenname &&
                                s.IncludeEntities == true &&
                                s.Type == StatusType.Home &&
                                s.Count == 200);

                        var statuses = TwitterModel.Instance.GetAuthorizedTwitterContext(user.TwitterScreenName)
                            .Status
                            .Where(where)
                            .ToList();

                        List<Tweet> results;

                        if (statuses != null && statuses.Count > 0)
                            results = statuses.Select(s => new Tweet(s)).ToList();
                        else
                            results = null;

                        return results;
                    }
                    catch { return null; }
                }
            }
            return null;
        }
开发者ID:rickyn,项目名称:postworthy,代码行数:67,代码来源:StatusTimeline.cs

示例8: GetAllTweets

        private List<Status> GetAllTweets(ulong sinceId = 0)
        {
            var allTweets = new List<Status>();

            using (var twitter = new TwitterContext(Auth))
            {
                foreach (var u in Users)
                {
                    ulong localSince = sinceId;
                    int lastCount = 199;
                    var oldestId = ulong.MaxValue;
                    while (lastCount > 1)
                    {
                        IQueryable<Status> statusTweets =
                            twitter.Status.Where(tweet => tweet.Type == StatusType.User
                                                          && tweet.ScreenName == u
                                                          && tweet.IncludeMyRetweet == true
                                                          && tweet.ExcludeReplies == false
                                                          && tweet.Count == 199);

                        if (oldestId != ulong.MaxValue && sinceId == 0)
                            statusTweets = statusTweets.Where(t => t.MaxID == oldestId);

                        if (sinceId != 0)
                            statusTweets = statusTweets.Where(t => t.SinceID == localSince);

                        if (statusTweets != null)
                        {
                            var returned = statusTweets.ToList();

                            if (!returned.Any())
                                break;

                            lastCount = returned.Count();
                            localSince = returned.Max(t => ulong.Parse(t.StatusID));
                            oldestId = returned.Min(t => ulong.Parse(t.StatusID));
                            returned.RemoveAt(returned.Count - 1);
                            allTweets.AddRange(returned);
                        }
                        else
                        {
                            lastCount = 0;
                        }
                    }
                }
            }

            return allTweets.Where(t => t.CreatedAt > new DateTime(2015,01,01)).OrderByDescending(s =>s.StatusID).ToList();
        }
开发者ID:rcknight,项目名称:TwitterStats,代码行数:49,代码来源:StatsViewModel.cs

示例9: ShowFavoritesAsync

        static async Task ShowFavoritesAsync(TwitterContext twitterCtx)
        {
            const int PerQueryFavCount = 200;

            // set from a value that you previously saved
            ulong sinceID = 1; 

            var favsResponse =
                await
                    (from fav in twitterCtx.Favorites
                     where fav.Type == FavoritesType.Favorites &&
                           fav.Count == PerQueryFavCount
                     select fav)
                    .ToListAsync();

            if (favsResponse == null)
            {
                Console.WriteLine("No favorites returned from Twitter.");
                return;
            }

            var favList = new List<Favorites>(favsResponse);

            // first tweet processed on current query
            ulong maxID = favList.Min(fav => fav.StatusID) - 1;

            do
            {
                favsResponse =
                    await
                        (from fav in twitterCtx.Favorites
                         where fav.Type == FavoritesType.Favorites &&
                               fav.Count == PerQueryFavCount &&
                               fav.SinceID == sinceID &&
                               fav.MaxID == maxID
                         select fav)
                        .ToListAsync();

                if (favsResponse == null || favsResponse.Count == 0) break;

                // reset first tweet to avoid re-querying the
                // same list you just received
                maxID = favsResponse.Min(fav => fav.StatusID) - 1;
                favList.AddRange(favsResponse);

            } while (favsResponse.Count > 0);

            favList.ForEach(fav => 
            {
                if (fav != null && fav.User != null)
                    Console.WriteLine(
                        "Name: {0}, Tweet: {1}",
                        fav.User.ScreenNameResponse, fav.Text);
            });

            // save this in your db for this user so you can set
            // sinceID accurately the next time you do a query
            // and avoid querying the same tweets again.
            ulong newSinceID = favList.Max(fav => fav.SinceID);
        }
开发者ID:prog-moh,项目名称:LinqToTwitter,代码行数:60,代码来源:FavoriteDemos.cs

示例10: UpdateStatus

        public static void UpdateStatus()
        {
            Login();

            OnStatusUpdating(EventArgs.Empty);

            var status = new List<DGStatus>();
            IOrderedEnumerable<DGStatus> newStatus = null;

            try
            {
                for (int i = 0; i < Contexts.Count; i++)
                {
                    var query = from t in Contexts[i].Status
                                where t.Type == StatusType.Home && t.CreatedAt >= s_lastStatusUpdating
                                select new DGStatus(t, Accounts[i]);


                    status.AddRange(query);
                }

                newStatus = status.Distinct(new StatusEqualityComparer()).OrderBy(s => s.CreatedAt);

            }
            catch (Exception ex)
            {
                OnStatusUpdateFailed(new StatusUpdateFailedEventArgs(ex));
                return;
            }

            s_lastStatusUpdating = DateTime.UtcNow;

            foreach (var s in newStatus)
            {
                OnStatusReceived(new StatusEventArgs(s));
            }

            OnStatusUpdated(new StatusUpdatedEventArgs(newStatus.ToArray()));
        }
开发者ID:giacomelli,项目名称:DG.TwitterClient,代码行数:39,代码来源:CommunicationManager.cs

示例11: GetListStatusesAsync

        static async Task GetListStatusesAsync(TwitterContext twitterCtx)
        {
            string ownerScreenName = "Linq2Twitr";
            string slug = "linq";
            int maxStatuses = 30;
            int lastStatusCount = 0;
            // last tweet processed on previous query
            ulong sinceID = 204251866668871681; 
            ulong maxID;
            int count = 10;
            var statusList = new List<Status>();

            // only count
            var listResponse =
                await
                (from list in twitterCtx.List
                 where list.Type == ListType.Statuses &&
                       list.OwnerScreenName == ownerScreenName &&
                       list.Slug == slug &&
                       list.Count == count
                 select list)
                .SingleOrDefaultAsync();

            if (listResponse != null && listResponse.Statuses != null)
            {
                List<Status> newStatuses = listResponse.Statuses;
                // first tweet processed on current query
                maxID = newStatuses.Min(status => status.StatusID) - 1; 
                statusList.AddRange(newStatuses);

                do
                {
                    // now add sinceID and maxID
                    listResponse =
                        await
                        (from list in twitterCtx.List
                         where list.Type == ListType.Statuses &&
                               list.OwnerScreenName == ownerScreenName &&
                               list.Slug == slug &&
                               list.Count == count &&
                               list.SinceID == sinceID &&
                               list.MaxID == maxID
                         select list)
                        .SingleOrDefaultAsync();

                    if (listResponse == null)
                        break;

                    newStatuses = listResponse.Statuses;
                    // first tweet processed on current query
                    maxID = newStatuses.Min(status => status.StatusID) - 1; 
                    statusList.AddRange(newStatuses);

                    lastStatusCount = newStatuses.Count;
                }
                while (lastStatusCount != 0 && statusList.Count < maxStatuses);

                for (int i = 0; i < statusList.Count; i++)
                {
                    Status status = statusList[i];

                    Console.WriteLine("{0, 4}. [{1}] User: {2}\nStatus: {3}",
                        i + 1, status.StatusID, status.User.Name, status.Text);
                }
            }
        }
开发者ID:prog-moh,项目名称:LinqToTwitter,代码行数:66,代码来源:ListDemos.cs

示例12: DoPagedSearchAsync

        static async Task DoPagedSearchAsync(TwitterContext twitterCtx)
        {
            const int MaxSearchEntriesToReturn = 100;

            string searchTerm = "twitter";

            // oldest id you already have for this search term
            ulong sinceID = 1;

            // used after the first query to track current session
            ulong maxID; 

            var combinedSearchResults = new List<Status>();

            List<Status> searchResponse =
                await
                (from search in twitterCtx.Search
                 where search.Type == SearchType.Search &&
                       search.Query == searchTerm &&
                       search.Count == MaxSearchEntriesToReturn &&
                       search.SinceID == sinceID
                 select search.Statuses)
                .SingleOrDefaultAsync();

            combinedSearchResults.AddRange(searchResponse);
            ulong previousMaxID = ulong.MaxValue;
            do
            {
                // one less than the newest id you've just queried
                maxID = searchResponse.Min(status => status.StatusID) - 1;

                Debug.Assert(maxID < previousMaxID);
                previousMaxID = maxID;

                searchResponse =
                    await
                    (from search in twitterCtx.Search
                     where search.Type == SearchType.Search &&
                           search.Query == searchTerm &&
                           search.Count == MaxSearchEntriesToReturn &&
                           search.MaxID == maxID &&
                           search.SinceID == sinceID
                     select search.Statuses)
                    .SingleOrDefaultAsync();

                combinedSearchResults.AddRange(searchResponse);
            } while (searchResponse.Any());

            combinedSearchResults.ForEach(tweet =>
                Console.WriteLine(
                    "\n  User: {0} ({1})\n  Tweet: {2}",
                    tweet.User.ScreenNameResponse,
                    tweet.User.UserIDResponse,
                    tweet.Text));
        }
开发者ID:yaremado,项目名称:LinqToTwitter,代码行数:55,代码来源:SearchDemos.cs

示例13: UserTweets

        public List<Status> UserTweets(string inUserName_)
        {
            List<Status> statusList = new List<Status>(from tweet in _twitterCtx.Status
                                                       where tweet.Type == StatusType.User &&
                                                               tweet.ScreenName == inUserName_ &&
                                                               tweet.Count == AMT_TWEET_QUERY &&
                                                               tweet.RetweetedStatus.StatusID == 0
                                                       select tweet);

            ulong maxID = statusList[statusList.Count - 1].StatusID;
            int prevCount = statusList.Count;

            while (prevCount > 1)
            {
                if (statusList.Count > AMT_MAX_TWEETS)
                    break;

                List<Status> tmp = (from tweet in _twitterCtx.Status
                                    where tweet.Type == StatusType.User &&
                                            tweet.ScreenName == inUserName_ &&
                                            tweet.Count == AMT_TWEET_QUERY &&
                                            tweet.RetweetedStatus.StatusID == 0 &&
                                            tweet.MaxID == maxID
                                    select tweet).ToList();
                if (tmp.Count == 1)
                    break;

                statusList.AddRange(tmp);
                maxID = tmp[tmp.Count - 1].StatusID;
            }

            return statusList;
        }
开发者ID:ramatronics,项目名称:baewatch,代码行数:33,代码来源:TwitterAPI.cs

示例14: GetAllTweets

        private List<Status> GetAllTweets(ulong sinceId = 0)
        {
            var allTweets = new List<Status>();

            using (var twitter = new TwitterContext(Auth))
            {
                int lastCount = 199;
                var oldestId = ulong.MaxValue;
                while (lastCount > 1)
                {
                    IQueryable<Status> statusTweets =
                        twitter.Status.Where(tweet => tweet.Type == StatusType.User
                                                      && tweet.ScreenName == UserName
                                                      && tweet.IncludeMyRetweet == true
                                                      && tweet.ExcludeReplies == false
                                                      && tweet.Count == 199);

                    if (oldestId != ulong.MaxValue)
                        statusTweets = statusTweets.Where(t => t.MaxID == oldestId);

                    if (sinceId != 0)
                        statusTweets = statusTweets.Where(t => t.SinceID == sinceId);

                    if (statusTweets != null)
                    {
                        var returned = statusTweets.ToList();

                        if (!returned.Any())
                            break;

                        lastCount = returned.Count();
                        oldestId = returned.Min(t => ulong.Parse(t.StatusID));
                        returned.RemoveAt(returned.Count - 1);
                        allTweets.AddRange(returned);
                    }
                    else
                    {
                        lastCount = 0;
                    }
                }
            }

            return allTweets.Distinct().ToList();
        }
开发者ID:lparkermg,项目名称:TwitterStats,代码行数:44,代码来源:StatsViewModel.cs

示例15: GetRelevantScreenNames

        public List<string> GetRelevantScreenNames(string screenname)
        {
            var screenNames = new List<string> { screenname.ToLower() };

            if (UsersCollection.Single(screenname) != null && UsersCollection.Single(screenname).IncludeFriends)
                screenNames.AddRange((Friends(screenname) ?? new List<Tweep>()).Where(f => f.Type != Tweep.TweepType.Follower).Select(f => f.User.Identifier.ScreenName.ToLower()));

            return screenNames;
        }
开发者ID:rickyn,项目名称:postworthy,代码行数:9,代码来源:TwitterModel.cs


注:本文中的LinqToTwitter.List.AddRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。