Example #1
0
        /// <summary>
        /// Retrieves the list of all operations on the database.
        /// </summary>
        /// <param name="databaseName">The name of database to retrieve operations.</param>
        /// <returns>An array of all operations on the database.</returns>
        public DatabaseOperation[] GetDatabaseOperations(string databaseName)
        {
            this.clientRequestId = SqlDatabaseCmdletBase.GenerateClientTracingId();

            // Get the SQL management client
            SqlManagementClient sqlManagementClient = this.subscription.CreateClient <SqlManagementClient>();

            this.AddTracingHeaders(sqlManagementClient);

            // Retrieve all operations on specified database
            DatabaseOperationListResponse response = sqlManagementClient.DatabaseOperations.ListByDatabase(
                this.serverName,
                databaseName);

            // For any database which has ever been created, there should be at least one operation
            if (response.Count() == 0)
            {
                throw new InvalidOperationException(
                          string.Format(
                              CultureInfo.InvariantCulture,
                              Resources.DatabaseOperationNotFoundOnDatabase,
                              this.ServerName,
                              databaseName));
            }

            // Construct the resulting database operations
            DatabaseOperation[] operations = response.Select(operation => CreateDatabaseOperationsFromResponse(operation)).ToArray();
            return(operations);
        }
Example #2
0
        /// <summary>
        /// Retrieves the list of all databases' operations on the server.
        /// </summary>
        /// <returns>An array of all operations on the server.</returns>
        public DatabaseOperation[] GetDatabasesOperations()
        {
            this.clientRequestId = SqlDatabaseCmdletBase.GenerateClientTracingId();

            // Get the SQL management client
            SqlManagementClient sqlManagementClient = this.subscription.CreateClient <SqlManagementClient>();

            this.AddTracingHeaders(sqlManagementClient);

            // Retrieve the operations on specified server
            // We do not validate the number of operations returned since it's possible that there is no
            // database operations on a new created server.
            DatabaseOperationListResponse response = sqlManagementClient.DatabaseOperations.ListByServer(
                this.serverName);

            // Construct the resulting database operations array
            DatabaseOperation[] operations = response.Select(operation => CreateDatabaseOperationsFromResponse(operation)).ToArray();
            return(operations);
        }