/// <summary>Snippet for CreateBatchAsync</summary> public async Task CreateBatchResourceNamesAsync() { // Snippet: CreateBatchAsync(LocationName, Batch, string, CallSettings) // Additional: CreateBatchAsync(LocationName, Batch, string, CancellationToken) // Create client BatchControllerClient batchControllerClient = await BatchControllerClient.CreateAsync(); // Initialize request argument(s) LocationName parent = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"); Batch batch = new Batch(); string batchId = ""; // Make the request Operation <Batch, BatchOperationMetadata> response = await batchControllerClient.CreateBatchAsync(parent, batch, batchId); // Poll until the returned long-running operation is complete Operation <Batch, BatchOperationMetadata> completedResponse = await response.PollUntilCompletedAsync(); // Retrieve the operation result Batch result = completedResponse.Result; // Or get the name of the operation string operationName = response.Name; // This name can be stored, then the long-running operation retrieved later by name Operation <Batch, BatchOperationMetadata> retrievedResponse = await batchControllerClient.PollOnceCreateBatchAsync(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result Batch retrievedResult = retrievedResponse.Result; } // End snippet }
/// <summary>Snippet for DeleteBatchAsync</summary> public async Task DeleteBatchResourceNamesAsync() { // Snippet: DeleteBatchAsync(BatchName, CallSettings) // Additional: DeleteBatchAsync(BatchName, CancellationToken) // Create client BatchControllerClient batchControllerClient = await BatchControllerClient.CreateAsync(); // Initialize request argument(s) BatchName name = BatchName.FromProjectLocationBatch("[PROJECT]", "[LOCATION]", "[BATCH]"); // Make the request await batchControllerClient.DeleteBatchAsync(name); // End snippet }
/// <summary>Snippet for DeleteBatchAsync</summary> public async Task DeleteBatchAsync() { // Snippet: DeleteBatchAsync(string, CallSettings) // Additional: DeleteBatchAsync(string, CancellationToken) // Create client BatchControllerClient batchControllerClient = await BatchControllerClient.CreateAsync(); // Initialize request argument(s) string name = "projects/[PROJECT]/locations/[LOCATION]/batches/[BATCH]"; // Make the request await batchControllerClient.DeleteBatchAsync(name); // End snippet }
/// <summary>Snippet for ListBatchesAsync</summary> public async Task ListBatchesRequestObjectAsync() { // Snippet: ListBatchesAsync(ListBatchesRequest, CallSettings) // Create client BatchControllerClient batchControllerClient = await BatchControllerClient.CreateAsync(); // Initialize request argument(s) ListBatchesRequest request = new ListBatchesRequest { ParentAsLocationName = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"), }; // Make the request PagedAsyncEnumerable <ListBatchesResponse, Batch> response = batchControllerClient.ListBatchesAsync(request); // Iterate over all response items, lazily performing RPCs as required await response.ForEachAsync((Batch 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((ListBatchesResponse page) => { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (Batch 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 <Batch> 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 (Batch 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 GetBatchAsync</summary> public async Task GetBatchRequestObjectAsync() { // Snippet: GetBatchAsync(GetBatchRequest, CallSettings) // Additional: GetBatchAsync(GetBatchRequest, CancellationToken) // Create client BatchControllerClient batchControllerClient = await BatchControllerClient.CreateAsync(); // Initialize request argument(s) GetBatchRequest request = new GetBatchRequest { BatchName = BatchName.FromProjectLocationBatch("[PROJECT]", "[LOCATION]", "[BATCH]"), }; // Make the request Batch response = await batchControllerClient.GetBatchAsync(request); // End snippet }