/// <summary>Snippet for ListInstanceConfigsAsync</summary> public async Task ListInstanceConfigsAsync() { // Snippet: ListInstanceConfigsAsync(ProjectName,string,int?,CallSettings) // Create client InstanceAdminClient instanceAdminClient = await InstanceAdminClient.CreateAsync(); // Initialize request argument(s) ProjectName parent = new ProjectName("[PROJECT]"); // Make the request PagedAsyncEnumerable <ListInstanceConfigsResponse, InstanceConfig> response = instanceAdminClient.ListInstanceConfigsAsync(parent); // Iterate over all response items, lazily performing RPCs as required await response.ForEachAsync((InstanceConfig 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((ListInstanceConfigsResponse page) => { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (InstanceConfig item in page) { 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 <InstanceConfig> 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 (InstanceConfig item in singlePage) { Console.WriteLine(item); } // Store the pageToken, for when the next page is required. string nextPageToken = singlePage.NextPageToken; // End snippet }
private async Task CreateInstanceWithMultiRegionAsync() { InstanceAdminClient instanceAdminClient = await InstanceAdminClient.CreateAsync(); var projectName = ProjectName.FromProject(ProjectId); Instance instance = new Instance { DisplayName = "Multi-region samples test", ConfigAsInstanceConfigName = InstanceConfigName.FromProjectInstanceConfig(ProjectId, InstanceConfigId), InstanceName = InstanceName.FromProjectInstance(ProjectId, InstanceIdWithMultiRegion), NodeCount = 1, }; await SafeCreateInstanceAsync(async() => { var response = await instanceAdminClient.CreateInstanceAsync(projectName, InstanceIdWithMultiRegion, instance); // Poll until the returned long-running operation is complete response = await response.PollUntilCompletedAsync(); return(response.Result); }); }
private async Task <bool> InitializeInstanceAsync() { InstanceAdminClient instanceAdminClient = await InstanceAdminClient.CreateAsync(); InstanceName instanceName = InstanceName.FromProjectInstance(ProjectId, InstanceId); try { Instance response = await instanceAdminClient.GetInstanceAsync(instanceName); return(true); } catch (RpcException ex) when(ex.Status.StatusCode == StatusCode.NotFound) { CreateInstanceSample createInstanceSample = new CreateInstanceSample(); await SafeCreateInstanceAsync(() => Task.FromResult(createInstanceSample.CreateInstance(ProjectId, InstanceId))); return(false); } }
/// <summary>Snippet for CreateInstanceAsync</summary> public async Task CreateInstanceAsync_RequestObject() { // Snippet: CreateInstanceAsync(CreateInstanceRequest,CallSettings) // Create client InstanceAdminClient instanceAdminClient = await InstanceAdminClient.CreateAsync(); // Initialize request argument(s) CreateInstanceRequest request = new CreateInstanceRequest { ParentAsProjectName = new ProjectName("[PROJECT]"), InstanceIdAsInstanceName = new InstanceName("[PROJECT]", "[INSTANCE]"), Instance = new Instance(), }; // Make the request Operation <Instance, CreateInstanceMetadata> response = await instanceAdminClient.CreateInstanceAsync(request); // Poll until the returned long-running operation is complete Operation <Instance, CreateInstanceMetadata> completedResponse = await response.PollUntilCompletedAsync(); // Retrieve the operation result Instance 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 <Instance, CreateInstanceMetadata> retrievedResponse = await instanceAdminClient.PollOnceCreateInstanceAsync(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result Instance retrievedResult = retrievedResponse.Result; } // End snippet }
/// <summary>Snippet for UpdateInstanceAsync</summary> public async Task UpdateInstanceAsync_RequestObject() { // Snippet: UpdateInstanceAsync(UpdateInstanceRequest,CallSettings) // Create client InstanceAdminClient instanceAdminClient = await InstanceAdminClient.CreateAsync(); // Initialize request argument(s) UpdateInstanceRequest request = new UpdateInstanceRequest { Instance = new Instance(), FieldMask = new FieldMask(), }; // Make the request Operation <Instance, UpdateInstanceMetadata> response = await instanceAdminClient.UpdateInstanceAsync(request); // Poll until the returned long-running operation is complete Operation <Instance, UpdateInstanceMetadata> completedResponse = await response.PollUntilCompletedAsync(); // Retrieve the operation result Instance 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 <Instance, UpdateInstanceMetadata> retrievedResponse = await instanceAdminClient.PollOnceUpdateInstanceAsync(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result Instance retrievedResult = retrievedResponse.Result; } // End snippet }
public async Task CreateInstanceAsync() { // Snippet: CreateInstanceAsync(string,string,Instance,CallSettings) // Additional: CreateInstanceAsync(string,string,Instance,CancellationToken) // Create client InstanceAdminClient instanceAdminClient = await InstanceAdminClient.CreateAsync(); // Initialize request argument(s) string formattedParent = new ProjectName("[PROJECT]").ToString(); string instanceId = ""; Instance instance = new Instance(); // Make the request Operation <Instance> response = await instanceAdminClient.CreateInstanceAsync(formattedParent, instanceId, instance); // Poll until the returned long-running operation is complete Operation <Instance> completedResponse = await response.PollUntilCompletedAsync(); // Retrieve the operation result Instance 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 <Instance> retrievedResponse = await instanceAdminClient.PollOnceCreateInstanceAsync(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result Instance retrievedResult = retrievedResponse.Result; } // End snippet }