public void Undo()
 {
     if (oldGetGatewayResponse.State == GatewayProvisioningEventStates.Provisioned)
     {
         GatewayCreateParameters createParameters = new GatewayCreateParameters()
         {
             GatewayType = oldGetGatewayResponse.GatewayType,
         };
         gatewayClient.Create(virtualNetworkSiteName, createParameters);
     }
 }
        protected override void OnProcessRecord()
        {
            GatewayCreateParameters parameters = new GatewayCreateParameters()
            {
                GatewayType = this.GatewayType,
            };

            ServiceManagementProfile.Initialize();
            ExecuteClientActionNewSM(
                null,
                this.CommandRuntime.ToString(),
                () => this.NetworkClient.Gateways.Create(this.VNetName, parameters));
        }
        private void EnsureGatewayExists(GatewayCreateParameters createGatewayParameters)
        {
            bool gatewayExists = false;
            while (gatewayExists == false)
            {
                GatewayGetResponse getGatewayResponse = GetGateway(NetworkTestConstants.VirtualNetworkSiteName);
                switch (getGatewayResponse.State)
                {
                    case GatewayProvisioningEventStates.NotProvisioned:
                        CreateGateway(NetworkTestConstants.VirtualNetworkSiteName, createGatewayParameters);
                        break;

                    case GatewayProvisioningEventStates.Provisioning:
                    case GatewayProvisioningEventStates.Deprovisioning:
                        Thread.Sleep(TimeSpan.FromSeconds(10));
                        break;

                    case GatewayProvisioningEventStates.Provisioned:
                        gatewayExists = true;
                        break;
                }
            }
        }
 /// <summary>
 /// The Create Virtual network Gateway operation creates a new network
 /// gateway for the specified virtual network in Azure.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/jj154119.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Network.IGatewayOperations.
 /// </param>
 /// <param name='networkName'>
 /// Required. The name of the virtual network for this gateway.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Virtual Network Gateway
 /// operation.
 /// </param>
 /// <returns>
 /// The response body contains the status of the specified asynchronous
 /// operation, indicating whether it has succeeded, is in progress, or
 /// has failed. Note that this status is distinct from the HTTP status
 /// code returned for the Get Operation Status operation itself. If
 /// the asynchronous operation succeeded, the response body includes
 /// the HTTP status code for the successful request. If the
 /// asynchronous operation failed, the response body includes the HTTP
 /// status code for the failed request, and also includes error
 /// information regarding the failure.
 /// </returns>
 public static Task<GatewayGetOperationStatusResponse> CreateAsync(this IGatewayOperations operations, string networkName, GatewayCreateParameters parameters)
 {
     return operations.CreateAsync(networkName, parameters, CancellationToken.None);
 }
 /// <summary>
 /// The Create Virtual network Gateway operation creates a new network
 /// gateway for the specified virtual network in Azure.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/jj154119.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Network.IGatewayOperations.
 /// </param>
 /// <param name='networkName'>
 /// Required. The name of the virtual network for this gateway.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Virtual Network Gateway
 /// operation.
 /// </param>
 /// <returns>
 /// The response body contains the status of the specified asynchronous
 /// operation, indicating whether it has succeeded, is in progress, or
 /// has failed. Note that this status is distinct from the HTTP status
 /// code returned for the Get Operation Status operation itself. If
 /// the asynchronous operation succeeded, the response body includes
 /// the HTTP status code for the successful request. If the
 /// asynchronous operation failed, the response body includes the HTTP
 /// status code for the failed request, and also includes error
 /// information regarding the failure.
 /// </returns>
 public static GatewayGetOperationStatusResponse Create(this IGatewayOperations operations, string networkName, GatewayCreateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IGatewayOperations)s).CreateAsync(networkName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// The Begin Creating Virtual network Gateway operation creates a new
 /// network gateway for the specified virtual network in Azure.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/jj154119.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Network.IGatewayOperations.
 /// </param>
 /// <param name='networkName'>
 /// Required. The name of the virtual network for this gateway.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Begin Creating Virtual Network
 /// Gateway operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<GatewayOperationResponse> BeginCreatingAsync(this IGatewayOperations operations, string networkName, GatewayCreateParameters parameters)
 {
     return operations.BeginCreatingAsync(networkName, parameters, CancellationToken.None);
 }
        public GatewayGetOperationStatusResponse CreateGateway(string virtualNetworkSiteName, GatewayCreateParameters parameters)
        {
            CreateGateway operation = new CreateGateway(gatewayClient, virtualNetworkSiteName, parameters);

            testClient.InvokeTestOperation(operation);

            return operation.InvokeResponse;
        }
 public CreateGateway(IGatewayOperations gatewayClient, string virtualNetworkSiteName, GatewayCreateParameters parameters)
 {
     this.gatewayClient = gatewayClient;
     this.virtualNetworkSiteName = virtualNetworkSiteName;
     this.parameters = parameters;
 }
 /// <summary>
 /// The Create Virtual network Gateway operation creates a new network
 /// gateways account in Windows Azure.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/jj154119.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Network.IGatewayOperations.
 /// </param>
 /// <param name='virtualNetworkName'>
 /// The name of the virtual network for this gateway.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Create Virtual Network Gateway operation.
 /// </param>
 /// <returns>
 /// The response body contains the status of the specified asynchronous
 /// operation, indicating whether it has succeeded, is inprogress, or
 /// has failed. Note that this status is distinct from the HTTP status
 /// code returned for the Get Operation Status operation itself.  If
 /// the asynchronous operation succeeded, the response body includes
 /// the HTTP status code for the successful request.  If the
 /// asynchronous operation failed, the response body includes the HTTP
 /// status code for the failed request, and also includes error
 /// information regarding the failure.
 /// </returns>
 public static GatewayGetOperationStatusResponse Create(this IGatewayOperations operations, string virtualNetworkName, GatewayCreateParameters parameters)
 {
     try
     {
         return operations.CreateAsync(virtualNetworkName, parameters).Result;
     }
     catch (AggregateException ex)
     {
         if (ex.InnerExceptions.Count > 1)
         {
             throw;
         }
         else
         {
             throw ex.InnerException;
         }
     }
 }