NominateAsync() public static method

public static NominateAsync ( string host, int port, CookieCollection cookieCollection, System.Guid electionId ) : Task
host string
port int
cookieCollection System.Net.CookieCollection
electionId System.Guid
return Task
示例#1
0
        public static Election NominateUsers(string host, Election election, User[] candidates)
        {
            log.InfoFormat("Nominating rest {0} candidates for election...", candidates.Length);
            var nominateTasks = candidates.Select(candidate => new { candidate, task = ElectroClient.NominateAsync(host, Program.PORT, candidate.Cookies, election.Id) }).ToArray();

            Election[] elections;
            try
            {
                elections = nominateTasks.Select(arg => arg.task.Result).ToArray();
            }
            catch (Exception e)
            {
                throw new ServiceException(ExitCode.DOWN, string.Format("Failed to nominate {0} candidates in parallel: {1}", nominateTasks.Length, e));
            }

            var electionId = election.Id;

            election = elections.FirstOrDefault(election1 => election1 != null && election1.Candidates.Count >= candidates.Length + 1);
            if (election == null)
            {
                throw new ServiceException(ExitCode.MUMBLE, string.Format("Nominated '{0}' candidates for election '{1}', but got less in result", candidates.Length + 1, electionId));
            }

            log.Info("Candidates nomindated");
            return(election);
        }