Example #1
0
        /// <summary>
        /// Creates a new summation of votes.
        /// </summary>
        /// <param name="parameters">Voting parameters.</param>
        /// <param name="certificateStorage">Certificate storage to verify against.</param>
        /// <param name="publicKey">Public key with which the votes where encrypted.</param>
        public Tally(
            VotingParameters parameters,
            CertificateStorage certificateStorage,
            BigInt publicKey,
            int checkProofCount)
        {
            this.rng = RandomNumberGenerator.Create();
              this.parameters = parameters;
              this.proofCheckCount = Math.Min(parameters.ProofCount, checkProofCount);
              this.certificateStorage = certificateStorage;
              this.publicKey = publicKey;

              this.voteSums = new Vote[this.parameters.Questions.Count()][];
              for (int questionIndex = 0; questionIndex < this.parameters.Questions.Count(); questionIndex++)
              {
            Question question = this.parameters.Questions.ElementAt(questionIndex);
            this.voteSums[questionIndex] = new Vote[question.Options.Count()];
              }

              this.result = new VotingResult(this.parameters.VotingId, this.parameters);
              this.partialDeciphers = new List<PartialDecipher>();
              this.countedVoters = new List<Guid>();
              this.nextEnvelopeIndex = 0;
              this.envelopeSequencerList = new Dictionary<int, Tuple<Signed<Envelope>, bool>>();

              EnvelopeHash = new byte[] { };
              EnvelopeCount = 0;
              ValidEnvelopeCount = 0;

              CryptoLog.Begin(CryptoLogLevel.Summary, "Begin tallying");
              CryptoLog.Add(CryptoLogLevel.Summary, "Voting id", parameters.VotingId);
              CryptoLog.Add(CryptoLogLevel.Summary, "Voting title", parameters.Title.Text);
              CryptoLog.Add(CryptoLogLevel.Detailed, "ProofCount", parameters.ProofCount);
              CryptoLog.Add(CryptoLogLevel.Detailed, "Thereshold", parameters.Thereshold);
              CryptoLog.Add(CryptoLogLevel.Numeric, "P", parameters.P);
              CryptoLog.Add(CryptoLogLevel.Numeric, "G", parameters.G);
              CryptoLog.Add(CryptoLogLevel.Numeric, "F", parameters.F);
              CryptoLog.Add(CryptoLogLevel.Numeric, "Q", parameters.Q);
              CryptoLog.EndWrite();
        }
Example #2
0
 private void GetResultComplete(VotingResult result, IDictionary<Guid, VoteReceiptStatus> voteReceiptsStatus, Exception exception)
 {
     this.votingResult = result;
       this.voteReceiptsStatus = voteReceiptsStatus;
       this.exception = exception;
       this.run = false;
 }
        private void GetResultComplete(VotingResult result, IDictionary<Guid, VoteReceiptStatus> voteReceiptsStatus, Exception exception)
        {
            if (exception == null)
            {
                var table = new StringTable();

                table.SetColumnCount(2);

                table.AddRow(result.Title.Text, string.Empty);
                table.AddRow("Total Ballots", result.TotalBallots.ToString());
                table.AddRow("Invalid Ballots", result.InvalidBallots.ToString());
                table.AddRow("Valid Ballots", result.ValidBallots.ToString());

                foreach (var question in result.Questions)
                {
                    table.AddRow(question.Text.Text, string.Empty);

                    foreach (var option in question.Options)
                    {
                        table.AddRow(option.Text.Text, option.Result.ToString());
                    }
                }

                BotMethods.SendMessage(SendType.Message, Channel, "Pi-Vote: Result of voting:");
                OutTable(table);
            }
            else
            {
                BotMethods.SendMessage(SendType.Message, Channel, "Pi-Vote: " + exception.Message);
            }

            OnCompleted();
        }
Example #4
0
 public void Set(VotingResult result, IDictionary<Guid, VoteReceiptStatus> voteReceiptStatus)
 {
     SetResultList(result, voteReceiptStatus);
 }
Example #5
0
 public static void ShowResult(VotingResult result, IDictionary<Guid, VoteReceiptStatus> voteReceiptStatus)
 {
     ResultDisplayDialog dialog = new ResultDisplayDialog();
       dialog.Set(result, voteReceiptStatus);
       dialog.ShowDialog();
 }
Example #6
0
        private void SetResultList(VotingResult result, IDictionary<Guid, VoteReceiptStatus> voteReceiptStatus)
        {
            this.table = new StringTable();
              table.SetColumnCount(2);

              Add(result.Title.Text, true);
              Add(Resources.ResultDialogTotalBallots, result.TotalBallots.ToString());
              Add(Resources.ResultDialogValidBallots, result.ValidBallots.ToString());
              Add(Resources.ResultDialogInvalidBallots, result.InvalidBallots.ToString());
              Add();

              foreach (var question in result.Questions)
              {
            Add(question.Text.Text, true);
            int abstentions = 0;

            foreach (var option in question.Options)
            {
              if (option.IsAbstentionSpecial)
              {
            abstentions += option.Result;
              }
              else
              {
            Add(option.Text.Text, option.Result.ToString());
              }
            }

            if (abstentions > 0)
            {
              Add(Resources.ResultDialogAbstain, abstentions.ToString());
            }

            Add();
              }

              if (voteReceiptStatus.Count > 0)
              {
            Add(Resources.ResultDialogYourVote, true);

            foreach (var voteReceipt in voteReceiptStatus)
            {
              switch (voteReceipt.Value)
              {
            case VoteReceiptStatus.FoundBad:
              Add(voteReceipt.Key.ToString(), Resources.ResultDialogFoundBad);
              break;
            case VoteReceiptStatus.FoundOk:
              Add(voteReceipt.Key.ToString(), Resources.ResultDialogFoundOk);
              break;
            case VoteReceiptStatus.NotFound:
              Add(voteReceipt.Key.ToString(), Resources.ResultDialogNotFound);
              break;
              }
            }
              }
        }