/// <summary>
 /// Start a server upgrade
 /// </summary>
 /// <param name="model">The server upgrade model to start the upgrade</param>
 public void Start(AzureSqlServerUpgradeStartModel model)
 {
     ServerUpgradeStartParameters parameters = new ServerUpgradeStartParameters()
     {
         Properties = new ServerUpgradeProperties()
         {
             Version = model.ServerVersion,
             ScheduleUpgradeAfterUtcDateTime = model.ScheduleUpgradeAfterUtcDateTime,
             DatabaseCollection = model.DatabaseCollection
         }
     };
     Communicator.Start(model.ResourceGroupName, model.ServerName, parameters, Util.GenerateTracingId());
 }
 /// <summary>
 /// Start an Azure SQL Database Server Upgrade.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Sql.IServerUpgradeOperations.
 /// </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 to upgrade.
 /// </param>
 /// <param name='parameters'>
 /// Required. The required parameters for the Azure SQL Database Server
 /// Upgrade.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<AzureOperationResponse> StartAsync(this IServerUpgradeOperations operations, string resourceGroupName, string serverName, ServerUpgradeStartParameters parameters)
 {
     return operations.StartAsync(resourceGroupName, serverName, parameters, CancellationToken.None);
 }
 /// <summary>
 /// Start an Azure SQL Database Server Upgrade.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Sql.IServerUpgradeOperations.
 /// </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 to upgrade.
 /// </param>
 /// <param name='parameters'>
 /// Required. The required parameters for the Azure SQL Database Server
 /// Upgrade.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static AzureOperationResponse Start(this IServerUpgradeOperations operations, string resourceGroupName, string serverName, ServerUpgradeStartParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IServerUpgradeOperations)s).StartAsync(resourceGroupName, serverName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
        /// <summary>
        /// Create upgrade start parameters for testing
        /// </summary>
        /// <param name="version">The version to upgrade the server to</param>
        /// <param name="scheduleUpgradeAfter">The earliest time to upgrade the server</param>
        /// <param name="database">The database to map to new edition and SLO. Target SLO and edition are in the constants at the top of this file</param>
        /// <returns>The server upgrade start parameters object</returns>
        private ServerUpgradeStartParameters CreateUpgradeStartParameters(
            string version = upgradedVersion,
            DateTime? scheduleUpgradeAfter = null,
            Database database = null)
        {
            var parameters = new ServerUpgradeStartParameters()
            {
                Properties = new ServerUpgradeProperties()
                {
                    Version = version,
                    ScheduleUpgradeAfterUtcDateTime = scheduleUpgradeAfter
                }
            };

            if (database != null)
            {
                parameters.Properties.DatabaseCollection = new List<RecommendedDatabaseProperties>()
                {
                    new RecommendedDatabaseProperties()
                    {
                        Name = database.Name,
                        TargetServiceLevelObjective = targetServiceLevelObjective,
                        TargetEdition = targetEdition
                    }
                };
            }

            return parameters;
        }
        /// <summary>
        /// Create upgrade start parameters for testing
        /// </summary>
        /// <param name="version">The version to upgrade the server to</param>
        /// <param name="scheduleUpgradeAfter">The earliest time to upgrade the server</param>
        /// <param name="recommendedDatabase">The database to map to new edition and SLO. Target SLO and edition are in the constants at the top of this file</param>
        /// <param name="databaseInElasticPool">The database to be put in new elastic pool. Elastic pool properties are in the constants at the top of this file</param>
        /// <returns>The server upgrade start parameters object</returns>
        private ServerUpgradeStartParameters CreateUpgradeStartParameters(
            string version = upgradedVersion,
            DateTime? scheduleUpgradeAfter = null,
            Database recommendedDatabase = null,
            Database databaseInElasticPool = null)
        {
            var parameters = new ServerUpgradeStartParameters()
            {
                Properties = new ServerUpgradeProperties()
                {
                    Version = version,
                    ScheduleUpgradeAfterUtcDateTime = scheduleUpgradeAfter
                }
            };

            if (recommendedDatabase != null)
            {
                parameters.Properties.DatabaseCollection = new List<RecommendedDatabaseProperties>()
                {
                    new RecommendedDatabaseProperties()
                    {
                        Name = recommendedDatabase.Name,
                        TargetServiceLevelObjective = targetServiceLevelObjective,
                        TargetEdition = targetEdition
                    }
                };
            }

            if (databaseInElasticPool != null)
            {
                parameters.Properties.ElasticPoolCollection = new List<UpgradeRecommendedElasticPoolProperties>()
                {
                    // Create an elastic pool with default values and contain only the provided database
                    new UpgradeRecommendedElasticPoolProperties()
                    {
                        Name = TestUtilities.GenerateName("csm-ep-"),
                        Edition = targetEdition,
                        Dtu = defaultElasticPoolDtu,
                        StorageMb = defaultElasticPoolStorageMb,
                        DatabaseDtuMax = defaultElasticPoolDatabaseDtuMax,
                        DatabaseDtuMin = defaultElasticPoolDatabaseDtuMin,
                        DatabaseCollection = new List<string>() { databaseInElasticPool.Name }
                    }
                };
            }

            return parameters;
        }
 /// <summary>
 /// Start an Azure Sql Database Server Upgrade
 /// </summary>
 public void Start(string resourceGroupName, string serverName, ServerUpgradeStartParameters parameters, string clientRequestId)
 {
     GetCurrentSqlClient(clientRequestId).ServerUpgrades.Start(resourceGroupName, serverName, parameters);
 }