/// <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, string databaseCollation, DatabaseEdition databaseEdition, ServiceObjective serviceObjective) { this.clientRequestId = SqlDatabaseCmdletBase.GenerateClientTracingId(); // Get the SQL management client SqlManagementClient sqlManagementClient = this.subscription.CreateClient <SqlManagementClient>(); this.AddTracingHeaders(sqlManagementClient); // Create the database DatabaseCreateResponse response = sqlManagementClient.Databases.Create( this.serverName, new DatabaseCreateParameters() { Name = databaseName, Edition = databaseEdition != DatabaseEdition.None ? databaseEdition.ToString() : DatabaseEdition.Web.ToString(), CollationName = databaseCollation ?? string.Empty, MaximumDatabaseSizeInGB = databaseMaxSizeInGB ?? (databaseEdition == DatabaseEdition.Business || databaseEdition == DatabaseEdition.Premium ? 10 : 1), ServiceObjectiveId = serviceObjective != null ? serviceObjective.Id.ToString() : null, }); // Construct the resulting Database object Database database = CreateDatabaseFromResponse(response); return(database); }
/// <summary> /// Ensures any extra property on the given <paramref name="obj"/> is loaded. /// </summary> /// <param name="obj">The object that needs the extra properties.</param> public void LoadExtraProperties(object obj) { try { Database database = obj as Database; if (database != null) { this.LoadExtraProperties(database); return; } ServiceObjective serviceObjective = obj as ServiceObjective; if (serviceObjective != null) { this.LoadExtraProperties(serviceObjective); return; } RestorableDroppedDatabase restorableDroppedDatabase = obj as RestorableDroppedDatabase; if (restorableDroppedDatabase != null) { this.LoadExtraProperties(restorableDroppedDatabase); return; } } catch { // Ignore exceptions when loading extra properties, for backward compatibility. } }
/// <summary> /// Ensures any extra property on the given <paramref name="serviceObjective"/> is loaded. /// </summary> /// <param name="serviceObjective">The serviceObjective that needs the extra properties.</param> private void LoadExtraProperties(ServiceObjective serviceObjective) { // Fill in the context property serviceObjective.Context = this; // Fill in the service objective Dimension Settings this.LoadProperty(serviceObjective, "DimensionSettings"); }
/// <summary> /// Updates the property on the database with the name <paramref name="databaseName"/>. /// </summary> /// <param name="databaseName">The database to update.</param> /// <param name="newDatabaseName"> /// The new database name, or <c>null</c> to not update. /// </param> /// <param name="databaseMaxSize"> /// The new database max size, or <c>null</c> to not update. /// </param> /// <param name="databaseEdition"> /// The new database edition, or <c>null</c> to not update. /// </param> /// <param name="serviceObjective"> /// The new service objective, or <c>null</c> to not update. /// </param> /// <returns>The updated database object.</returns> public Database UpdateDatabase( string databaseName, string newDatabaseName, int?databaseMaxSizeGb, long?databaseMaxSizeBytes, DatabaseEdition?databaseEdition, ServiceObjective serviceObjective) { // Find the database by name Database database = GetDatabase(databaseName); // Update the name if specified if (newDatabaseName != null) { database.Name = newDatabaseName; } // Update the max size and edition properties if (databaseMaxSizeGb != null) { database.MaxSizeGB = (int)databaseMaxSizeGb; } if (databaseMaxSizeBytes != null) { database.MaxSizeBytes = (long)databaseMaxSizeBytes; } database.Edition = databaseEdition == null ? null : databaseEdition.ToString(); database.IsRecursiveTriggersOn = null; // Update the service objective property if specified if (serviceObjective != null) { database.ServiceObjectiveId = serviceObjective.Id; } else { database.ServiceObjectiveId = null; } // Mark the database object for update and submit the changes this.UpdateObject(database); try { this.SaveChanges(); } catch { this.RevertChanges(database); throw; } return(this.GetDatabase(database.Name)); }
/// <summary> /// Updates the property on the database with the name <paramref name="databaseName"/>. /// </summary> /// <param name="builder">The sql connection string information</param> /// <param name="databaseName">The database to update.</param> /// <param name="newDatabaseName">The new database name, or <c>null</c> to not update.</param> /// <param name="databaseMaxSizeGb">The max size for the database in GB.</param> /// <param name="databaseMaxSizeBytes">The max size for the database in bytes.</param> /// <param name="databaseEdition">The new database edition, or <c>null</c> to not update.</param> /// <param name="serviceObjective">The new service objective, or <c>null</c> to not update.</param> /// <returns>The updated database object.</returns> public Database UpdateDatabase( string databaseName, string newDatabaseName, int?databaseMaxSizeGb, long?databaseMaxSizeBytes, DatabaseEdition?databaseEdition, ServiceObjective serviceObjective) { return(UpdateDatabase( databaseName, newDatabaseName, databaseMaxSizeGb, databaseMaxSizeBytes, databaseEdition, serviceObjective == null ? null : serviceObjective.Name)); }
/// <summary> /// Creates a new Sql Database. /// </summary> /// <param name="databaseName">The name for the new database.</param> /// <param name="databaseMaxSizeGb">The max size for the database in GB.</param> /// <param name="databaseMaxSizeBytes">The max size for the database in bytes.</param> /// <param name="databaseCollation">The collation for the database.</param> /// <param name="databaseEdition">The edition for the database.</param> /// <param name="serviceObjective">The service object to assign to the database</param> /// <returns>The newly created Sql Database.</returns> public Database CreateNewDatabase( string databaseName, int?databaseMaxSizeGb, long?databaseMaxSizeBytes, string databaseCollation, DatabaseEdition databaseEdition, ServiceObjective serviceObjective) { return(CreateNewDatabase( databaseName, databaseMaxSizeGb, databaseMaxSizeBytes, databaseCollation, databaseEdition, serviceObjective == null ? null : serviceObjective.Name)); }
/// <summary> /// Retrieve information on service objective with the specified name /// </summary> /// <param name="serviceObjectiveName">The service objective to retrieve.</param> /// <returns> /// An object containing the information about the specific service objective. /// </returns> public ServiceObjective GetServiceObjective(string serviceObjectiveName) { ServiceObjective serviceObjective = GetServiceObjectives() .Where(s => s.Name == serviceObjectiveName) .FirstOrDefault(); if (serviceObjective == null) { throw new InvalidOperationException( string.Format( CultureInfo.InvariantCulture, Resources.ServiceObjectiveNotFound, this.ServerName, serviceObjectiveName)); } return(serviceObjective); }
/// <summary> /// Retrieve information on latest service objective with service objective /// </summary> /// <param name="serviceObjective">The service objective to refresh.</param> /// <returns> /// An object containing the information about the specific service objective. /// </returns> public ServiceObjective GetServiceObjective(ServiceObjective serviceObjectiveToRefresh) { this.clientRequestId = SqlDatabaseCmdletBase.GenerateClientTracingId(); // Get the SQL management client SqlManagementClient sqlManagementClient = this.subscription.CreateClient <SqlManagementClient>(); this.AddTracingHeaders(sqlManagementClient); // Retrieve the specified database ServiceObjectiveGetResponse response = sqlManagementClient.ServiceObjectives.Get( this.serverName, serviceObjectiveToRefresh.Id.ToString()); // Construct the resulting Database object ServiceObjective serviceObjective = CreateServiceObjectiveFromResponse(response); return(serviceObjective); }
/// <summary> /// Update a database on the server. /// </summary> /// <param name="databaseName">The name of the database to modify.</param> /// <param name="newDatabaseName">The new name of the database.</param> /// <param name="databaseMaxSizeInGB">The new maximum size of the database.</param> /// <param name="databaseEdition">The new edition of the database.</param> /// <param name="serviceObjective">The new service objective of the database.</param> /// <returns>The updated database.</returns> public Database UpdateDatabase( string databaseName, string newDatabaseName, int?databaseMaxSizeInGB, DatabaseEdition?databaseEdition, ServiceObjective serviceObjective) { this.clientRequestId = SqlDatabaseCmdletBase.GenerateClientTracingId(); // Get the SQL management client SqlManagementClient sqlManagementClient = this.subscription.CreateClient <SqlManagementClient>(); this.AddTracingHeaders(sqlManagementClient); // Retrieve the specified database DatabaseGetResponse database = sqlManagementClient.Databases.Get( this.serverName, databaseName); // Update the database with the new properties DatabaseUpdateResponse response = sqlManagementClient.Databases.Update( this.serverName, databaseName, new DatabaseUpdateParameters() { Id = database.Id, Name = !string.IsNullOrEmpty(newDatabaseName) ? newDatabaseName : database.Name, Edition = databaseEdition.HasValue && (databaseEdition != DatabaseEdition.None) ? databaseEdition.ToString() : (database.Edition ?? string.Empty), CollationName = database.CollationName ?? string.Empty, MaximumDatabaseSizeInGB = databaseMaxSizeInGB.HasValue ? databaseMaxSizeInGB.Value : database.MaximumDatabaseSizeInGB, ServiceObjectiveId = serviceObjective != null ? serviceObjective.Id.ToString() : null, }); // Construct the resulting Database object Database updatedDatabase = CreateDatabaseFromResponse(response); return(updatedDatabase); }
/// <summary> /// Retrieve information on latest service objective with service objective /// <paramref name="serviceObjectives"/>. /// </summary> /// <param name="serviceObjective">The service objective to retrieve.</param> /// <returns> /// An object containing the information about the specific service objective. /// </returns> public ServiceObjective GetServiceObjective(ServiceObjective serviceObjective) { return this.GetServiceObjective(serviceObjective.Name); }
/// <summary> /// Updates the property on the database with the name <paramref name="databaseName"/>. /// </summary> /// <param name="databaseName">The database to update.</param> /// <param name="newDatabaseName"> /// The new database name, or <c>null</c> to not update. /// </param> /// <param name="databaseMaxSize"> /// The new database max size, or <c>null</c> to not update. /// </param> /// <param name="databaseEdition"> /// The new database edition, or <c>null</c> to not update. /// </param> /// <param name="serviceObjective"> /// The new service objective, or <c>null</c> to not update. /// </param> /// <returns>The updated database object.</returns> public Database UpdateDatabase( string databaseName, string newDatabaseName, int? databaseMaxSizeGb, long? databaseMaxSizeBytes, DatabaseEdition? databaseEdition, ServiceObjective serviceObjective) { // Find the database by name Database database = GetDatabase(databaseName); // Update the name if specified if (newDatabaseName != null) { database.Name = newDatabaseName; } // Update the max size and edition properties if (databaseMaxSizeGb != null) { database.MaxSizeGB = (int)databaseMaxSizeGb; } if (databaseMaxSizeBytes != null) { database.MaxSizeBytes = (long)databaseMaxSizeBytes; } database.Edition = databaseEdition == null ? null : databaseEdition.ToString(); database.IsRecursiveTriggersOn = null; // Update the service objective property if specified if (serviceObjective != null) { database.ServiceObjectiveId = serviceObjective.Id; } else { database.ServiceObjectiveId = null; } // Mark the database object for update and submit the changes this.UpdateObject(database); try { this.SaveChanges(); } catch { this.RevertChanges(database); throw; } return this.GetDatabase(database.Name); }
/// <summary> /// Creates a new Sql Database. /// </summary> /// <param name="databaseName">The name for the new database.</param> /// <param name="databaseMaxSize">The max size for the database.</param> /// <param name="databaseCollation">The collation for the database.</param> /// <param name="databaseEdition">The edition for the database.</param> /// <returns>The newly created Sql Database.</returns> public Database CreateNewDatabase( string databaseName, int? databaseMaxSizeGb, long? databaseMaxSizeBytes, string databaseCollation, DatabaseEdition databaseEdition, ServiceObjective serviceObjective) { // Create a new request Id for this operation this.clientRequestId = SqlDatabaseCmdletBase.GenerateClientTracingId(); // Create the new entity and set its properties Database database = new Database(); database.Name = databaseName; if (databaseMaxSizeGb != null) { database.MaxSizeGB = (int)databaseMaxSizeGb; } if(databaseMaxSizeBytes != null) { database.MaxSizeBytes = (long)databaseMaxSizeBytes; } if (!string.IsNullOrEmpty(databaseCollation)) { database.CollationName = databaseCollation; } if (databaseEdition != DatabaseEdition.None) { database.Edition = databaseEdition.ToString(); } if (serviceObjective != null) { database.ServiceObjectiveId = serviceObjective.Id; } else { database.ServiceObjectiveId = null; } // Save changes this.AddToDatabases(database); try { this.SaveChanges(SaveChangesOptions.None); // Re-Query the database for server side updated information database = this.RefreshEntity(database); if (database == null) { throw new ApplicationException(Resources.ErrorRefreshingDatabase); } } catch { this.ClearTrackedEntity(database); throw; } // Load the extra properties for this object. this.LoadExtraProperties(database); return database; }
/// <summary> /// Ensures any extra property on the given <paramref name="serviceObjective"/> is loaded. /// </summary> /// <param name="serviceObjective">The serviceObjective that needs the extra properties.</param> private void LoadExtraProperties(ServiceObjective serviceObjective) { // Fill in the context property serviceObjective.Context = this; // Fill in the service objective Dimension Settings this.LoadProperty(serviceObjective, "DimensionSettings"); }
/// <summary> /// Validate that the service objective properties match the expected values /// </summary> /// <param name="so">The service objective object</param> /// <param name="name">The expected name for the service objective</param> /// <param name="description">The expected description for the service objective</param> /// <param name="dimSettingsCount">The expected number of dimension settings</param> /// <param name="desc">A list of the expected descriptions for each dimension setting</param> private static void ValidateServiceObjectiveProperties(ServiceObjective so, string name, string description, int dimSettingsCount, params string[] desc) { Assert.AreEqual(name, so.Name); Assert.AreEqual(description, so.Description); Assert.IsNotNull(so.DimensionSettings, "Expecting some Dimension Setting objects."); Assert.AreEqual(dimSettingsCount, so.DimensionSettings.Count(), "Expecting 1 Dimension Setting."); for (int i = 0; i < dimSettingsCount; i++) { Assert.AreEqual(desc[i], so.DimensionSettings[i].Description); } }
public ServiceObjective GetServiceObjective(ServiceObjective serviceObjective) { return(GetServiceObjective(serviceObjective.Name)); }
/// <summary> /// Creates a new Sql Database. /// </summary> /// <param name="databaseName">The name for the new database.</param> /// <param name="databaseMaxSize">The max size for the database.</param> /// <param name="databaseCollation">The collation for the database.</param> /// <param name="databaseEdition">The edition for the database.</param> /// <returns>The newly created Sql Database.</returns> public Database CreateNewDatabase( string databaseName, int?databaseMaxSize, string databaseCollation, DatabaseEdition databaseEdition, ServiceObjective serviceObjective) { // Create a new request Id for this operation this.clientRequestId = SqlDatabaseCmdletBase.GenerateClientTracingId(); // Create the new entity and set its properties Database database = new Database(); database.Name = databaseName; if (databaseMaxSize != null) { database.MaxSizeGB = (int)databaseMaxSize; } if (!string.IsNullOrEmpty(databaseCollation)) { database.CollationName = databaseCollation; } if (databaseEdition != DatabaseEdition.None) { database.Edition = databaseEdition.ToString(); } if (serviceObjective != null) { database.ServiceObjectiveId = serviceObjective.Id; } else { database.ServiceObjectiveId = null; } // Save changes this.AddToDatabases(database); try { this.SaveChanges(SaveChangesOptions.None); // Re-Query the database for server side updated information database = this.RefreshEntity(database); if (database == null) { throw new ApplicationException(Resources.ErrorRefreshingDatabase); } } catch { this.ClearTrackedEntity(database); throw; } // Load the extra properties for this object. this.LoadExtraProperties(database); return(database); }