forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add convenient Database.Rename methods
Fixes Azure#4055
- Loading branch information
Showing
6 changed files
with
213 additions
and
7 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
src/SDKs/SqlManagement/Management.Sql/DatabasesOperations.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for | ||
// license information. | ||
|
||
namespace Microsoft.Azure.Management.Sql | ||
{ | ||
using Microsoft.Rest.Azure; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
internal partial class DatabasesOperations | ||
{ | ||
/// <summary> | ||
/// Renames a database. | ||
/// </summary> | ||
/// <param name='resourceGroupName'> | ||
/// The name of the resource group that contains the resource. You can | ||
/// obtain this value from the Azure Resource Manager API or the | ||
/// portal. | ||
/// </param> | ||
/// <param name='serverName'> | ||
/// The name of the server. | ||
/// </param> | ||
/// <param name='databaseName'> | ||
/// The name of the database to rename. | ||
/// </param> | ||
/// <param name='newName'> | ||
/// The new name that the database should be renamed to. | ||
/// </param> | ||
/// <param name='customHeaders'> | ||
/// The headers that will be added to request. | ||
/// </param> | ||
/// <param name='cancellationToken'> | ||
/// The cancellation token. | ||
/// </param> | ||
/// <exception cref="Microsoft.Rest.Azure.CloudException"> | ||
/// Thrown when the operation returned an invalid status code | ||
/// </exception> | ||
/// <exception cref="Microsoft.Rest.ValidationException"> | ||
/// Thrown when a required parameter is null | ||
/// </exception> | ||
public async Task<AzureOperationResponse> RenameWithHttpMessagesAsync( | ||
string resourceGroupName, | ||
string serverName, | ||
string databaseName, | ||
string newName, | ||
Dictionary<string, List<string>> customHeaders = null, | ||
CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
return await this.RenameWithHttpMessagesAsync( | ||
resourceGroupName, | ||
serverName, | ||
databaseName, | ||
new Models.ResourceMoveDefinition( | ||
string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/servers/{2}/databases/{3}", | ||
this.Client.SubscriptionId, | ||
resourceGroupName, | ||
serverName, | ||
newName)), | ||
customHeaders, | ||
cancellationToken); | ||
} | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/SDKs/SqlManagement/Management.Sql/DatabasesOperationsExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for | ||
// license information. | ||
|
||
namespace Microsoft.Azure.Management.Sql | ||
{ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
public partial class DatabasesOperationsExtensions | ||
{ | ||
/// <summary> | ||
/// Renames a database. | ||
/// </summary> | ||
/// <param name='operations'> | ||
/// The operations group for this extension method. | ||
/// </param> | ||
/// <param name='resourceGroupName'> | ||
/// The name of the resource group that contains the resource. You can obtain | ||
/// this value from the Azure Resource Manager API or the portal. | ||
/// </param> | ||
/// <param name='serverName'> | ||
/// The name of the server. | ||
/// </param> | ||
/// <param name='databaseName'> | ||
/// The name of the database to rename. | ||
/// </param> | ||
/// <param name='newName'> | ||
/// The new name that the database should be renamed to. | ||
/// </param> | ||
public static void Rename( | ||
this IDatabasesOperations operations, | ||
string resourceGroupName, | ||
string serverName, | ||
string databaseName, | ||
string newName) | ||
{ | ||
RenameAsync(operations, resourceGroupName, serverName, databaseName, newName).GetAwaiter().GetResult(); | ||
} | ||
|
||
/// <summary> | ||
/// Renames a database. | ||
/// </summary> | ||
/// <param name='operations'> | ||
/// The operations group for this extension method. | ||
/// </param> | ||
/// <param name='resourceGroupName'> | ||
/// The name of the resource group that contains the resource. You can obtain | ||
/// this value from the Azure Resource Manager API or the portal. | ||
/// </param> | ||
/// <param name='serverName'> | ||
/// The name of the server. | ||
/// </param> | ||
/// <param name='databaseName'> | ||
/// The name of the database to rename. | ||
/// </param> | ||
/// <param name='newName'> | ||
/// The new name that the database should be renamed to. | ||
/// </param> | ||
/// <param name='cancellationToken'> | ||
/// The cancellation token. | ||
/// </param> | ||
public static async Task RenameAsync( | ||
this IDatabasesOperations operations, | ||
string resourceGroupName, | ||
string serverName, | ||
string databaseName, | ||
string newName, | ||
CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
(await operations.RenameWithHttpMessagesAsync( | ||
resourceGroupName, | ||
serverName, | ||
databaseName, | ||
newName, | ||
null, | ||
cancellationToken).ConfigureAwait(false)).Dispose(); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/SDKs/SqlManagement/Management.Sql/IDatabasesOperations.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for | ||
// license information. | ||
|
||
namespace Microsoft.Azure.Management.Sql | ||
{ | ||
using Microsoft.Rest.Azure; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
public partial interface IDatabasesOperations | ||
{ | ||
/// <summary> | ||
/// Renames a database. | ||
/// </summary> | ||
/// <param name='resourceGroupName'> | ||
/// The name of the resource group that contains the resource. You can | ||
/// obtain this value from the Azure Resource Manager API or the | ||
/// portal. | ||
/// </param> | ||
/// <param name='serverName'> | ||
/// The name of the server. | ||
/// </param> | ||
/// <param name='databaseName'> | ||
/// The name of the database to rename. | ||
/// </param> | ||
/// <param name='newName'> | ||
/// The new name that the database should be renamed to. | ||
/// </param> | ||
/// <param name='customHeaders'> | ||
/// The headers that will be added to request. | ||
/// </param> | ||
/// <param name='cancellationToken'> | ||
/// The cancellation token. | ||
/// </param> | ||
/// <exception cref="Microsoft.Rest.Azure.CloudException"> | ||
/// Thrown when the operation returned an invalid status code | ||
/// </exception> | ||
/// <exception cref="Microsoft.Rest.ValidationException"> | ||
/// Thrown when a required parameter is null | ||
/// </exception> | ||
Task<AzureOperationResponse> RenameWithHttpMessagesAsync( | ||
string resourceGroupName, | ||
string serverName, | ||
string databaseName, | ||
string newName, | ||
Dictionary<string, List<string>> customHeaders = null, | ||
CancellationToken cancellationToken = default(CancellationToken)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters