当前位置: 首页>>代码示例>>C#>>正文


C# MySqlCommand.Add方法代码示例

本文整理汇总了C#中MySql.Data.MySqlClient.MySqlCommand.Add方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlCommand.Add方法的具体用法?C# MySqlCommand.Add怎么用?C# MySqlCommand.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MySql.Data.MySqlClient.MySqlCommand的用法示例。


在下文中一共展示了MySqlCommand.Add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Vote


//.........这里部分代码省略.........
              DateTime.Now.ToString());
            throw new PiArgumentException(ExceptionCode.InvalidEnvelopeBadDateTime, "Invalid envelope. Date out of range.");
              }

              if (envelope.VoterId != signedEnvelope.Certificate.Id)
              {
            Logger.Log(LogLevel.Warning,
              "Connection {0}: Voter id {1} (verified) tried to vote, but the envelope voter id did not match his certificate.",
              connection.Id,
              signedEnvelope.Certificate.Id.ToString());
            throw new PiArgumentException(ExceptionCode.InvalidEnvelopeBadVoterId, "Invalid envelope. Voter id does not match.");
              }

              if (envelope.Ballots.Count != Parameters.Questions.Count())
              {
            Logger.Log(LogLevel.Warning,
              "Connection {0}: Voter id {1} (verified) tried to vote, but there were {2} ballots in the envelope for {3} questions.",
              connection.Id,
              signedEnvelope.Certificate.Id.ToString(),
              envelope.Ballots.Count,
              Parameters.Questions.Count());
            throw new PiArgumentException(ExceptionCode.InvalidEnvelopeBadBallotCount, "Invalid envelope. Ballot count does not match.");
              }

              for (int questionIndex = 0; questionIndex < parameters.Questions.Count(); questionIndex++)
              {
            var ballot = envelope.Ballots[questionIndex];
            var question = parameters.Questions.ElementAt(questionIndex);

            if (ballot.SumProves.Count != parameters.ProofCount)
            {
              Logger.Log(LogLevel.Warning,
            "Connection {0}: Voter id {1} (verified) tried to vote, but there were {2} sum proofs present where there sould have been {3}.",
            connection.Id,
            signedEnvelope.Certificate.Id.ToString(),
            ballot.SumProves.Count,
            parameters.ProofCount);
              throw new PiArgumentException(ExceptionCode.InvalidEnvelopeBadProofCount, "Invalid envelope. Number of sum prooves does not match.");
            }

            if (ballot.Votes.Count != question.Options.Count())
            {
              Logger.Log(LogLevel.Warning,
            "Connection {0}: Voter id {1} (verified) tried to vote, but there were {2} votes present for {3} options.",
            connection.Id,
            signedEnvelope.Certificate.Id.ToString(),
            ballot.Votes.Count,
            question.Options.Count());
              throw new PiArgumentException(ExceptionCode.InvalidEnvelopeBadVoteCount, "Invalid envelope. Vote count does not match.");
            }

            if (ballot.Votes.Any(vote => vote.RangeProves.Count != parameters.ProofCount))
            {
              Logger.Log(LogLevel.Warning,
            "Connection {0}: Voter id {1} (verified) tried to vote, but there was the wrong number of range proofs on a vote.",
            connection.Id,
            signedEnvelope.Certificate.Id.ToString());
              throw new PiArgumentException(ExceptionCode.InvalidEnvelopeBadProofCount, "Invalid envelope. Number of range prooves does not match.");
            }
              }

              bool hasVoted = DbConnection.ExecuteHasRows(
            "SELECT count(*) FROM envelope WHERE VotingId = @VotingId AND VoterId = @VoterId",
            "@VotingId", Id.ToByteArray(),
            "@VoterId", signedEnvelope.Certificate.Id.ToByteArray());
              if (hasVoted)
            throw new PiArgumentException(ExceptionCode.AlreadyVoted, "Voter has already voted.");

              MySqlTransaction transaction = DbConnection.BeginTransaction();

              MySqlCommand indexCommand = new MySqlCommand(
            "SELECT max(EnvelopeIndex) + 1 FROM envelope WHERE VotingId = @VotingId",
            DbConnection,
            transaction);
              indexCommand.Add("@VotingId", Id.ToByteArray());
              object indexObject = indexCommand.ExecuteScalar();
              int envelopeIndex = indexObject == DBNull.Value ? 1 : Convert.ToInt32(indexObject);

              MySqlCommand insertCommand = new MySqlCommand(
            "INSERT INTO envelope (VotingId, EnvelopeIndex, VoterId, Value) VALUES (@VotingId, @EnvelopeIndex, @VoterId, @Value)",
            DbConnection,
            transaction);
              insertCommand.Add("@VotingId", Id.ToByteArray());
              insertCommand.Add("@VoterId", signedEnvelope.Certificate.Id.ToByteArray());
              insertCommand.Add("@Value", signedEnvelope.ToBinary());
              insertCommand.Add("@EnvelopeIndex", envelopeIndex);
              insertCommand.ExecuteNonQuery();

              transaction.Commit();

              Logger.Log(LogLevel.Info,
            "Connection {0}: Envelope for certificate id {1} on voting id {2} stored.",
            connection.Id,
            signedEnvelope.Certificate.Id.ToString(),
            Id.ToString());

              VoteReceipt voteReceipt = new VoteReceipt(Parameters, signedEnvelope);

              return new Signed<VoteReceipt>(voteReceipt, this.serverCertificate);
        }
开发者ID:dbrgn,项目名称:pi-vote,代码行数:101,代码来源:VotingServerEntity.cs

示例2: DepositPartialDecipher

        /// <summary>
        /// Deposit partial deciphers from an authority.
        /// </summary>
        /// <param name="signedPartialDecipherList">Partial decipher list.</param>
        public void DepositPartialDecipher(
            IRpcConnection connection,
            Signed<PartialDecipherList> signedPartialDecipherList)
        {
            if (signedPartialDecipherList == null)
            throw new ArgumentNullException("partialDecipherContainer");

              if (Status != VotingStatus.Deciphering)
              {
            Logger.Log(LogLevel.Warning, "Authority id {0} (unverified) tried to deposit his partial decipher, but the status was {1}.", signedPartialDecipherList.Certificate.Id.ToString(), Status.ToString());
            throw new InvalidOperationException("Wrong status for operation.");
              }

              PartialDecipherList partialDecipherList = signedPartialDecipherList.Value;

              Certificate certificate = GetAuthority(partialDecipherList.AuthorityIndex);

              if (!signedPartialDecipherList.Verify(this.certificateStorage, Parameters.VotingBeginDate))
              {
            if (signedPartialDecipherList.VerifySimple())
            {
              Logger.Log(LogLevel.Warning, "Authority id {0} (unverified) tried to deposit his partial decipher, but his certificate had state {1}.", signedPartialDecipherList.Certificate.Id.ToString(), signedPartialDecipherList.Certificate.Validate(this.certificateStorage, Parameters.VotingBeginDate).Text());
            }
            else
            {
              Logger.Log(LogLevel.Warning, "Authority id {0} (unverified) tried to deposit his partial decipher, but the signature was invalid.", signedPartialDecipherList.Certificate.Id.ToString());
            }

            throw new PiArgumentException(ExceptionCode.InvalidSignature, "Bad signature.");
              }

              if (!signedPartialDecipherList.Certificate.IsIdentic(certificate))
              {
            Logger.Log(LogLevel.Warning, "Authority id {0} (verified) tried to deposit his partial decipher, but his certificate did not match id {1} for authority index {2}.", signedPartialDecipherList.Certificate.Id.ToString(), certificate.Id.ToString(), partialDecipherList.AuthorityIndex);
            throw new PiArgumentException(ExceptionCode.AuthorityInvalid, "Not signed by proper authority.");
              }

              if (partialDecipherList.PartialDeciphers.Count < 4)
              {
            Logger.Log(LogLevel.Warning, "Authority id {0} (verified) tried to deposit his partial decipher, but there were only {1} parts instead of 4.", signedPartialDecipherList.Certificate.Id.ToString(), partialDecipherList.PartialDeciphers.Count);
            throw new PiArgumentException(ExceptionCode.AuthorityCountMismatch, "Your Pi-Vote client is outdated.");
              }

              bool exists = DbConnection.ExecuteHasRows(
            "SELECT count(*) FROM deciphers WHERE VotingId = @VotingId AND AuthorityIndex = @AuthorityIndex",
            "@VotingId", Id.ToByteArray(),
            "@AuthorityIndex", partialDecipherList.AuthorityIndex);
              if (exists)
            throw new ArgumentException("Authority has already deposited shares.");

              MySqlCommand insertCommand = new MySqlCommand("INSERT INTO deciphers (VotingId, AuthorityIndex, Value) VALUES (@VotingId, @AuthorityIndex, @Value)", DbConnection);
              insertCommand.Add("@VotingId", Id.ToByteArray());
              insertCommand.Add("@AuthorityIndex", partialDecipherList.AuthorityIndex);
              insertCommand.Add("@Value", signedPartialDecipherList.ToBinary());
              insertCommand.ExecuteNonQuery();

              Logger.Log(LogLevel.Info, "Connection {0}: Partical deciphers for certificate id {1} on voting id {2} stored.", connection.Id, signedPartialDecipherList.Certificate.Id.ToString(), Id.ToString());

              long depositedShareResponseCount = (long)DbConnection.ExecuteScalar(
            "SELECT count(*) FROM deciphers WHERE VotingId = @VotingId",
            "@VotingId", Id.ToByteArray());

              SendAdminAuthorityActivityMail(certificate, "deposited partial deciphers");

              if (depositedShareResponseCount == this.parameters.Thereshold + 1)
              {
            Status = VotingStatus.Finished;
              }
        }
开发者ID:dbrgn,项目名称:pi-vote,代码行数:73,代码来源:VotingServerEntity.cs

示例3: DepositShares

        /// <summary>
        /// Deposit a share part from authorities.
        /// </summary>
        /// <param name="signedSharePart">Share part.</param>
        public void DepositShares(
            IRpcConnection connection,
            Signed<SharePart> signedSharePart)
        {
            if (signedSharePart == null)
            throw new ArgumentNullException("shares");

              if (Status != VotingStatus.New)
              {
            Logger.Log(LogLevel.Warning,
              "Connection {0}: Authority id {1} (unverified) tried to deposit shares, but the status was {2}.",
              connection.Id,
              signedSharePart.Certificate.Id.ToString(),
              Status.ToString());
            throw new PiArgumentException(ExceptionCode.WrongStatusForOperation, "Wrong status for operation.");
              }

              SharePart sharePart = signedSharePart.Value;

              Certificate certificate = GetAuthority(sharePart.AuthorityIndex);

              if (!signedSharePart.Verify(this.certificateStorage, Parameters.VotingBeginDate))
              {
            if (signedSharePart.VerifySimple())
            {
              Logger.Log(LogLevel.Warning,
            "Connection {0}: Authority id {1} (unverified) tried to deposit shares, but his certificate had state {2}.",
            connection.Id,
            signedSharePart.Certificate.Id.ToString(),
            signedSharePart.Certificate.Validate(this.certificateStorage, Parameters.VotingBeginDate).Text());
            }
            else
            {
              Logger.Log(LogLevel.Warning,
            "Connection {0}: Authority id {1} (unverified) tried to deposit shares, but the signature was invalid.",
            connection.Id,
            signedSharePart.Certificate.Id.ToString());
            }

            throw new PiSecurityException(ExceptionCode.InvalidSignature, "Bad signature.");
              }

              if (!signedSharePart.Certificate.IsIdentic(certificate))
              {
            Logger.Log(LogLevel.Warning,
              "Connection {0}: Authority id {1} (verified) tried to deposit shares, but his certificate did not match id {2} for authority index {3}.",
              connection.Id,
              signedSharePart.Certificate.Id.ToString(),
              certificate.Id.ToString(),
              sharePart.AuthorityIndex);
            throw new PiSecurityException(ExceptionCode.NoAuthorizedAuthority, "Not signed by proper authority.");
              }

              bool exists = DbConnection.ExecuteHasRows(
            "SELECT count(*) FROM sharepart WHERE VotingId = @VotingId AND AuthorityIndex = @AuthorityIndex",
            "@VotingId", Id.ToByteArray(),
            "@AuthorityIndex", sharePart.AuthorityIndex);

              if (exists)
              {
            Logger.Log(LogLevel.Warning,
              "Connection {0}: uthority id {1} (verified) tried to deposit shares, these were already present.",
              connection.Id,
              signedSharePart.Certificate.Id.ToString());
            throw new PiArgumentException(ExceptionCode.AuthorityHasAlreadyDeposited, "Authority has already deposited shares.");
              }

              MySqlCommand insertCommand = new MySqlCommand("INSERT INTO sharepart (VotingId, AuthorityIndex, Value) VALUES (@VotingId, @AuthorityIndex, @Value)", DbConnection);
              insertCommand.Add("@VotingId", Id.ToByteArray());
              insertCommand.Add("@AuthorityIndex", sharePart.AuthorityIndex);
              insertCommand.Add("@Value", signedSharePart.ToBinary());
              insertCommand.ExecuteNonQuery();

              Logger.Log(LogLevel.Info,
            "Connection {0}: Shares for certificate id {1} on voting id {2} stored.",
            connection.Id,
            signedSharePart.Certificate.Id.ToString(), Id.ToString());

              long depositedSharePartCount = (long)DbConnection.ExecuteScalar(
            "SELECT count(*) FROM sharepart WHERE VotingId = @VotingId",
            "@VotingId", Id.ToByteArray());

              SendAdminAuthorityActivityMail(certificate, "deposited shares");

              if (depositedSharePartCount == this.parameters.AuthorityCount)
              {
            Status = VotingStatus.Sharing;
              }
        }
开发者ID:dbrgn,项目名称:pi-vote,代码行数:93,代码来源:VotingServerEntity.cs

示例4: AddAuthority

        /// <summary>
        /// Add an authority.
        /// </summary>
        /// <param name="certificate">Authority to be added.</param>
        /// <returns>Index of the authority.</returns>
        public int AddAuthority(
            IRpcConnection connection,
            Certificate certificate)
        {
            if (certificate == null)
            throw new ArgumentNullException("certificate");
              if (certificate.Validate(this.certificateStorage) != CertificateValidationResult.Valid)
            throw new PiSecurityException(ExceptionCode.InvalidCertificate, "Authority certificate not valid.");
              if (!(certificate is AuthorityCertificate))
            throw new PiSecurityException(ExceptionCode.NoAuthorizedAuthority, "No an authority certificate.");

              MySqlTransaction transaction = DbConnection.BeginTransaction();

              MySqlCommand countCommand = new MySqlCommand("SELECT count(*) FROM authority WHERE VotingId = @VotingId", DbConnection, transaction);
              countCommand.Add("@VotingId", this.parameters.VotingId.ToByteArray());
              if ((long)countCommand.ExecuteScalar() >= this.parameters.AuthorityCount)
            throw new PiArgumentException(ExceptionCode.AlreadyEnoughAuthorities, "Already enough authorities.");

              MySqlCommand addedCommand = new MySqlCommand("SELECT count(*) FROM authority WHERE VotingId = @VotingId AND AuthorityId = @AuthorityId", DbConnection, transaction);
              addedCommand.Add("@VotingId", this.parameters.VotingId.ToByteArray());
              addedCommand.Add("@AuthorityId", certificate.Id.ToByteArray());
              if (addedCommand.ExecuteHasRows())
            throw new PiArgumentException(ExceptionCode.AuthorityAlreadyInVoting, "Already an authority of the voting.");

              MySqlCommand indexCommand = new MySqlCommand("SELECT max(AuthorityIndex) + 1 FROM authority WHERE VotingId = @VotingId", DbConnection, transaction);
              indexCommand.Add("@VotingId", this.parameters.VotingId.ToByteArray());
              object authorityIndexNull = indexCommand.ExecuteScalar();
              int authorityIndex = authorityIndexNull == DBNull.Value ? 1 : Convert.ToInt32((long)authorityIndexNull);

              MySqlCommand insertCommand = new MySqlCommand("INSERT INTO authority (VotingId, AuthorityIndex, AuthorityId, Certificate) VALUES (@VotingId, @AuthorityIndex, @AuthorityId, @Certificate)", DbConnection, transaction);
              insertCommand.Parameters.AddWithValue("@VotingId", this.parameters.VotingId.ToByteArray());
              insertCommand.Parameters.AddWithValue("@AuthorityIndex", authorityIndex);
              insertCommand.Parameters.AddWithValue("@AuthorityId", certificate.Id.ToByteArray());
              insertCommand.Parameters.AddWithValue("@Certificate", certificate.ToBinary());
              insertCommand.ExecuteNonQuery();

              Logger.Log(LogLevel.Info, "Connection {0}: Authority id {1} added to voting id {2}", connection.Id, certificate.Id.ToString(), Id.ToString());

              transaction.Commit();

              return authorityIndex;
        }
开发者ID:dbrgn,项目名称:pi-vote,代码行数:47,代码来源:VotingServerEntity.cs


注:本文中的MySql.Data.MySqlClient.MySqlCommand.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。