本文整理汇总了C#中LinqToTwitter.List.Add方法的典型用法代码示例。如果您正苦于以下问题:C# List.Add方法的具体用法?C# List.Add怎么用?C# List.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinqToTwitter.List
的用法示例。
在下文中一共展示了List.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAllAvailableOptions
public List<Objects.Option> GetAllAvailableOptions()
{
var tweetCountNumerics = new List<int>(1);
tweetCountNumerics.Add(10); // default to 10 minutes in between tweet count updates
var tweetCountOption = new Objects.Option(1, null, tweetCountNumerics); // id 1 is the tweet count notification option for Twitter
var directMessageOption = new Objects.Option(2, null, null); // id 2 is the direct message notification option for Twitter
var options = new List<Objects.Option>(2);
options.Add(tweetCountOption);
options.Add(directMessageOption);
return options;
}
示例2: GetTweetsFor
public async Task<IEnumerable<TweetDto>> GetTweetsFor(IEnumerable<string> tweetsIds)
{
var tweetsIdsList = tweetsIds.Select(s => Convert.ToUInt64(s)).Materialize();
if (tweetsIdsList.IsEmpty())
{
return Enumerable.Empty<TweetDto>();
}
using (var twitterContext = CreateContext())
{
var results = new List<TweetDto>();
foreach (var tweetsId in tweetsIdsList)
{
var id = tweetsId;
var tweet = await
twitterContext.Status
.Where(status => status.Type == StatusType.Show && status.ID == id).FirstOrDefaultAsync();
if (tweet != null)
{
results.Add(BuildTweetDto(tweet));
}
}
return results;
}
}
示例3: 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());
}
示例4: Index
public IActionResult Index(string screenname, string order)
{
// TODO handle hashtags separately
int markovOrder;
// default order is 2, if the parse failed
if (!int.TryParse(order, out markovOrder))
markovOrder = 2;
// hack to avoid null pointer exception
if (markovOrder > 5)
markovOrder = 5;
int tweetCount = 200;
var generator = new MarkovGenerator(markovOrder, false);
// how to handle hashtags? just keep a list of them along with a probability for each,
// i.e. a single-prefix markov chain?
// would also need a no-hashtag probability
// no, that won't work, since there wouldn't be an end point, really. at least not one that makes sense.
// what might work is keeping track of individual hashtag probabilities,
// as well as a probability distribution of number of hashtags. (fun to get some stats on that, see if it's poisson-distributed)
ViewData["Screenname"] = screenname;
var auth = new SingleUserAuthorizer
{
CredentialStore = new SingleUserInMemoryCredentialStore
{
ConsumerKey = _consumerKey,
ConsumerSecret = _consumerSecret,
AccessToken = _accessToken,
AccessTokenSecret = _accessTokenSecret
}
};
var twitterCtx = new TwitterContext(auth);
var timeline =
(twitterCtx.Status.Where(tweet => tweet.Type == StatusType.User &&
tweet.ScreenName == screenname &&
tweet.Count == tweetCount))
.ToList();
foreach (var tweet in timeline)
{
generator.ReadInput(tweet.Text);
}
int outputCount = 20;
var outputList = new List<string>();
for (int i = 0; i < outputCount; i++)
{
outputList.Add(generator.GenerateOutput());
}
//TODO add form
//TODO use form data
return View(outputList);
}
示例5: BuildLast20TweetsOfUser
private IEnumerable<TweetFromUser> BuildLast20TweetsOfUser(IEnumerable<Status> tweets)
{
var last20TweetsFromUser = new List<TweetFromUser>();
tweets.ToList().ForEach(tweet => last20TweetsFromUser
.Add(new TweetFromUser
{
TweetText = tweet.Text
}));
return last20TweetsFromUser;
}
示例6: Search
public override List<Result> Search(string pKeyWords)
{
string twitterConsumerKey = ConfigurationManager.AppSettings["twitter-consumer-key"];
string twitterConsumerSecret = ConfigurationManager.AppSettings["twitter-consumer-secret"];
if (string.IsNullOrWhiteSpace(twitterConsumerKey) || string.IsNullOrWhiteSpace(twitterConsumerSecret))
throw new Exception("App was unable to find Twitter credentials on the current settings file. Please add twitter-consumer-key and twitter-consumer-secret to the appSettings section.");
ApplicationOnlyAuthorizer authorization = new ApplicationOnlyAuthorizer()
{
Credentials = new InMemoryCredentials()
{
ConsumerKey = twitterConsumerKey,
ConsumerSecret = twitterConsumerSecret
}
};
authorization.Authorize();
if(!authorization.IsAuthorized)
throw new Exception("Twitter authorizaton was unsuccessful. Please review your Twitter key and secret.");
TwitterContext twitterContext = new TwitterContext(authorization);
LinqToTwitter.Search twitterSearch =
(from search in twitterContext.Search
where search.Type == SearchType.Search &&
search.Query == pKeyWords &&
search.Count == this.MaxResultSearch
select search)
.SingleOrDefault();
IEnumerable<Status> tweets =
from status in twitterSearch.Statuses
orderby status.CreatedAt descending
select status;
List<Result> domainResults = new List<Result>();
foreach (Status status in tweets)
{
domainResults.Add(
new Result()
{
CreatedDate = status.CreatedAt,
Type = SourceType.Twitter,
Text = status.Text,
Title = status.Text.Length > 50? string.Format("{0}...",status.Text.Substring(0, 47)) : status.Text,
URL = string.Format("http://twitter.com/{0}", status.User.Identifier.ScreenName)
}
);
}
return domainResults;
}
示例7: BuildTweetsFromStatuses
private IEnumerable<TweetFromUser> BuildTweetsFromStatuses(IEnumerable<Status> myWall)
{
var tweetFromUserList = new List<TweetFromUser>();
myWall.ToList().ForEach(tweet => tweetFromUserList
.Add(new TweetFromUser
{
TweetText = tweet.Text,
User = BuildUserOffUserId(tweet.User.Identifier.UserID)
}));
return tweetFromUserList;
}
示例8: getstopwords
public static List<string> getstopwords(string lang)
{
//lang can be implemented later. XML doc has lang attribute in wordlist element.
List<string> sw = new List<string>();
XmlDocument xd = new XmlDocument();
xd.Load(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content/StopWords.xml"));
XmlNodeList nl = xd.SelectNodes("/wordlist/word");
foreach (XmlNode n in nl)
{
sw.Add(n.InnerText);
}
return sw;
}
示例9: FindAllUserStatistics
/// <summary>
///
/// </summary>
/// <param name="actionState"></param>
/// <returns></returns>
public List<UserStatistics> FindAllUserStatistics(ActionState actionState)
{
List<UserStatistics> userStattisticsList = new List<UserStatistics>();
IEnumerable<BsonValue> userNameList = FindAUsersID(actionState);
for (int i = 0; i < userNameList.ToArray<BsonValue>().Count(); i++)
{
UserStatistics userStatistic = new UserStatistics();
userStatistic.Name = userNameList.ToArray<BsonValue>()[i].AsString;
userStatistic.Count = FindTwitterCountByName(userStatistic.Name, actionState);
userStattisticsList.Add(userStatistic);
}
return userStattisticsList;
}
示例10: CreateGeometry
/// <summary>
/// Converts XML to a new Geometry
/// </summary>
/// <param name="geometry">XML to convert</param>
/// <returns>Geometry containing info from XML</returns>
public Geometry CreateGeometry(XElement geometry)
{
if (geometry == null)
{
return null;
}
List<Coordinate> coords = new List<Coordinate>();
if (geometry.Element("coordinates") == null)
{
XNamespace geoRss = "http://www.georss.org/georss";
if (geometry.Element(geoRss + "polygon") != null)
{
var coordArr = geometry.Element(geoRss + "polygon").Value.Split(' ');
for (int lat = Coordinate.LatitudePos, lon = Coordinate.LongitudePos; lon < coordArr.Length; lat+=2, lon += 2)
{
coords.Add(
new Coordinate
{
Latitude = double.Parse(coordArr[lat]),
Longitude = double.Parse(coordArr[lon])
});
}
}
}
else
{
var coordinate = new Coordinate();
coords =
(from coord in geometry.Element("coordinates").Element("item").Elements("item")
select coordinate.CreateCoordinate(coord))
.ToList();
}
return new Geometry
{
Type =
geometry.Element("type") == null ?
string.Empty :
geometry.Element("type").Value,
Coordinates = coords
};
}
示例11: Tweets
public async Task<IActionResult> Tweets(string screenName)
{
var model = new List<TweetViewModel>();
List<Status> statuses = await twitterService.GetUserTweetsAsync(screenName);
foreach (var status in statuses) {
var tweet = new TweetViewModel
{
TweetId = status.StatusID,
TweetedOn = status.CreatedAt,
InReplyToScreenName = status.InReplyToScreenName,
Text = status.Text,
Url = "https://twitter.com/" + status.ScreenName + "/status/" + status.StatusID
};
model.Add(tweet);
}
return View("Index", model);
}
示例12: Get
// GET api/UpdateTweets
public async Task<string> Get()
{
//Services.Log.Info("Hello from custom controller!");
var dbCtx = new MobileServiceContext();
long lastTweetId = 0;
var t = dbCtx.Tweets.OrderByDescending(x => x.Date).ToList().Select(x => new { StatusId = x.StatusId }).FirstOrDefault();
if (t != null) { lastTweetId = t.StatusId; }
var statuses = await GetLatestsTwittersWithHashtag("mobilecloudhackday", lastTweetId);
var newTweets = new List<Tweet>();
foreach (var status in statuses)
{
var twt = new Tweet()
{
Id = Guid.NewGuid().ToString(),
StatusId = (long)status.StatusID,
Text = status.Text,
Date = status.CreatedAt,
User = status.User.Name,
UserId = status.User.ScreenNameResponse,
UserImageUri = status.User.ProfileImageUrl
};
dbCtx.Tweets.Add(twt);
newTweets.Add(twt);
}
await dbCtx.SaveChangesAsync();
await NotifyPush(newTweets);
return "Ok";
}
示例13: GetLatestTweets
public IList<Tweet> GetLatestTweets(int count)
{
var twitterContext = new TwitterContext(Authorize());
var tweets = new List<Tweet>();
var statusTweets = from tweet in twitterContext.Status
where tweet.Type == StatusType.User &&
tweet.ScreenName == _twitterAccount &&
tweet.IncludeContributorDetails == true &&
tweet.Count == 10 &&
tweet.IncludeEntities == true
select tweet;
foreach (var statusTweet in statusTweets)
{
tweets.Add(Tweet.Create(statusTweet.User.ProfileImageUrl, statusTweet.User.ScreenName,
GetTweetMediaUrl(statusTweet), statusTweet.Text));
}
return tweets;
}
示例14: Search
public IEnumerable<TwitterSearchResult> Search(string searchText)
{
IList<TwitterSearchResult> foundTweets = new List<TwitterSearchResult>();
try
{
var queryResults =
from search in TwitterCtx.Search
where search.Type == SearchType.Search &&
search.Query == searchText
select search;
var queryResult = queryResults.SingleOrDefault();
foreach (var entry in queryResult.Entries)
{
var statusID = entry.ID.Substring(entry.ID.LastIndexOf(":") + 1);
var status =
(from tweet in twitterCtx.Status
where tweet.Type == StatusType.Show &&
tweet.ID == statusID
select tweet)
.SingleOrDefault();
TwitterSearchResult foundTweet = new TwitterSearchResult() { UserName = "@" + status.User.Identifier.ScreenName, ProfileImageUrl = status.User.ProfileImageUrl, TweetText = status.Text, DateTime = status.CreatedAt.ToLongDateString() + " " + status.CreatedAt.ToLongTimeString(), Source = "via: "+status.Source };
foundTweets.Add(foundTweet);
}
}
catch (TargetInvocationException ex)
{
MessageBox.Show("Error Querying Twitter: " + ex.InnerException.Message );
}
return foundTweets;
}
示例15: GetFeed
public IList<Feed> GetFeed(FeedModel request)
{
var result = new List<Feed>();
var user = repository.AsQueryable<Sociopath.DataEntities.Entities.User>().FirstOrDefault(x => x.Id == request.UserId);
if (user == null || user.TwitterToken == null || user.TwitterSecret == null)
{
return result;
}
var auth = new SingleUserAuthorizer
{
CredentialStore = new InMemoryCredentialStore
{
ConsumerKey = ConsumerKey,
ConsumerSecret = ConsumerSecret,
OAuthToken = user.TwitterToken,
OAuthTokenSecret = user.TwitterSecret
}
};
var twitterCtx = new TwitterContext(auth);
var tweets = twitterCtx.Status.Where(tweet => tweet.Type == StatusType.User).ToList();
foreach (Status tweet in tweets)
{
Feed feedItem = repository.AsQueryable<Feed>().FirstOrDefault(x => x.TwitterExternalId == tweet.StatusID.ToString()) ?? new Feed();
feedItem.TwitterExternalId = tweet.StatusID.ToString();
feedItem.Message = tweet.Text;
feedItem.Time = tweet.CreatedAt;
repository.Save(feedItem);
result.Add(feedItem);
}
repository.Commit();
return result;
}