/// <summary>
 /// Manage (CUD) VPN configuration 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 ManageVirtualNetworks
 /// operation.
 /// </param>
 /// <returns>
 /// The response of the CreateOrUpdate Api Management service long
 /// running operation.
 /// </returns>
 public static ApiServiceLongRunningOperationResponse ManageVirtualNetworks(this IApiManagementOperations operations, string resourceGroupName, string name, ApiServiceManageVirtualNetworksParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IApiManagementOperations)s).ManageVirtualNetworksAsync(resourceGroupName, name, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// Manage (CUD) VPN configuration 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 ManageVirtualNetworks
 /// operation.
 /// </param>
 /// <returns>
 /// The response of the CreateOrUpdate Api Management service long
 /// running operation.
 /// </returns>
 public static Task<ApiServiceLongRunningOperationResponse> ManageVirtualNetworksAsync(this IApiManagementOperations operations, string resourceGroupName, string name, ApiServiceManageVirtualNetworksParameters parameters)
 {
     return operations.ManageVirtualNetworksAsync(resourceGroupName, name, parameters, CancellationToken.None);
 }
        public ApiManagementLongRunningOperation BeginManageVirtualNetworks(
            string resourceGroupName, 
            string serviceName, 
            IList<PsApiManagementVirtualNetwork> virtualNetworks)
        {
            var parameters = new ApiServiceManageVirtualNetworksParameters
            {
                VirtualNetworkConfigurations = (virtualNetworks == null || virtualNetworks.Count == 0)
                    ? null
                    : virtualNetworks.Select(vn =>
                        new VirtualNetworkConfiguration
                        {
                            Location = vn.Location,
                            SubnetName = vn.SubnetName,
                            VnetId = vn.VnetId
                        }).ToList()
            };

            var longrunningResponse = Client.ResourceProvider.BeginManagingVirtualNetworks(resourceGroupName, serviceName, parameters);
            AdjustRetryAfter(longrunningResponse, _client.LongRunningOperationInitialTimeout);
            return ApiManagementLongRunningOperation.CreateLongRunningOperation("Set-AzureRmApiManagementVirtualNetworks", longrunningResponse);
        }