예제 #1
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voting client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientCreateSharePartPrepareAuthority;
                  Progress = 0d;
                  SubText = string.Empty;
                  SubProgress = 0d;

                  var parameters = client.proxy.FetchParameters(this.votingId, this.authorityCertificate);

                  client.CreateAuthority(this.authorityCertificate);
                  client.authorityEntity.Prepare(parameters.Key, parameters.Value);

                  Text = LibraryResources.ClientCreateSharePartFetchAuthorityList;
                  Progress = 0.15d;

                  var authorityList = client.proxy.FetchAuthorityList(this.votingId);

                  client.authorityEntity.SetAuthorities(authorityList);

                  Text = LibraryResources.ClientCreateSharePartSaveAuthority;
                  Progress = 0.3d;

                  client.SaveAuthority(this.authorityFileName);

                  Text = LibraryResources.ClientCreateSharePartCreateShareParts;
                  Progress = 0.55d;

                  var sharePart = client.authorityEntity.GetShares();

                  Text = LibraryResources.ClientCreateSharePartPushShareParts;
                  Progress = 0.75d;

                  client.proxy.PushShares(this.votingId, sharePart);

                  Text = LibraryResources.ClientCreateSharePartGetVotingStatus;
                  Progress = 0.9d;

                  var material = client.proxy.FetchVotingMaterial(this.votingId);
                  List<Guid> authoritieDone;
                  VotingStatus status = client.proxy.FetchVotingStatus(this.votingId, out authoritieDone);
                  var votingDescriptor = new VotingDescriptor(material.Parameters.Value, status, authoritieDone, material.CastEnvelopeCount);

                  Progress = 1d;

                  this.callBack(votingDescriptor, null);
                }
                catch (Exception exception)
                {
                  this.callBack(null, exception);
                }
            }
예제 #2
0
            /// <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);
                }
            }
예제 #3
0
 private void CreateSharesCompleteCallBack(VotingDescriptor votingDescriptor, Exception exception)
 {
     this.exception = exception;
       this.votingDescriptor = votingDescriptor;
       this.run = false;
 }
예제 #4
0
        public void Display(VotingDescriptor voting)
        {
            this.questionControls = new List<QuestionControl>();
              this.titleControl.Title = voting.Title.Text;
              this.titleControl.InfoFont = new Font("Arial", 12, FontStyle.Bold);
              this.titleControl.Description = voting.Description.Text;
              this.titleControl.Url = voting.Url.Text;
              this.titleControl.BeginInfo();

              RecalculateLayout();
              this.questionTabs.TabPages.Clear();
              int number = 1;

              foreach (var question in voting.Questions)
              {
            TabPage tabPage = new TabPage();
            tabPage.Text = string.Format(Resources.VotingDialogQuestion, number);
            this.questionTabs.TabPages.Add(tabPage);

            QuestionControl questionControl = new QuestionControl();
            tabPage.Controls.Add(questionControl);
            questionControl.Dock = DockStyle.Fill;
            questionControl.Display(question);
            questionControl.ValidChanged += new EventHandler(QuestionControl_ValidChanged);
            this.questionControls.Add(questionControl);

            number++;
              }
        }
예제 #5
0
 private void CreateDeciphersComplete(VotingDescriptor votingDescriptor, Exception exception)
 {
     this.exception = exception;
       this.votingDescriptor = votingDescriptor;
       this.run = false;
 }
예제 #6
0
 private void CheckSharesComplete(VotingDescriptor votingDescriptor, bool accept, Signed<BadShareProof> signedBadShareProof, Exception exception)
 {
     this.exception = exception;
       this.votingDescriptor = votingDescriptor;
       this.acceptShares = accept;
       this.signedBadShareProof = signedBadShareProof;
       this.run = false;
 }
예제 #7
0
        private void DownloadVoting(VotingDescriptor votingDescriptor)
        {
            this.run = true;
              this.votingList.Enabled = false;
              OnUpdateWizard();

              Status.VotingClient.DownloadVoting(votingDescriptor.Id, Status.DataPath, DownloadVotingComplete);

              while (this.run)
              {
            Status.UpdateProgress();
            Thread.Sleep(10);
              }

              if (this.exception == null)
              {
            RefreshList();

            Status.SetMessage(Resources.ListVotingDownloadSuccess, MessageType.Success);
              }
              else
              {
            Status.SetMessage(this.exception.Message, MessageType.Error);
              }

              this.votingList.Enabled = true;
              OnUpdateWizard();
        }
예제 #8
0
        private void AddVotingToList(VotingDescriptor voting)
        {
            ListViewItem item = new ListViewItem(voting.Status.Text());
              item.SubItems.Add(voting.Title.Text);
              item.SubItems.Add(Status.GetGroupName(voting.GroupId));
              item.SubItems.Add(voting.VoteFrom.ToShortDateString());
              item.SubItems.Add(voting.VoteUntil.ToShortDateString());

              switch (voting.Status)
              {
            case VotingStatus.New:
            case VotingStatus.Sharing:
            case VotingStatus.Deciphering:
              item.SubItems.Add(voting.AuthoritiesDone.Count().ToString() + " / " + voting.AuthorityCount.ToString());
              break;
            default:
              item.SubItems.Add(string.Empty);
              break;
              }

              switch (voting.Status)
              {
            case VotingStatus.Voting:
            case VotingStatus.Deciphering:
            case VotingStatus.Finished:
            case VotingStatus.Offline:
              item.SubItems.Add(voting.EnvelopeCount.ToString());
              break;
            default:
              item.SubItems.Add(string.Empty);
              break;
              }

              if (this.voteReceipts.ContainsKey(voting.Id))
              {
            var voteReceiptList = this.voteReceipts[voting.Id];

            if (voteReceiptList.Count > 1)
            {
              item.SubItems.Add(voteReceiptList.Count.ToString());
            }
            else
            {
              item.SubItems.Add(Resources.ListVotingsVotedYes);
            }
              }
              else
              {
            item.SubItems.Add(Resources.ListVotingsVotedNo);
              }

              item.Tag = voting;
              this.votingList.Items.Add(item);
        }
예제 #9
0
            /// <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);
                }
            }