/// <summary>
 /// Upload SSL certificate for an Api Management service.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.ApiManagement.IApiManagementOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='name'>
 /// Required. The name of the Api Management service.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Upload SSL certificate for an
 /// Api Management service operation.
 /// </param>
 /// <returns>
 /// The response of the Upload SSL certificate for an Api Management
 /// service operation.
 /// </returns>
 public static ApiServiceUploadCertificateResponse UploadCertificate(this IApiManagementOperations operations, string resourceGroupName, string name, ApiServiceUploadCertificateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IApiManagementOperations)s).UploadCertificateAsync(resourceGroupName, name, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// Upload SSL certificate for an Api Management service.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.ApiManagement.IApiManagementOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='name'>
 /// Required. The name of the Api Management service.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Upload SSL certificate for an
 /// Api Management service operation.
 /// </param>
 /// <returns>
 /// The response of the Upload SSL certificate for an Api Management
 /// service operation.
 /// </returns>
 public static Task<ApiServiceUploadCertificateResponse> UploadCertificateAsync(this IApiManagementOperations operations, string resourceGroupName, string name, ApiServiceUploadCertificateParameters parameters)
 {
     return operations.UploadCertificateAsync(resourceGroupName, name, parameters, CancellationToken.None);
 }
        public PsApiManagementHostnameCertificate UploadCertificate(
            string resourceGroupName,
            string serviceName,
            PsApiManagementHostnameType hostnameType,
            string pfxPath,
            string pfxPassword)
        {
            byte[] certificate;
            using (var certStream = File.OpenRead(pfxPath))
            {
                certificate = new byte[certStream.Length];
                certStream.Read(certificate, 0, certificate.Length);
            }
            var encodedCertificate = Convert.ToBase64String(certificate);

            var parameters = new ApiServiceUploadCertificateParameters(MapHostnameType(hostnameType), encodedCertificate, pfxPassword);
            var result = Client.ResourceProvider.UploadCertificate(resourceGroupName, serviceName, parameters);

            return new PsApiManagementHostnameCertificate(result.Value);
        }