示例#1
0
 private void ScheduleLikesForFollowee(long now, RandomLikeAutomatonData data, ScheduledTasks tasks, string userId, List <TweetData> tweets)
 {
     for (var i = 0; i < tweets.Count; i++)
     {
         if (data.PercentageLikeChance > _random.Next(1) && data.LikesGivenPerFollowee[userId] < data.MaxLikesPerFollowee[userId])
         {
             var operation = new ScheduledOperation(DateTimeOffset.FromUnixTimeSeconds(now + _random.Next(SecondsPerHour * 2)),
                                                    _like.Name,
                                                    tweets[i].Id.ToString());
             tasks.Add(CreateTaskWithUniqueId(tasks, operation));
             data.LikesGivenPerFollowee[userId]++;
         }
     }
 }
示例#2
0
        private async Task <Result> ScheduleLikesForFollowees(long now, IEnumerable <string> userIds, RandomLikeAutomatonData data, ScheduledTasks tasks)
        {
            foreach (var id in userIds)
            {
                var tweetsResult = await _twitter.GetNewTweets(data.MaxLikesPerFollowee.ContainsKey(id)?data.LastUpdatedTimestamp : now - SecondsPerHour * 24, id.ToString());

                if (!tweetsResult.Succeeded())
                {
                    return(tweetsResult);
                }

                if (!data.MaxLikesPerFollowee.ContainsKey(id))
                {
                    data.MaxLikesPerFollowee.Add(id, 0);
                    data.LikesGivenPerFollowee.Add(id, 0);
                }
                ScheduleLikesForFollowee(now, data, tasks, id, tweetsResult.Content);
            }
            return(Result.Success());
        }