本文整理汇总了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;
}
}
}
}
示例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;
//.........这里部分代码省略.........
示例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();
}