/// <summary>
 /// Creates a database in an Azure SQL Database Server.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Sql.IDatabaseOperations.
 /// </param>
 /// <param name='serverName'>
 /// Required. The name of the Azure SQL Database Server where the
 /// database will be created.
 /// </param>
 /// <param name='parameters'>
 /// Required. The parameters for the create database operation.
 /// </param>
 /// <returns>
 /// Represents the response to a create database request from the
 /// service.
 /// </returns>
 public static DatabaseCreateResponse Create(this IDatabaseOperations operations, string serverName, DatabaseCreateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IDatabaseOperations)s).CreateAsync(serverName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// The Create Database operation creates a database in a SQL Server
 /// database server.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Sql.IDatabaseOperations.
 /// </param>
 /// <param name='serverName'>
 /// The name of the SQL Server where the database will be created
 /// </param>
 /// <param name='parameters'>
 /// The parameters for the create database operation
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static DatabaseCreateResponse Create(this IDatabaseOperations operations, string serverName, DatabaseCreateParameters parameters)
 {
     try
     {
         return operations.CreateAsync(serverName, parameters).Result;
     }
     catch (AggregateException ex)
     {
         if (ex.InnerExceptions.Count > 1)
         {
             throw;
         }
         else
         {
             throw ex.InnerException;
         }
     }
 }
 /// <summary>
 /// Creates a database in an Azure SQL Database Server.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Sql.IDatabaseOperations.
 /// </param>
 /// <param name='serverName'>
 /// Required. The name of the Azure SQL Database Server where the
 /// database will be created.
 /// </param>
 /// <param name='parameters'>
 /// Required. The parameters for the create database operation.
 /// </param>
 /// <returns>
 /// Represents the response to a create database request from the
 /// service.
 /// </returns>
 public static Task<DatabaseCreateResponse> CreateAsync(this IDatabaseOperations operations, string serverName, DatabaseCreateParameters parameters)
 {
     return operations.CreateAsync(serverName, parameters, CancellationToken.None);
 }
        /// <summary>
        /// Creates a new sql database.
        /// </summary>
        /// <param name="databaseName">The name for the new database</param>
        /// <param name="databaseMaxSizeInGB">The maximum size of the new database</param>
        /// <param name="databaseCollation">The collation for the new database</param>
        /// <param name="databaseEdition">The edition for the new database</param>
        /// <returns>The newly created Sql Database</returns>
        public Database CreateNewDatabase(
            string databaseName,
            int? databaseMaxSizeInGB,
            long? databaseMaxSizeInBytes,
            string databaseCollation,
            DatabaseEdition databaseEdition,
            ServiceObjective serviceObjective)
        {
            this.clientRequestId = SqlDatabaseCmdletBase.GenerateClientTracingId();

            // Get the SQL management client
            SqlManagementClient sqlManagementClient = AzureSession.ClientFactory.CreateClient<SqlManagementClient>(this.profile, subscription, AzureEnvironment.Endpoint.ServiceManagement);
            this.AddTracingHeaders(sqlManagementClient);

            DatabaseCreateParameters parameters = new DatabaseCreateParameters()
            {
                Name = databaseName,
                Edition = databaseEdition != DatabaseEdition.None ?
                    databaseEdition.ToString() : null,
                CollationName = databaseCollation ?? string.Empty,
                MaximumDatabaseSizeInGB = databaseMaxSizeInGB,
                MaximumDatabaseSizeInBytes = databaseMaxSizeInBytes,
                ServiceObjectiveId = serviceObjective != null ? serviceObjective.Id.ToString() : null,
            };

            // Create the database
            DatabaseCreateResponse response = sqlManagementClient.Databases.Create(
                this.serverName,
                parameters);

            // Construct the resulting Database object
            Database database = CreateDatabaseFromResponse(response);
            return database;
        }