protected override void ProcessRecord() { base.ProcessRecord(); ListAgentsRequest request; try { request = new ListAgentsRequest { CompartmentId = CompartmentId, Limit = Limit, Page = Page, SortBy = SortBy, SortOrder = SortOrder, DisplayName = DisplayName, LifecycleState = LifecycleState, OpcRequestId = OpcRequestId }; IEnumerable <ListAgentsResponse> responses = GetRequestDelegate().Invoke(request); foreach (var item in responses) { response = item; WriteOutput(response, response.AgentCollection, 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); } }
public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems) { AmazonDataSyncConfig config = new AmazonDataSyncConfig(); config.RegionEndpoint = region; ConfigureClient(config); AmazonDataSyncClient client = new AmazonDataSyncClient(creds, config); ListAgentsResponse resp = new ListAgentsResponse(); do { ListAgentsRequest req = new ListAgentsRequest { NextToken = resp.NextToken , MaxResults = maxItems }; resp = client.ListAgents(req); CheckError(resp.HttpStatusCode, "200"); foreach (var obj in resp.Agents) { AddObject(obj); } }while (!string.IsNullOrEmpty(resp.NextToken)); }
/// <summary> /// Creates a new enumerable which will iterate over the responses received from the ListAgents 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 <ListAgentsResponse> ListAgentsResponseEnumerator(ListAgentsRequest request, Common.Retry.RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default) { return(new Common.Utils.ResponseEnumerable <ListAgentsRequest, ListAgentsResponse>( response => response.OpcNextPage, input => { if (!string.IsNullOrEmpty(input)) { request.Page = input; } return request; }, request => client.ListAgents(request, retryConfiguration, cancellationToken) )); }
/// <summary>Snippet for ListAgents</summary> public async Task ListAgentsRequestObjectAsync() { // Snippet: ListAgentsAsync(ListAgentsRequest, CallSettings) // Create client AgentsClient agentsClient = await AgentsClient.CreateAsync(); // Initialize request argument(s) ListAgentsRequest request = new ListAgentsRequest { ParentAsLocationName = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"), }; // Make the request PagedAsyncEnumerable <ListAgentsResponse, Agent> response = agentsClient.ListAgentsAsync(request); // Iterate over all response items, lazily performing RPCs as required await response.ForEachAsync((Agent 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((ListAgentsResponse page) => { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (Agent 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 <Agent> 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 (Agent 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 }