public static GenRandomUser ( string privateNotes = null ) : User | ||
privateNotes | string | |
return | User |
private static User[] GenerateCandidates(int minCount, int maxCount) { var r = new Random(); int count = r.Next(minCount, maxCount + 1); return(Enumerable.Range(0, count).Select(i => UsersManager.GenRandomUser()).ToArray()); }
public static KeyValuePair <User, int[]>[] RegisterVoters(string host, int[][] votes, User[] candidateUsers) { var fakeTasks = votes.Take(candidateUsers.Length).Zip(candidateUsers, (vote, voter) => new { vote, voter, task = Task.FromResult(voter.Cookies) }); var newVotersTasks = votes.Skip(candidateUsers.Length).Select(vote => { var voter = UsersManager.GenRandomUser(); return(new { vote, voter, task = ElectroClient.RegUserAsync(host, Program.PORT, voter.Login, voter.Pass, voter.PublicMessage, voter.PrivateMessage) }); }).ToArray(); log.InfoFormat("Registering {0} new voters", newVotersTasks.Length); var voterTasks = fakeTasks.Concat(newVotersTasks).ToArray(); KeyValuePair <User, int[]>[] voters; try { voters = voterTasks.Select(arg => { arg.voter.Cookies = arg.task.Result; return(new KeyValuePair <User, int[]>(arg.voter, arg.vote)); }).ToArray(); } catch (AggregateException e) { throw new ServiceException(ExitCode.DOWN, string.Format("Failed to reg {0} voters in parallel: {1}", newVotersTasks.Length, e.Flatten())); } log.Info("Voters registered"); return(voters); }