/// <summary>
 /// Begins creating a new Azure SQL Database or updating an existing
 /// Azure SQL Database. To determine the status of the operation call
 /// GetDatabaseOperationStatus.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the Microsoft.Azure.Management.Sql.IDatabaseOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the Resource Group to which the Azure SQL
 /// Database Server belongs.
 /// </param>
 /// <param name='serverName'>
 /// Required. The name of the Azure SQL Database Server on which the
 /// database is hosted.
 /// </param>
 /// <param name='databaseName'>
 /// Required. The name of the Azure SQL Database to be operated on
 /// (Updated or created).
 /// </param>
 /// <param name='parameters'>
 /// Required. The required parameters for creating or updating a
 /// database.
 /// </param>
 /// <returns>
 /// Response for long running Azure Sql Database operations.
 /// </returns>
 public static DatabaseCreateOrUpdateResponse BeginCreateOrUpdate(this IDatabaseOperations operations, string resourceGroupName, string serverName, string databaseName, DatabaseCreateOrUpdateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IDatabaseOperations)s).BeginCreateOrUpdateAsync(resourceGroupName, serverName, databaseName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// Restore a given Sql Azure Database
 /// </summary>
 /// <param name="resourceGroup">The name of the resource group</param>
 /// <param name="serverName">The name of the Azure SQL Server</param>
 /// <param name="databaseName">The name of the Azure SQL database</param>
 /// <param name="parameters">Parameters describing the database restore request</param>
 /// <returns>Restored database object</returns>
 public Management.Sql.Models.Database RestoreDatabase(string resourceGroupName, string serverName, string databaseName, string clientRequestId, DatabaseCreateOrUpdateParameters parameters)
 {
     return GetCurrentSqlClient(clientRequestId).Databases.CreateOrUpdate(resourceGroupName, serverName, databaseName, parameters).Database;
 }
 /// <summary>
 /// Creates a new Azure SQL Database or updates an existing Azure SQL
 /// Database.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the Microsoft.Azure.Management.Sql.IDatabaseOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the Resource Group to which the server
 /// belongs.
 /// </param>
 /// <param name='serverName'>
 /// Required. The name of the Azure SQL Database Server on which the
 /// database is hosted.
 /// </param>
 /// <param name='databaseName'>
 /// Required. The name of the Azure SQL Database to be operated on
 /// (Updated or created).
 /// </param>
 /// <param name='parameters'>
 /// Required. The required parameters for creating or updating a
 /// database.
 /// </param>
 /// <returns>
 /// Response for long running Azure Sql Database operations.
 /// </returns>
 public static Task<DatabaseCreateOrUpdateResponse> CreateOrUpdateAsync(this IDatabaseOperations operations, string resourceGroupName, string serverName, string databaseName, DatabaseCreateOrUpdateParameters parameters)
 {
     return operations.CreateOrUpdateAsync(resourceGroupName, serverName, databaseName, parameters, CancellationToken.None);
 }
 /// <summary>
 /// Restore a given Sql Azure Database
 /// </summary>
 /// <param name="resourceGroup">The name of the resource group</param>
 /// <param name="restorePointInTime">A point to time to restore to (for PITR and dropped DB restore)</param>
 /// <param name="resourceId">The resource ID of the DB to restore (live, geo backup, or deleted database)</param>
 /// <param name="model">An object modeling the database to create via restore</param>
 /// <param name="parameters">Parameters describing the database restore request</param>
 /// <returns>Restored database object</returns>
 internal AzureSqlDatabaseModel RestoreDatabase(string resourceGroup, DateTime restorePointInTime, string resourceId, AzureSqlDatabaseModel model)
 {
     DatabaseCreateOrUpdateParameters parameters = new DatabaseCreateOrUpdateParameters()
         {
             Location = model.Location,
             Properties = new DatabaseCreateOrUpdateProperties()
             {
                 Edition = model.Edition == DatabaseEdition.None ? null : model.Edition.ToString(),
                 RequestedServiceObjectiveId = model.RequestedServiceObjectiveId,
                 ElasticPoolName = model.ElasticPoolName,
                 RequestedServiceObjectiveName = model.RequestedServiceObjectiveName,
                 SourceDatabaseId = resourceId,
                 RestorePointInTime = restorePointInTime,
                 CreateMode = model.CreateMode
             }
         };
     var resp = Communicator.RestoreDatabase(resourceGroup, model.ServerName, model.DatabaseName, Util.GenerateTracingId(), parameters);
     return AzureSqlDatabaseAdapter.CreateDatabaseModelFromResponse(resourceGroup, model.ServerName, resp);
 }