protected override void ProcessRecord() { base.ProcessRecord(); ListBudgetsRequest request; try { request = new ListBudgetsRequest { CompartmentId = CompartmentId, Limit = Limit, Page = Page, SortOrder = SortOrder, SortBy = SortBy, LifecycleState = LifecycleState, DisplayName = DisplayName, TargetType = TargetType, OpcRequestId = OpcRequestId }; IEnumerable <ListBudgetsResponse> responses = GetRequestDelegate().Invoke(request); foreach (var item in responses) { response = item; WriteOutput(response, response.Items, true); } FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
/// <summary> /// Gets a list of Budgets in a compartment. /// <br/> /// By default, ListBudgets returns budgets of 'COMPARTMENT' target type and the budget records with only ONE target compartment OCID. /// <br/> /// To list ALL budgets, set the targetType query parameter to ALL. /// Example: /// 'targetType=ALL' /// <br/> /// Additional targetTypes would be available in future releases. Clients should ignore new targetType /// or upgrade to latest version of client SDK to handle new targetType. /// /// </summary> /// <param name="request">The request object containing the details to send. Required.</param> /// <param name="retryConfiguration">The retry configuration that will be used by to send this request. Optional.</param> /// <param name="cancellationToken">The cancellation token to cancel this operation. Optional.</param> /// <returns>A response object containing details about the completed operation</returns> /// <example>Click <a href="https://docs.cloud.oracle.com/en-us/iaas/tools/dot-net-examples/latest/budget/ListBudgets.cs.html">here</a> to see an example of how to use ListBudgets API.</example> public async Task <ListBudgetsResponse> ListBudgets(ListBudgetsRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default) { logger.Trace("Called listBudgets"); Uri uri = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/budgets".Trim('/'))); HttpMethod method = new HttpMethod("GET"); HttpRequestMessage requestMessage = Converter.ToHttpRequestMessage(uri, method, request); requestMessage.Headers.Add("Accept", "application/json"); GenericRetrier retryingClient = Retrier.GetPreferredRetrier(retryConfiguration, this.retryConfiguration); HttpResponseMessage responseMessage; try { if (retryingClient != null) { responseMessage = await retryingClient.MakeRetryingCall(this.restClient.HttpSend, requestMessage, cancellationToken).ConfigureAwait(false); } else { responseMessage = await this.restClient.HttpSend(requestMessage).ConfigureAwait(false); } this.restClient.CheckHttpResponseMessage(requestMessage, responseMessage); return(Converter.FromHttpResponseMessage <ListBudgetsResponse>(responseMessage)); } catch (Exception e) { logger.Error($"ListBudgets failed with error: {e.Message}"); throw; } }
public static void ConsoleDisplay(ClientConfig config) { var identityClient = new IdentityClient(config) { Region = Regions.US_ASHBURN_1 }; var budgetClient = new BudgetsClient(config) { Region = Regions.US_ASHBURN_1 }; var listCompartmentRequest = new ListCompartmentRequest() { CompartmentId = config.TenancyId, CompartmentIdInSubtree = true, AccessLevel = ListCompartmentRequest.AccessLevels.ACCESSIBLE }; var compartments = identityClient.ListCompartment(listCompartmentRequest).Items; compartments.Add(new Compartment { Id = config.TenancyId, Name = "root compartment", LifecycleState = "ACTIVE" }); Console.WriteLine("* Budgets Resources------------------------"); foreach (var com in compartments) { if (com.LifecycleState != "ACTIVE") { continue; } Console.WriteLine($" Compartment<{com.Name}>--------"); ListBudgetsRequest listBudgetsRequest = new ListBudgetsRequest() { CompartmentId = com.Id }; var budgets = budgetClient.ListBudgets(listBudgetsRequest); foreach (var budget in budgets.Items) { Console.WriteLine($"\t|-name:{budget.DisplayName}, state:{budget.LifecycleState}, amount:{budget.Amount}"); } } }
/// <summary> /// Creates a new enumerable which will iterate over the responses received from the ListBudgets operation. This enumerable /// will fetch more data from the server as needed. /// </summary> /// <param name="request">The request object containing the details to send</param> /// <param name="retryConfiguration">The configuration for retrying, may be null</param> /// <param name="cancellationToken">The cancellation token object</param> /// <returns>The enumerator, which supports a simple iteration over a collection of a specified type</returns> public IEnumerable <ListBudgetsResponse> ListBudgetsResponseEnumerator(ListBudgetsRequest request, Common.Retry.RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default) { return(new Common.Utils.ResponseEnumerable <ListBudgetsRequest, ListBudgetsResponse>( response => response.OpcNextPage, input => { if (!string.IsNullOrEmpty(input)) { request.Page = input; } return request; }, request => client.ListBudgets(request, retryConfiguration, cancellationToken).Result )); }
/// <summary>Snippet for ListBudgetsAsync</summary> public async Task ListBudgetsRequestObjectAsync() { // Snippet: ListBudgetsAsync(ListBudgetsRequest, CallSettings) // Create client BudgetServiceClient budgetServiceClient = await BudgetServiceClient.CreateAsync(); // Initialize request argument(s) ListBudgetsRequest request = new ListBudgetsRequest { ParentAsBillingAccountName = BillingAccountName.FromBillingAccount("[BILLING_ACCOUNT]"), }; // Make the request PagedAsyncEnumerable <ListBudgetsResponse, Budget> response = budgetServiceClient.ListBudgetsAsync(request); // Iterate over all response items, lazily performing RPCs as required await response.ForEachAsync((Budget item) => { // Do something with each item Console.WriteLine(item); }); // Or iterate over pages (of server-defined size), performing one RPC per page await response.AsRawResponses().ForEachAsync((ListBudgetsResponse page) => { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (Budget item in page) { // Do something with each item Console.WriteLine(item); } }); // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; Page <Budget> singlePage = await response.ReadPageAsync(pageSize); // Do something with the page of items Console.WriteLine($"A page of {pageSize} results (unless it's the final page):"); foreach (Budget item in singlePage) { // Do something with each item Console.WriteLine(item); } // Store the pageToken, for when the next page is required. string nextPageToken = singlePage.NextPageToken; // End snippet }
/// <summary> /// Lists budgets in the specified compartment. /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <ListBudgetsResponse> ListBudgets(ListBudgetsRequest request) { var uri = new Uri($"{GetEndPoint(BudgetsServices.Budgets, this.Region, "oci.oraclecloud.com")}?{request.GetOptionQuery()}"); using (var webResponse = await this.RestClientAsync.Get(uri)) using (var stream = webResponse.GetResponseStream()) using (var reader = new StreamReader(stream)) { var response = await reader.ReadToEndAsync(); return(new ListBudgetsResponse() { Items = this.JsonSerializer.Deserialize <List <BudgetSummary> >(response), OpcRequestId = webResponse.Headers.Get("opc-request-id"), OpcNextPage = webResponse.Headers.Get("opc-next-page") }); } }
protected override void ProcessRecord() { base.ProcessRecord(); ListBudgetsRequest request; try { request = new ListBudgetsRequest { CompartmentId = CompartmentId, Limit = Limit, Page = Page, SortOrder = SortOrder, SortBy = SortBy, LifecycleState = LifecycleState, DisplayName = DisplayName, TargetType = TargetType, OpcRequestId = OpcRequestId }; IEnumerable <ListBudgetsResponse> responses = GetRequestDelegate().Invoke(request); foreach (var item in responses) { response = item; WriteOutput(response, response.Items, true); } if (!ParameterSetName.Equals(AllPageSet) && !ParameterSetName.Equals(LimitSet) && response.OpcNextPage != null) { WriteWarning("This operation supports pagination and not all resources were returned. Re-run using the -All option to auto paginate and list all resources."); } FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }