/// <summary>
        /// Create a certificate order
        /// </summary>
        /// <param name="bearerToken">The Azure bearer token</param>
        /// <param name="subscription">Subscription Id for authorization</param>
        /// <param name="resourceGroupName">Name of the resource group to place the new certificate in</param>
        /// <param name="orderNickname">A nickname for the order</param>
        /// <param name="certificateRequestText">The text content of a certificate request (CSR)</param>
        /// <param name="autoRenew">Set to TRUE to autorenew the certificate at the end of the specified validity period</param>
        /// <param name="type">Type of certificate (WARNING: selection has cost implications!)</param>
        /// <param name="validityPeriod">Period in years, that the issued certificate will be valid for</param>
        /// <returns>Details of the placed order</returns>
        public static async Task <CertificateOrderDetail?> OrderUsingCSR(string bearerToken, Guid subscription, string resourceGroupName, string orderNickname,
                                                                         string certificateRequestText, bool autoRenew = true, CertificateTypesEnum type = CertificateTypesEnum.StandardDomainValidatedSsl,
                                                                         CertificateValidityPeriod validityPeriod      = CertificateValidityPeriod.OneYear)
        {
            if (string.IsNullOrWhiteSpace(bearerToken))
            {
                throw new ArgumentNullException(nameof(bearerToken));
            }
            if (subscription == Guid.Empty)
            {
                throw new ArgumentNullException(nameof(subscription));
            }
            if (string.IsNullOrWhiteSpace(resourceGroupName))
            {
                throw new ArgumentNullException(nameof(resourceGroupName));
            }
            if (string.IsNullOrWhiteSpace(orderNickname))
            {
                throw new ArgumentNullException(nameof(orderNickname));
            }
            if (string.IsNullOrWhiteSpace(certificateRequestText))
            {
                throw new ArgumentNullException(nameof(certificateRequestText));
            }

            AppServiceCertificateOrderRequest request = new AppServiceCertificateOrderRequest()
            {
                Location   = "global",
                Name       = orderNickname,
                Properties = new AppServiceCertificateOrderRequestProperties()
                {
                    AppServiceDomainName = null,
                    AutoRenew            = autoRenew,
                    KeySize = CertificateKeySizesEnum.Default,
                    LastGeneratedCertificateRequestText = certificateRequestText,
                    Type     = type,
                    Validity = validityPeriod
                }
            };

            RestApiResponse response = await RestApiClient.PUT(
                bearerToken,
                $"https://management.azure.com/subscriptions/{subscription:d}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{orderNickname}",
                CLIENT_API_VERSION,
                null,
                request,
                new int[] { 200, 201 }
                );

            if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body))
            {
                return(null);
            }

            return(JsonConvert.DeserializeObject <CertificateOrderDetail>(response.Body));
        }
コード例 #2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            //国籍资料
            String BoatName    = textBoatName.Text;
            String CerNo       = textCerNo.Text.Trim();
            String CerDeadLine = textCerDeadLine.Text;
            String BoatMan     = textBoatMan.Text;
            String CerOutDate  = textCerOutDate.Text;
            String CerOut      = textCerOut.Text;

            //历史操作
            OperationHistory OH = new OperationHistory();

            OH.userID         = DataBase.userID;
            OH.operationDate  = DateTime.Now.ToString();
            OH.operationNanme = "船舶国籍更改";

            //证书有效期
            CertificateValidityPeriod validDate = new CertificateValidityPeriod();

            validDate.shipName         = textBoatName.Text.Trim();
            validDate.certificateName  = "船舶国籍";
            validDate.certificateLimit = textCerDeadLine.Text;
            validDate.certificateNo    = textCerNo.Text.Trim();

            //通知时间
            DateTime dt = new DateTime();

            try
            {
                dt = DateTime.ParseExact(validDate.certificateLimit, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture);
                dt = dt.AddDays(-3); //通知时间为期限的前3天
            }
            catch (Exception et)
            {
                MessageBox.Show(et.Message + ",输入的日期格式不正确", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //连接数据库
            SqlConnection conn = DataBase.Connect();

            String str  = "UPDATE 船舶国籍证书 SET 船名 = '" + BoatName + "', 证书编号 = '" + CerNo + "', 证书有效期 = '" + CerDeadLine + "', 船舶所有人 = '" + BoatMan + "', 发证日期 = '" + CerOutDate + "', 发证机关及其编号 = '" + CerOut + "'";
            String str1 = "select * from 船只基本资料 where 船只名称 = '" + BoatName + "'";
            String str2 = "UPDATE 各证书有效期 SET 证书名 = '" + validDate.certificateName + "', 证书有效期至 = '" + validDate.certificateLimit + "', 通知时间 = '" + dt.ToString("yyyy-MM-dd") + "'";
            String str3 = "INSERT INTO 用户重要操作历史表 VALUES ('" + OH.userID + "', '" + OH.operationDate + "', '" + OH.operationNanme + "')";

            try
            {
                if (!DataBase.Inquire(str1, conn))
                {
                    MessageBox.Show("船只不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (DataBase.Insert(str, conn))
                {
                    MessageBox.Show("更改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }

                DataBase.Update(str2, conn);    //更新证书有效期表
                DataBase.Insert(str3, conn);    //记录该操作
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "更改失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                DataBase.Close(conn);
            }
        }
コード例 #3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            //营运证资料
            OperatingCertificates operatingCertificates = new OperatingCertificates();

            operatingCertificates.BoatName       = textBoatName.Text.Trim();
            operatingCertificates.CerNo          = lblYY.Text.Trim() + textCerNo.Text.Trim();
            operatingCertificates.CerType        = textCerType.Text.Trim();
            operatingCertificates.CerOut         = textCerOut.Text;
            operatingCertificates.CerOutDate     = textCerOutDate.Text;
            operatingCertificates.CerOutNo       = textCerOutNo.Text.Trim();
            operatingCertificates.DeadLine       = textDeadLine.Text;
            operatingCertificates.BoatRunnerName = textBoatRunnerName.Text.Trim();
            operatingCertificates.RunnerNo       = textRunnerNo.Text.Trim();

            //历史操作
            OperationHistory OH = new OperationHistory();

            OH.userID         = DataBase.userID;
            OH.operationDate  = DateTime.Now.ToString();
            OH.operationNanme = "营运证添加";

            //证书有效期
            CertificateValidityPeriod validDate = new CertificateValidityPeriod();

            validDate.shipName         = textBoatName.Text.Trim();
            validDate.certificateName  = "船舶营运证";
            validDate.certificateLimit = textDeadLine.Text;
            validDate.certificateNo    = lblYY.Text.Trim() + textCerNo.Text.Trim();

            //通知时间
            DateTime dt = new DateTime();

            try
            {
                dt = DateTime.ParseExact(validDate.certificateLimit, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture);
                dt = dt.AddDays(-3); //通知时间为期限的前3天
            }
            catch (Exception et)
            {
                MessageBox.Show(et.Message + ",输入的日期格式不正确", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //连接数据库
            SqlConnection conn = DataBase.Connect();

            String str  = "INSERT INTO 船舶营运证 VALUES ('" + operatingCertificates.BoatName + "', '" + operatingCertificates.CerNo + "', '" + operatingCertificates.CerType + "', '" + operatingCertificates.BoatRunnerName + "', '" + operatingCertificates.RunnerNo + "', '" + operatingCertificates.CerOut + "', '" + operatingCertificates.CerOutNo + "', '" + operatingCertificates.CerOutDate + "', '" + operatingCertificates.DeadLine + "')";
            String str1 = "select * from 船只基本资料 where 船只名称 = '" + operatingCertificates.BoatName + "'";
            String str2 = "INSERT INTO 各证书有效期 VALUES ('" + validDate.shipName + "', '" + validDate.certificateNo + "', '" + validDate.certificateName + "','" + validDate.certificateLimit + "','" + dt.ToString("yyyy-MM-dd") + "')";
            String str3 = "INSERT INTO 用户重要操作历史表 VALUES ('" + OH.userID + "', '" + OH.operationDate + "', '" + OH.operationNanme + "')";

            try
            {
                if (!DataBase.Inquire(str1, conn))
                {
                    MessageBox.Show("船只不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (DataBase.Insert(str, conn))
                {
                    MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }

                DataBase.Insert(str2, conn);    //插入证书有效期表
                DataBase.Insert(str3, conn);    //记录该操作
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "添加失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                DataBase.Close(conn);
            }
        }