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


C# List.ForEach方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            if (!EnsureSingleLoad())
            {
                Console.WriteLine("{0}: Another Instance Currently Runing", DateTime.Now);
                return;
            }

            var streamMonitors = new List<DualStreamMonitor>();

            UsersCollection.PrimaryUsers().AsParallel()
                .ForAll(u =>
            {
                var streamMonitor = new DualStreamMonitor(u, Console.Out);
                streamMonitor.Start();

                lock (streamMonitors)
                {
                    streamMonitors.Add(streamMonitor);
                }
            });

            while (Console.ReadLine() != "exit") ;

            streamMonitors.ForEach(s => s.Stop());
        }
开发者ID:postworthy,项目名称:postworthy,代码行数:26,代码来源:Program.cs

示例2: 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

示例3: ConditionalSearchDemo

        static void ConditionalSearchDemo(TwitterContext twitterCtx)
        {
            const string TwitterSearchGeocodeFormat = "{0},{1},{2}";
            string query = "Twitter";
            string language = null;
            string locale = null;
            string latitude = "37.781157";
            string longitude = "-122.398720";
            uint radius = 1;
            string radiusUnitType = "mi";

            Type searchType = typeof(Search);
            ParameterExpression srch = Expression.Parameter(searchType, "srch");

            var predicates = new List<Expression>();

            if (!string.IsNullOrWhiteSpace(query))
            {
                predicates.Add(
                    Expression.Equal(
                        Expression.Property(srch, "Query"),
                        Expression.Constant(query)));
            }

            if (!string.IsNullOrWhiteSpace(language))
            {
                predicates.Add(
                    Expression.Equal(
                        Expression.Property(srch, "SearchLanguage"),
                        Expression.Constant(language)));
            }

            if (!string.IsNullOrWhiteSpace(locale))
            {
                predicates.Add(
                    Expression.Equal(
                        Expression.Property(srch, "Locale"),
                        Expression.Constant(locale)));
            }

            if (!string.IsNullOrWhiteSpace(longitude) && !string.IsNullOrWhiteSpace(latitude) && radius > 0)
            {
                var radiusString = string.Format("{0}{1}", radius, radiusUnitType.ToString().ToLower());
                var geoCodeParameter = String.Format(TwitterSearchGeocodeFormat, latitude, longitude, radiusString);
                predicates.Add(
                    Expression.Equal(
                        Expression.Property(srch, "GeoCode"),
                        Expression.Constant(geoCodeParameter)));
            }

            BinaryExpression expr = Expression.Equal(
                Expression.Property(srch, "Type"),
                Expression.Constant(SearchType.Search));

            predicates.ForEach(pred => expr = Expression.AndAlso(expr, pred));

            var searchLambda =
                Expression.Lambda(expr, srch) as Expression<Func<Search, bool>>;

            var response = 
                twitterCtx.Search
                    .Where(searchLambda)
                    .SingleOrDefault();

            Console.WriteLine("\nQuery: {0}\n", response.SearchMetaData.Query);
            response.Statuses.ForEach(entry =>
                Console.WriteLine(
                    "ID: {0, -15}, Source: {1}\nContent: {2}\n",
                    entry.StatusID, entry.Source, entry.Text));
        }
开发者ID:prog-moh,项目名称:LinqToTwitter,代码行数:70,代码来源:SearchDemos.cs

示例4: PrintTweetsResults

 static void PrintTweetsResults(List<Status> tweets)
 {
     if (tweets != null)
         tweets.ForEach(tweet => 
         {
             if (tweet != null && tweet.User != null)
                 Console.WriteLine(
                     "ID: [{0}] Name: {1}\n\tTweet: {2}",
                     tweet.StatusID, tweet.User.ScreenNameResponse, tweet.Text);
         });
 }
开发者ID:yaremado,项目名称:LinqToTwitter,代码行数:11,代码来源:StatusDemos.cs

示例5: 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

示例6: 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


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