/// <summary>
 /// Creates a vault
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.RecoveryServices.IVaultOperations.
 /// </param>
 /// <param name='cloudServiceName'>
 /// Required. The name of the cloud service containing the job
 /// collection.
 /// </param>
 /// <param name='vaultName'>
 /// Required. The name of the vault to create.
 /// </param>
 /// <param name='vaultCreationInput'>
 /// Required. Vault object to be created
 /// </param>
 /// <returns>
 /// The response model for the Vm group object.
 /// </returns>
 public static VaultCreateResponse BeginCreating(this IVaultOperations operations, string cloudServiceName, string vaultName, VaultCreateArgs vaultCreationInput)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IVaultOperations)s).BeginCreatingAsync(cloudServiceName, vaultName, vaultCreationInput);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
        /// <summary>
        /// ProcessRecord of the command.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            try
            {
                this.WriteWarningWithTimestamp(
                    string.Format(
                        Properties.Resources.CmdletWillBeDeprecatedSoon,
                        this.MyInvocation.MyCommand.Name));

                string cloudServiceName = Utilities.GenerateCloudServiceName(this.Location);
                byte[] bytes = System.Text.Encoding.UTF8.GetBytes(cloudServiceName);
                string base64Label = Convert.ToBase64String(bytes);

                CloudServiceCreateArgs cloudServiceCreateArgs = new CloudServiceCreateArgs()
                {
                    GeoRegion = this.Location,
                    Label = base64Label,
                    Description = base64Label
                };

                RecoveryServicesClient.FindOrCreateCloudService(cloudServiceName, cloudServiceCreateArgs);

                VaultCreateArgs vaultCreateArgs = new VaultCreateArgs()
                {
                    Name = this.Name,
                    Plan = string.Empty,
                    ResourceProviderNamespace = Constants.ResourceNamespace,
                    Type = Constants.ASRVaultType,
                    ETag = Guid.NewGuid().ToString(),
                    SchemaVersion = Constants.RpSchemaVersion
                };

                RecoveryServicesOperationStatusResponse response = RecoveryServicesClient.CreateVault(cloudServiceName, this.Name, vaultCreateArgs);

                VaultOperationOutput output = new VaultOperationOutput()
                {
                    Response = response.StatusCode == HttpStatusCode.OK ? Resources.VaultCreationSuccessMessage : response.StatusCode.ToString()
                };

                this.WriteObject(output, true);
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
 /// <summary>
 /// Method to create Azure Site Recovery Vault
 /// </summary>
 /// <param name="cloudServiceName">name of the cloud service</param>
 /// <param name="vaultName">name of the vault</param>
 /// <param name="vaultCreateInput">vault creation input object</param>
 /// <returns>creation response object.</returns>
 public RecoveryServicesOperationStatusResponse CreateVault(string cloudServiceName, string vaultName, VaultCreateArgs vaultCreateInput)
 {
     return this.GetRecoveryServicesClient.Vaults.Create(cloudServiceName, vaultName, vaultCreateInput);
 }
 /// <summary>
 /// Creates a vault
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.RecoveryServices.IVaultOperations.
 /// </param>
 /// <param name='cloudServiceName'>
 /// Required. The name of the cloud service containing the job
 /// collection.
 /// </param>
 /// <param name='vaultName'>
 /// Required. The name of the vault to create.
 /// </param>
 /// <param name='vaultCreationInput'>
 /// Required. Vault object to be created
 /// </param>
 /// <returns>
 /// The response model for the Vm group object.
 /// </returns>
 public static Task<VaultCreateResponse> BeginCreatingAsync(this IVaultOperations operations, string cloudServiceName, string vaultName, VaultCreateArgs vaultCreationInput)
 {
     return operations.BeginCreatingAsync(cloudServiceName, vaultName, vaultCreationInput, CancellationToken.None);
 }
 /// <summary>
 /// Creates a vault
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.RecoveryServices.IVaultOperations.
 /// </param>
 /// <param name='cloudServiceName'>
 /// Required. The name of the cloud service containing the job
 /// collection.
 /// </param>
 /// <param name='vaultName'>
 /// Required. The name of the vault to create.
 /// </param>
 /// <param name='vaultCreationInput'>
 /// Required. Vault object to be created
 /// </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 Task<RecoveryServicesOperationStatusResponse> CreateAsync(this IVaultOperations operations, string cloudServiceName, string vaultName, VaultCreateArgs vaultCreationInput)
 {
     return operations.CreateAsync(cloudServiceName, vaultName, vaultCreationInput, CancellationToken.None);
 }