RegUserAsync() public static method

public static RegUserAsync ( string host, int port, string login, string pass, string publicMessage = null, string privateNotes = null ) : Task
host string
port int
login string
pass string
publicMessage string
privateNotes string
return Task
示例#1
0
        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);
        }
示例#2
0
        public static User[] RegisterCandidates(string host, User[] users)
        {
            log.Info("Registering candidates...");
            var candidateTasks = users.Select(candidate => new { candidate, task = ElectroClient.RegUserAsync(host, Program.PORT, candidate.Login, candidate.Pass, candidate.PublicMessage, candidate.PrivateMessage) }).ToArray();

            try
            {
                var result = candidateTasks.Select(arg =>
                {
                    arg.candidate.Cookies = arg.task.Result;
                    return(arg.candidate);
                }).ToArray();
                log.InfoFormat("Registered {0} candidates", result.Length);
                return(result);
            }
            catch (Exception e)
            {
                throw new ServiceException(ExitCode.DOWN, string.Format("Failed to reg {0} candidates in parallel: {1}", candidateTasks.Length, e));
            }
        }