Example #1
0
        /// <summary>Snippet for DeleteIndexAsync</summary>
        public async Task DeleteIndexResourceNamesAsync()
        {
            // Snippet: DeleteIndexAsync(IndexName, CallSettings)
            // Additional: DeleteIndexAsync(IndexName, CancellationToken)
            // Create client
            IndexServiceClient indexServiceClient = await IndexServiceClient.CreateAsync();

            // Initialize request argument(s)
            IndexName name = IndexName.FromProjectLocationIndex("[PROJECT]", "[LOCATION]", "[INDEX]");
            // Make the request
            Operation <Empty, DeleteOperationMetadata> response = await indexServiceClient.DeleteIndexAsync(name);

            // Poll until the returned long-running operation is complete
            Operation <Empty, DeleteOperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

            // Retrieve the operation result
            Empty 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 <Empty, DeleteOperationMetadata> retrievedResponse = await indexServiceClient.PollOnceDeleteIndexAsync(operationName);

            // Check if the retrieved long-running operation has completed
            if (retrievedResponse.IsCompleted)
            {
                // If it has completed, then access the result
                Empty retrievedResult = retrievedResponse.Result;
            }
            // End snippet
        }
Example #2
0
        /// <summary>Snippet for UpdateIndexAsync</summary>
        public async Task UpdateIndexAsync()
        {
            // Snippet: UpdateIndexAsync(Index, FieldMask, CallSettings)
            // Additional: UpdateIndexAsync(Index, FieldMask, CancellationToken)
            // Create client
            IndexServiceClient indexServiceClient = await IndexServiceClient.CreateAsync();

            // Initialize request argument(s)
            gcav::Index index      = new gcav::Index();
            FieldMask   updateMask = new FieldMask();
            // Make the request
            Operation <gcav::Index, UpdateIndexOperationMetadata> response = await indexServiceClient.UpdateIndexAsync(index, updateMask);

            // Poll until the returned long-running operation is complete
            Operation <gcav::Index, UpdateIndexOperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

            // Retrieve the operation result
            gcav::Index 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 <gcav::Index, UpdateIndexOperationMetadata> retrievedResponse = await indexServiceClient.PollOnceUpdateIndexAsync(operationName);

            // Check if the retrieved long-running operation has completed
            if (retrievedResponse.IsCompleted)
            {
                // If it has completed, then access the result
                gcav::Index retrievedResult = retrievedResponse.Result;
            }
            // End snippet
        }
Example #3
0
        /// <summary>Snippet for CreateIndexAsync</summary>
        public async Task CreateIndexRequestObjectAsync()
        {
            // Snippet: CreateIndexAsync(CreateIndexRequest, CallSettings)
            // Additional: CreateIndexAsync(CreateIndexRequest, CancellationToken)
            // Create client
            IndexServiceClient indexServiceClient = await IndexServiceClient.CreateAsync();

            // Initialize request argument(s)
            CreateIndexRequest request = new CreateIndexRequest
            {
                ParentAsLocationName = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"),
                Index = new gcav::Index(),
            };
            // Make the request
            Operation <gcav::Index, CreateIndexOperationMetadata> response = await indexServiceClient.CreateIndexAsync(request);

            // Poll until the returned long-running operation is complete
            Operation <gcav::Index, CreateIndexOperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

            // Retrieve the operation result
            gcav::Index 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 <gcav::Index, CreateIndexOperationMetadata> retrievedResponse = await indexServiceClient.PollOnceCreateIndexAsync(operationName);

            // Check if the retrieved long-running operation has completed
            if (retrievedResponse.IsCompleted)
            {
                // If it has completed, then access the result
                gcav::Index retrievedResult = retrievedResponse.Result;
            }
            // End snippet
        }
Example #4
0
        /// <summary>Snippet for ListIndexesAsync</summary>
        public async Task ListIndexesRequestObjectAsync()
        {
            // Snippet: ListIndexesAsync(ListIndexesRequest, CallSettings)
            // Create client
            IndexServiceClient indexServiceClient = await IndexServiceClient.CreateAsync();

            // Initialize request argument(s)
            ListIndexesRequest request = new ListIndexesRequest
            {
                ParentAsLocationName = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"),
                Filter   = "",
                ReadMask = new FieldMask(),
            };
            // Make the request
            PagedAsyncEnumerable <ListIndexesResponse, gcav::Index> response = indexServiceClient.ListIndexesAsync(request);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((gcav::Index 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((ListIndexesResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (gcav::Index 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 <gcav::Index> 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 (gcav::Index 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
        }
Example #5
0
        /// <summary>Snippet for GetIndexAsync</summary>
        public async Task GetIndexResourceNamesAsync()
        {
            // Snippet: GetIndexAsync(IndexName, CallSettings)
            // Additional: GetIndexAsync(IndexName, CancellationToken)
            // Create client
            IndexServiceClient indexServiceClient = await IndexServiceClient.CreateAsync();

            // Initialize request argument(s)
            IndexName name = IndexName.FromProjectLocationIndex("[PROJECT]", "[LOCATION]", "[INDEX]");
            // Make the request
            gcav::Index response = await indexServiceClient.GetIndexAsync(name);

            // End snippet
        }
Example #6
0
        /// <summary>Snippet for GetIndexAsync</summary>
        public async Task GetIndexAsync()
        {
            // Snippet: GetIndexAsync(string, CallSettings)
            // Additional: GetIndexAsync(string, CancellationToken)
            // Create client
            IndexServiceClient indexServiceClient = await IndexServiceClient.CreateAsync();

            // Initialize request argument(s)
            string name = "projects/[PROJECT]/locations/[LOCATION]/indexes/[INDEX]";
            // Make the request
            gcav::Index response = await indexServiceClient.GetIndexAsync(name);

            // End snippet
        }