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; }
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)); } }