public void UpdateState() { using (UndoContext context = UndoContext.Current) { context.Start(); var handler = new BasicDelegatingHandler(); var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler); var updateParams = new RecommendedIndexUpdateParameters { Properties = new RecommendedIndexUpdateProperties { State = "Pending" } }; var response = sqlClient.RecommendedIndexes.Update(ResourceGroupName, ServerName, DatabaseName, Schema, TableName, IndexName, updateParams); var index = response.RecommendedIndex; ValidateRecommendedIndex(index, "Pending"); updateParams.Properties.State = "Active"; sqlClient.RecommendedIndexes.Update(ResourceGroupName, ServerName, DatabaseName, Schema, TableName, IndexName, updateParams); } }
/// <summary> /// We execute or cancel index operations by updating index state. /// Allowed state transitions are :Active -> Pending /// - Start index creation processPending -> Active /// - Cancel index creationActive/Pending -> Ignored /// - Ignore index recommendation so it will no longer show /// in active recommendationsIgnored -> Active - /// Restore index recommendationSuccess -> Pending Revert - /// Revert index that has been createdPending Revert -> Revert /// Canceled - Cancel index revert operation /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Sql.IRecommendedIndexOperations. /// </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. /// </param> /// <param name='schemaName'> /// Required. The name of the Azure SQL Database schema. /// </param> /// <param name='tableName'> /// Required. The name of the Azure SQL Database table. /// </param> /// <param name='indexName'> /// Required. The name of the Azure SQL Database recommended index. /// </param> /// <param name='parameters'> /// Required. The required parameters for updating index state. /// </param> /// <returns> /// Represents the response to a get recommended index request. /// </returns> public static Task<RecommendedIndexUpdateResponse> UpdateAsync(this IRecommendedIndexOperations operations, string resourceGroupName, string serverName, string databaseName, string schemaName, string tableName, string indexName, RecommendedIndexUpdateParameters parameters) { return operations.UpdateAsync(resourceGroupName, serverName, databaseName, schemaName, tableName, indexName, parameters, CancellationToken.None); }
/// <summary> /// We execute or cancel index operations by updating index state. /// Allowed state transitions are :Active -> Pending /// - Start index creation processPending -> Active /// - Cancel index creationActive/Pending -> Ignored /// - Ignore index recommendation so it will no longer show /// in active recommendationsIgnored -> Active - /// Restore index recommendationSuccess -> Pending Revert - /// Revert index that has been createdPending Revert -> Revert /// Canceled - Cancel index revert operation /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Sql.IRecommendedIndexOperations. /// </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. /// </param> /// <param name='schemaName'> /// Required. The name of the Azure SQL Database schema. /// </param> /// <param name='tableName'> /// Required. The name of the Azure SQL Database table. /// </param> /// <param name='indexName'> /// Required. The name of the Azure SQL Database recommended index. /// </param> /// <param name='parameters'> /// Required. The required parameters for updating index state. /// </param> /// <returns> /// Represents the response to a get recommended index request. /// </returns> public static RecommendedIndexUpdateResponse Update(this IRecommendedIndexOperations operations, string resourceGroupName, string serverName, string databaseName, string schemaName, string tableName, string indexName, RecommendedIndexUpdateParameters parameters) { return Task.Factory.StartNew((object s) => { return ((IRecommendedIndexOperations)s).UpdateAsync(resourceGroupName, serverName, databaseName, schemaName, tableName, indexName, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }