public void ExecuteCommand()
        {
            var prodDeployment = GetDeploymentBySlot(DeploymentSlotType.Production);
            var stagingDeployment = GetDeploymentBySlot(DeploymentSlotType.Staging);

            if(stagingDeployment == null && prodDeployment == null)
            {
                throw new ArgumentOutOfRangeException(String.Format(Resources.NoDeploymentInStagingOrProduction, ServiceName));
            }

            if(stagingDeployment == null && prodDeployment != null)
            {
                throw new ArgumentOutOfRangeException(String.Format(Resources.NoDeploymentInStaging, ServiceName));
            }

            if(prodDeployment == null)
            {
                this.WriteVerbose(string.Format(Resources.MovingDeploymentFromStagingToProduction, ServiceName));
            }
            else
            {
                this.WriteVerbose(string.Format(Resources.VIPSwapBetweenStagingAndProduction, ServiceName));
            }

            var swapDeploymentParams = new DeploymentSwapParameters
            {
                SourceDeployment = stagingDeployment.Name,
                ProductionDeployment = prodDeployment == null ? null : prodDeployment.Name
            };

            ExecuteClientActionNewSM(
                swapDeploymentParams,
                CommandRuntime.ToString(),
                () => this.ComputeClient.Deployments.Swap(ServiceName, swapDeploymentParams));
        }
 /// <summary>
 ///     Swap deployment from/to production or testing
 /// </summary>
 /// <param name="hostedServiceName"></param>
 /// <param name="input"></param>
 public void SwapDeployment(string hostedServiceName, DeploymentSwapParameters input)
 {
     ComputeManagementClient.Deployments.SwapAsync(hostedServiceName, input, new CancellationToken()).Wait();
 }
 /// <summary>
 /// The Swap Deployment operation initiates a virtual IP address swap
 /// between the staging and production deployment environments for a
 /// service. If the service is currently running in the staging
 /// environment, it will be swapped to the production environment. If
 /// it is running in the production environment, it will be swapped to
 /// staging. For more information on this type of upgrade, see
 /// Performing Virtual IP Swap Upgrades at
 /// http://msdn.microsoft.com/en-us/library/windowsazure/ee517253.aspx.
 /// (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/ee460814.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IDeploymentOperations.
 /// </param>
 /// <param name='serviceName'>
 /// Required. The cloud service to swap deployments for.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Swap Deployment 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 error information regarding
 /// the failure.
 /// </returns>
 public static Task<OperationStatusResponse> SwapAsync(this IDeploymentOperations operations, string serviceName, DeploymentSwapParameters parameters)
 {
     return operations.SwapAsync(serviceName, parameters, CancellationToken.None);
 }
 /// <summary>
 /// The Swap Deployment operation initiates a virtual IP address swap
 /// between the staging and production deployment environments for a
 /// service. If the service is currently running in the staging
 /// environment, it will be swapped to the production environment. If
 /// it is running in the production environment, it will be swapped to
 /// staging. For more information on this type of upgrade, see
 /// Performing Virtual IP Swap Upgrades at
 /// http://msdn.microsoft.com/en-us/library/windowsazure/ee517253.aspx.
 /// (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/ee460814.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IDeploymentOperations.
 /// </param>
 /// <param name='serviceName'>
 /// Required. The cloud service to swap deployments for.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Swap Deployment 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 error information regarding
 /// the failure.
 /// </returns>
 public static OperationStatusResponse Swap(this IDeploymentOperations operations, string serviceName, DeploymentSwapParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IDeploymentOperations)s).SwapAsync(serviceName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// The Begin Swapping Deployment operation initiates a virtual IP
 /// address swap between the staging and production deployment
 /// environments for a service. If the service is currently running in
 /// the staging environment, it will be swapped to the production
 /// environment. If it is running in the production environment, it
 /// will be swapped to staging. For more information on this type of
 /// upgrade, see Performing Virtual IP Swap Upgrades at
 /// http://msdn.microsoft.com/en-us/library/windowsazure/ee517253.aspx.
 /// (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/ee460814.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IDeploymentOperations.
 /// </param>
 /// <param name='serviceName'>
 /// Required. The cloud service to swap deployments for.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Begin Swapping Deployment
 /// operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<AzureOperationResponse> BeginSwappingAsync(this IDeploymentOperations operations, string serviceName, DeploymentSwapParameters parameters)
 {
     return operations.BeginSwappingAsync(serviceName, parameters, CancellationToken.None);
 }
 /// <summary>
 /// The Swap Deployment operation initiates a virtual IP address swap
 /// between the staging and production deployment environments for a
 /// service. If the service is currently running in the staging
 /// environment, it will be swapped to the production environment. If
 /// it is running in the production environment, it will be swapped to
 /// staging. For more information on this type of upgrade, see
 /// Performing Virtual IP Swap Upgrades.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/ee460814.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IDeploymentOperations.
 /// </param>
 /// <param name='serviceName'>
 /// The cloud service to swap deployments for.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Swap Deployment operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static OperationResponse BeginSwapping(this IDeploymentOperations operations, string serviceName, DeploymentSwapParameters parameters)
 {
     try
     {
         return operations.BeginSwappingAsync(serviceName, parameters).Result;
     }
     catch (AggregateException ex)
     {
         if (ex.InnerExceptions.Count > 1)
         {
             throw;
         }
         else
         {
             throw ex.InnerException;
         }
     }
 }
 /// <summary>
 /// The Swap Deployment operation initiates a virtual IP address swap
 /// between the staging and production deployment environments for a
 /// service. If the service is currently running in the staging
 /// environment, it will be swapped to the production environment. If
 /// it is running in the production environment, it will be swapped to
 /// staging. For more information on this type of upgrade, see
 /// Performing Virtual IP Swap Upgrades.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/ee460814.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IDeploymentOperations.
 /// </param>
 /// <param name='serviceName'>
 /// The cloud service to swap deployments for.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Swap Deployment 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 ComputeOperationStatusResponse Swap(this IDeploymentOperations operations, string serviceName, DeploymentSwapParameters parameters)
 {
     try
     {
         return operations.SwapAsync(serviceName, parameters).Result;
     }
     catch (AggregateException ex)
     {
         if (ex.InnerExceptions.Count > 1)
         {
             throw;
         }
         else
         {
             throw ex.InnerException;
         }
     }
 }
        protected PSArgument[] CreateDeploymentSwapParameters()
        {
            string serviceName = string.Empty;
            DeploymentSwapParameters parameters = new DeploymentSwapParameters();

            return ConvertFromObjectsToArguments(new string[] { "ServiceName", "Parameters" }, new object[] { serviceName, parameters });
        }