/// <summary>
 /// Manage (CUD) deployments of 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 ManageDeployments operation.
 /// </param>
 /// <returns>
 /// The response of the CreateOrUpdate Api Management service long
 /// running operation.
 /// </returns>
 public static ApiServiceLongRunningOperationResponse ManageDeployments(this IApiManagementOperations operations, string resourceGroupName, string name, ApiServiceManageDeploymentsParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IApiManagementOperations)s).ManageDeploymentsAsync(resourceGroupName, name, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// Manage (CUD) deployments of 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 ManageDeployments operation.
 /// </param>
 /// <returns>
 /// The response of the CreateOrUpdate Api Management service long
 /// running operation.
 /// </returns>
 public static Task<ApiServiceLongRunningOperationResponse> ManageDeploymentsAsync(this IApiManagementOperations operations, string resourceGroupName, string name, ApiServiceManageDeploymentsParameters parameters)
 {
     return operations.ManageDeploymentsAsync(resourceGroupName, name, parameters, CancellationToken.None);
 }
        public ApiManagementLongRunningOperation BeginUpdateDeployments(
            string resourceGroupName,
            string serviceName,
            string location,
            PsApiManagementSku sku,
            int capacity,
            PsApiManagementVirtualNetwork vnetConfiguration,
            IList<PsApiManagementRegion> additionalRegions)
        {
            var parameters = new ApiServiceManageDeploymentsParameters(location, MapSku(sku))
            {
                SkuUnitCount = capacity
            };

            if (vnetConfiguration != null)
            {
                parameters.VirtualNetworkConfiguration = new VirtualNetworkConfiguration
                {
                    Location = vnetConfiguration.Location,
                    SubnetName = vnetConfiguration.SubnetName,
                    VnetId = vnetConfiguration.VnetId
                };
            }

            if (additionalRegions != null && additionalRegions.Any())
            {
                parameters.AdditionalRegions =
                    additionalRegions
                        .Select(region =>
                            new AdditionalRegion
                            {
                                Location = region.Location,
                                SkuType = MapSku(region.Sku),
                                SkuUnitCount = region.Capacity,
                                VirtualNetworkConfiguration = region.VirtualNetwork == null
                                    ? null
                                    : new VirtualNetworkConfiguration
                                    {
                                        Location = region.VirtualNetwork.Location,
                                        SubnetName = region.VirtualNetwork.SubnetName,
                                        VnetId = region.VirtualNetwork.VnetId
                                    }
                            })
                        .ToList();
            }

            var longrunningResponse = Client.ResourceProvider.BeginManagingDeployments(resourceGroupName, serviceName, parameters);
            AdjustRetryAfter(longrunningResponse, _client.LongRunningOperationInitialTimeout);
            return ApiManagementLongRunningOperation.CreateLongRunningOperation("Update-AzureRmApiManagementDeployment", longrunningResponse);
        }