public async Task ListImagesPerPageAsync( // TODO(developer): Set your own default values for these parameters or pass different values when calling this method. string projectId = "your-project-id") { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. ImagesClient client = await ImagesClient.CreateAsync(); // Make the request to list all non-deprecated images in a project. ListImagesRequest request = new ListImagesRequest { Project = projectId, // Listing only non-deprecated images to reduce the size of the reply. Filter = "deprecated.state != DEPRECATED", // MaxResults indicates the maximum number of items that will be returned per page. MaxResults = 10 }; // Call the AsRawResponses() method of the returned image sequence to access the page sequece instead // This allows you to have more granular control of iteration over paginated results from the API. // Each time you access the next page, the library retrieves that page from the API. int pageIndex = 0; await foreach (var page in client.ListAsync(request).AsRawResponses()) { Console.WriteLine($"Page index: {pageIndex}"); pageIndex++; foreach (var image in page) { // The result is an Image collection. Console.WriteLine($"Image: {image.Name}"); } } }
public async Task ListImagesAsync( // TODO(developer): Set your own default values for these parameters or pass different values when calling this method. string projectId = "your-project-id") { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. ImagesClient client = await ImagesClient.CreateAsync(); // Make the request to list all non-deprecated images in a project. ListImagesRequest request = new ListImagesRequest { Project = projectId, // Listing only non-deprecated images to reduce the size of the reply. Filter = "deprecated.state != DEPRECATED", // MaxResults indicates the maximum number of items that will be returned per page. MaxResults = 100 }; // Although the MaxResults parameter is specified in the request, the sequence returned // by the ListAsync() method hides the pagination mechanic. The library makes multiple // requests to the API for you, so you can simply iterate over all the images. await foreach (var image in client.ListAsync(request)) { // The result is an Image collection. Console.WriteLine($"Image: {image.Name}"); } }
/// <summary>Snippet for ListAsync</summary> public async Task ListRequestObjectAsync() { // Snippet: ListAsync(ListImagesRequest, CallSettings) // Create client ImagesClient imagesClient = await ImagesClient.CreateAsync(); // Initialize request argument(s) ListImagesRequest request = new ListImagesRequest { OrderBy = "", Project = "", Filter = "", ReturnPartialSuccess = false, }; // Make the request PagedAsyncEnumerable <ImageList, Image> response = imagesClient.ListAsync(request); // Iterate over all response items, lazily performing RPCs as required await response.ForEachAsync((Image 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((ImageList page) => { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (Image 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 <Image> 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 (Image 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>Snippet for ListAsync</summary> public async Task ListAsync() { // Snippet: ListAsync(string, CallSettings) // Additional: ListAsync(string, CancellationToken) // Create client ImagesClient imagesClient = await ImagesClient.CreateAsync(); // Initialize request argument(s) string project = ""; // Make the request ImageList response = await imagesClient.ListAsync(project); // End snippet }
/// <summary>Snippet for ListAsync</summary> public async Task ListRequestObjectAsync() { // Snippet: ListAsync(ListImagesRequest, CallSettings) // Additional: ListAsync(ListImagesRequest, CancellationToken) // Create client ImagesClient imagesClient = await ImagesClient.CreateAsync(); // Initialize request argument(s) ListImagesRequest request = new ListImagesRequest { PageToken = "", MaxResults = 0U, Filter = "", OrderBy = "", Project = "", ReturnPartialSuccess = false, }; // Make the request ImageList response = await imagesClient.ListAsync(request); // End snippet }