/// <summary> /// Execute the operation. /// </summary> /// <param name="client">Voting client to execute against.</param> public override void Execute(VotingClient client) { try { Text = LibraryResources.ClientCreateDeciphersLoadAuthority; Progress = 0d; SubText = string.Empty; SubProgress = 0d; client.LoadAuthority(this.authorityFileName, this.authorityCertificate); Text = LibraryResources.ClientCreateDeciphersFetchMaterial; Progress = 0.1d; var material = client.proxy.FetchVotingMaterial(this.votingId); client.authorityEntity.TallyBegin(material); Text = LibraryResources.ClientCreateDeciphersFetchEnvelopeCount; Progress = 0.2d; this.envelopeCount = client.proxy.FetchEnvelopeCount(votingId); Text = LibraryResources.ClientCreateDeciphersFetchEnvelope; Progress = 0.2d; this.client = client; this.envelopeQueue = new Queue<Tuple<int, Signed<Envelope>>>(); this.workerRun = true; Thread fetcher = new Thread(FetchWorker); fetcher.Priority = ThreadPriority.Lowest; fetcher.Start(); List<Thread> workers = new List<Thread>(); Environment.ProcessorCount.Times(() => workers.Add(new Thread(TallyAddWorker))); this.threadProgress = new Dictionary<int, double>(); workers.ForEach(worker => worker.Priority = ThreadPriority.Lowest); workers.ForEach(worker => this.threadProgress.Add(worker.ManagedThreadId, 0d)); workers.ForEach(worker => worker.Start()); HasSingleProgress = true; while (this.verifiedEnvelopes < this.envelopeCount) { lock (this.threadProgress) { SubText = string.Format(LibraryResources.ClientGetResultFetchEnvelopesOf, this.verifiedEnvelopes, this.envelopeCount); SubProgress = 0.2d / (double)this.envelopeCount * (double)this.fetchedEnvelopes + 0.8d / (double)this.envelopeCount * ((double)this.verifiedEnvelopes + this.threadProgress.Values.Sum()); SingleProgress = SubProgress; } Thread.Sleep(100); } this.workerRun = false; workers.ForEach(worker => worker.Join()); HasSingleProgress = false; SubText = string.Empty; Text = LibraryResources.ClientCreateDeciphersCreatePartialDecipher; Progress = 0.7d; if (this.askCallBack == null || this.askCallBack(client.authorityEntity.TallyValidEnvelopeCount)) { var decipherList = client.authorityEntity.PartiallyDecipher(); Text = LibraryResources.ClientCreateDeciphersPushPartialDecipher; Progress = 0.8d; client.proxy.PushPartailDecipher(this.votingId, decipherList); Text = LibraryResources.ClientCreateDeciphersFetchVotingStatus; Progress = 0.9d; material = client.proxy.FetchVotingMaterial(this.votingId); List<Guid> authoritiesDone; VotingStatus status = client.proxy.FetchVotingStatus(this.votingId, out authoritiesDone); var votingDescriptor = new VotingDescriptor(material.Parameters.Value, status, authoritiesDone, material.CastEnvelopeCount); Progress = 1d; this.callBack(votingDescriptor, null); } else { this.callBack(null, new PiException(ExceptionCode.CanceledByUser, LibraryResources.ExceptionCanceledByUser)); } } catch (Exception exception) { this.callBack(null, exception); } }
/// <summary> /// Execute the operation. /// </summary> /// <param name="client">Voting client to execute against.</param> public override void Execute(VotingClient client) { try { Text = LibraryResources.ClientCheckSharesLoadAuthority; Progress = 0d; SubText = string.Empty; SubProgress = 0d; client.LoadAuthority(this.authorityFileName, this.authorityCertificate); Text = LibraryResources.ClientCheckSharesFetchShares; Progress = 0.2d; var allShareParts = client.proxy.FetchAllShares(this.votingId); Text = LibraryResources.ClientCheckSharesVerifyShares; Progress = 0.4d; var signedShareResponse = client.authorityEntity.VerifyShares(allShareParts); Text = LibraryResources.ClientCheckSharesSaveAuthority; Progress = 0.5d; Signed<BadShareProof> signedBadShareProof = client.authorityEntity.CreateBadShareProof(allShareParts); signedBadShareProof.Save(Path.Combine(Path.GetDirectoryName(this.authorityFileName), signedBadShareProof.Value.FileName(signedBadShareProof.Certificate.Id))); client.SaveAuthority(this.authorityFileName); Text = LibraryResources.ClientCheckSharesPushShareResponse; Progress = 0.6d; client.proxy.PushShareResponse(this.votingId, signedShareResponse); Text = LibraryResources.ClientCheckSharesGetVotingStatus; Progress = 0.8d; var material = client.proxy.FetchVotingMaterial(this.votingId); List<Guid> authoritiesDone; VotingStatus status = client.proxy.FetchVotingStatus(this.votingId, out authoritiesDone); var votingDescriptor = new VotingDescriptor(material.Parameters.Value, status, authoritiesDone, material.CastEnvelopeCount); Progress = 1d; this.callBack(votingDescriptor, signedShareResponse.Value.AcceptShares, signedBadShareProof, null); } catch (Exception exception) { this.callBack(null, false, null, exception); } }