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


C# List.Where方法代码示例

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


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

示例1: ResetLastAccessed

 public void ResetLastAccessed(List<Objects.Option> options, int defaultPollingInterval)
 {
     if (options.Count(x => x.Active) > 0)
     {
         DateTime currentDate = DateTime.Now.ToUniversalTime();
         DateTime defaultLastCheckedDate = currentDate.AddMilliseconds(-defaultPollingInterval);
         foreach (Objects.Option option in options.Where(x => x.Active))
         {
             switch ((TwitterOptionId)option.OptionId)
             {
                 case TwitterOptionId.TweetCount:
                     option.LastAccessed = currentDate.AddMinutes(-option.Numerics[0]);
                     break;
                 default:
                     option.LastAccessed = defaultLastCheckedDate;
                     break;
             }
         }
     }
 }
开发者ID:runtime1point0,项目名称:Fritz-Notifier,代码行数:20,代码来源:TwitterNotifier.cs

示例2: TestForNotifications

        public List<Objects.Notification> TestForNotifications(List<Objects.Option> options)
        {
            var notifications = new List<Objects.Notification>(options.Count);

            //if (options.Count(x => x.Active) > 0)
            {
                var auth = new LinqToTwitter.SingleUserAuthorizer
                {
                    Credentials = new LinqToTwitter.SingleUserInMemoryCredentials
                    {
                        ConsumerKey = System.Configuration.ConfigurationManager.AppSettings.Get("consumerKey"),
                        ConsumerSecret = System.Configuration.ConfigurationManager.AppSettings.Get("consumerSecret"),
                        //AccessToken = "accessToken",
                        //AccessTokenSecret = "accessTokenSecret"
                        TwitterAccessToken = System.Configuration.ConfigurationManager.AppSettings.Get("accessToken"),
                        TwitterAccessTokenSecret = System.Configuration.ConfigurationManager.AppSettings.Get("accessTokenSecret")
                    }
                };

                auth.Authorize();

                using (var ctx = new LinqToTwitter.TwitterContext(auth))
                {

                    //try
                    //{
                    //    //Account account = accounts.SingleOrDefault();
                    //    Account account = ctx.Account.Single(acct => acct.Type == AccountType.VerifyCredentials && acct.SkipStatus == true);
                    //    //var account = twitterCtx.Account
                    //    //    .Where(t => t.Type == AccountType.VerifyCredentials)
                    //    //    .FirstOrDefault(t => t.SkipStatus == true);
                    //    User user = account.User;
                    //    Status tweet = user.Status ?? new Status();
                    //    Console.WriteLine("User (#" + user.Identifier.ID
                    //                        + "): " + user.Identifier.ScreenName
                    //                        + "\nTweet: " + tweet.Text
                    //                        + "\nTweet ID: " + tweet.StatusID + "\n");

                    //    Console.WriteLine("Account credentials are verified.");
                    //}
                    //catch (System.Net.WebException wex)
                    //{
                    //    Console.WriteLine("Twitter did not recognize the credentials. Response from Twitter: " + wex.Message);
                    //}

                    var testMessageNotification = new FritzNotifier.Objects.Notification(this.NotificationApplication, 0, "Test sender" + " sent message " + "message 1", "New message from " + "Test sender", DateTime.Now);
                    var testSimpleMessage = new FritzNotifier.Objects.Notification(this.NotificationApplication, 0, "simple notification", null, DateTime.Now);

                    notifications.Add(testMessageNotification);
                    notifications.Add(testSimpleMessage);
                    return notifications;

                    try
                    {
                        DateTime currentDate = DateTime.Now;
                        foreach (Objects.Option option in options.Where(x => x.Active))
                        {
                            switch ((TwitterOptionId)option.OptionId)
                            {
                                case TwitterOptionId.TweetCount:
                                    // if enough time has passed since we last accessed this
                                    if ((currentDate - option.LastAccessed).TotalMinutes > option.Numerics[0])
                                    {
                                    int tweetCount =
                                        (from tweet in ctx.Status
                                         where tweet.Type == StatusType.Home &&
                                         tweet.CreatedAt > option.LastAccessed
                                         select tweet).Count();

                                    var newTweetCountNotification = new FritzNotifier.Objects.Notification(this.NotificationApplication, 0, tweetCount.ToString() + " new tweets.", tweetCount.ToString() + " new tweets.", currentDate);
                                        option.LastAccessed = currentDate;
                                        notifications.Add(newTweetCountNotification);
                                    }
                                    break;
                                case TwitterOptionId.DirectMessage:
                                    var directMsgs =
                                        (from dm in ctx.DirectMessage
                                         where dm.Type == DirectMessageType.SentTo &&
                                         dm.CreatedAt > option.LastAccessed
                                         select dm).ToList();
                                    foreach (var directMsg in directMsgs)
                                    {
                                        // handle appropriately
                                        var newDirectMessageNotification = new FritzNotifier.Objects.Notification(this.NotificationApplication, 0, directMsg.Sender.Name + " sent message " + directMsg.Text, "New message from " + directMsg.Sender.Name, currentDate);
                                        notifications.Add(newDirectMessageNotification);
                                        option.LastAccessed = currentDate;
                                    }

                                    break;
                            }
                        }
                    }
                    catch (System.Net.WebException wex)
                    {
                        Console.WriteLine("Twitter did not recognize the credentials. Response from Twitter: " + wex.Message);
                    }
                }
            }

            return notifications;
//.........这里部分代码省略.........
开发者ID:jttew,项目名称:Fritz-Notifier,代码行数:101,代码来源:TwitterNotifier.cs

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


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