示例#1
0
    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
        }
示例#4
0
        /// <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 InsertAsync</summary>
        public async Task InsertAsync()
        {
            // Snippet: InsertAsync(string, Image, CallSettings)
            // Additional: InsertAsync(string, Image, CancellationToken)
            // Create client
            ImagesClient imagesClient = await ImagesClient.CreateAsync();

            // Initialize request argument(s)
            string project       = "";
            Image  imageResource = new Image();
            // Make the request
            Operation response = await imagesClient.InsertAsync(project, imageResource);

            // End snippet
        }
        /// <summary>Snippet for DeleteAsync</summary>
        public async Task DeleteAsync()
        {
            // Snippet: DeleteAsync(string, string, CallSettings)
            // Additional: DeleteAsync(string, string, CancellationToken)
            // Create client
            ImagesClient imagesClient = await ImagesClient.CreateAsync();

            // Initialize request argument(s)
            string project = "";
            string image   = "";
            // Make the request
            Operation response = await imagesClient.DeleteAsync(project, image);

            // End snippet
        }
        /// <summary>Snippet for GetIamPolicyAsync</summary>
        public async Task GetIamPolicyAsync()
        {
            // Snippet: GetIamPolicyAsync(string, string, CallSettings)
            // Additional: GetIamPolicyAsync(string, string, CancellationToken)
            // Create client
            ImagesClient imagesClient = await ImagesClient.CreateAsync();

            // Initialize request argument(s)
            string project  = "";
            string resource = "";
            // Make the request
            Policy response = await imagesClient.GetIamPolicyAsync(project, resource);

            // End snippet
        }
        /// <summary>Snippet for TestIamPermissionsAsync</summary>
        public async Task TestIamPermissionsAsync()
        {
            // Snippet: TestIamPermissionsAsync(string, string, TestPermissionsRequest, CallSettings)
            // Additional: TestIamPermissionsAsync(string, string, TestPermissionsRequest, CancellationToken)
            // Create client
            ImagesClient imagesClient = await ImagesClient.CreateAsync();

            // Initialize request argument(s)
            string project  = "";
            string resource = "";
            TestPermissionsRequest testPermissionsRequestResource = new TestPermissionsRequest();
            // Make the request
            TestPermissionsResponse response = await imagesClient.TestIamPermissionsAsync(project, resource, testPermissionsRequestResource);

            // End snippet
        }
        /// <summary>Snippet for SetLabelsAsync</summary>
        public async Task SetLabelsAsync()
        {
            // Snippet: SetLabelsAsync(string, string, GlobalSetLabelsRequest, CallSettings)
            // Additional: SetLabelsAsync(string, string, GlobalSetLabelsRequest, CancellationToken)
            // Create client
            ImagesClient imagesClient = await ImagesClient.CreateAsync();

            // Initialize request argument(s)
            string project  = "";
            string resource = "";
            GlobalSetLabelsRequest globalSetLabelsRequestResource = new GlobalSetLabelsRequest();
            // Make the request
            Operation response = await imagesClient.SetLabelsAsync(project, resource, globalSetLabelsRequestResource);

            // End snippet
        }
        /// <summary>Snippet for GetFromFamilyAsync</summary>
        public async Task GetFromFamilyRequestObjectAsync()
        {
            // Snippet: GetFromFamilyAsync(GetFromFamilyImageRequest, CallSettings)
            // Additional: GetFromFamilyAsync(GetFromFamilyImageRequest, CancellationToken)
            // Create client
            ImagesClient imagesClient = await ImagesClient.CreateAsync();

            // Initialize request argument(s)
            GetFromFamilyImageRequest request = new GetFromFamilyImageRequest
            {
                Project = "",
                Family  = "",
            };
            // Make the request
            Image response = await imagesClient.GetFromFamilyAsync(request);

            // End snippet
        }
        /// <summary>Snippet for TestIamPermissionsAsync</summary>
        public async Task TestIamPermissionsRequestObjectAsync()
        {
            // Snippet: TestIamPermissionsAsync(TestIamPermissionsImageRequest, CallSettings)
            // Additional: TestIamPermissionsAsync(TestIamPermissionsImageRequest, CancellationToken)
            // Create client
            ImagesClient imagesClient = await ImagesClient.CreateAsync();

            // Initialize request argument(s)
            TestIamPermissionsImageRequest request = new TestIamPermissionsImageRequest
            {
                Resource = "",
                Project  = "",
                TestPermissionsRequestResource = new TestPermissionsRequest(),
            };
            // Make the request
            TestPermissionsResponse response = await imagesClient.TestIamPermissionsAsync(request);

            // End snippet
        }
        /// <summary>Snippet for SetLabelsAsync</summary>
        public async Task SetLabelsRequestObjectAsync()
        {
            // Snippet: SetLabelsAsync(SetLabelsImageRequest, CallSettings)
            // Additional: SetLabelsAsync(SetLabelsImageRequest, CancellationToken)
            // Create client
            ImagesClient imagesClient = await ImagesClient.CreateAsync();

            // Initialize request argument(s)
            SetLabelsImageRequest request = new SetLabelsImageRequest
            {
                Resource = "",
                Project  = "",
                GlobalSetLabelsRequestResource = new GlobalSetLabelsRequest(),
            };
            // Make the request
            Operation response = await imagesClient.SetLabelsAsync(request);

            // End snippet
        }
        /// <summary>Snippet for DeleteAsync</summary>
        public async Task DeleteRequestObjectAsync()
        {
            // Snippet: DeleteAsync(DeleteImageRequest, CallSettings)
            // Additional: DeleteAsync(DeleteImageRequest, CancellationToken)
            // Create client
            ImagesClient imagesClient = await ImagesClient.CreateAsync();

            // Initialize request argument(s)
            DeleteImageRequest request = new DeleteImageRequest
            {
                RequestId = "",
                Image     = "",
                Project   = "",
            };
            // Make the request
            Operation response = await imagesClient.DeleteAsync(request);

            // End snippet
        }
        /// <summary>Snippet for GetIamPolicyAsync</summary>
        public async Task GetIamPolicyRequestObjectAsync()
        {
            // Snippet: GetIamPolicyAsync(GetIamPolicyImageRequest, CallSettings)
            // Additional: GetIamPolicyAsync(GetIamPolicyImageRequest, CancellationToken)
            // Create client
            ImagesClient imagesClient = await ImagesClient.CreateAsync();

            // Initialize request argument(s)
            GetIamPolicyImageRequest request = new GetIamPolicyImageRequest
            {
                Resource = "",
                Project  = "",
                OptionsRequestedPolicyVersion = 0,
            };
            // Make the request
            Policy response = await imagesClient.GetIamPolicyAsync(request);

            // End snippet
        }
        /// <summary>Snippet for PatchAsync</summary>
        public async Task PatchRequestObjectAsync()
        {
            // Snippet: PatchAsync(PatchImageRequest, CallSettings)
            // Additional: PatchAsync(PatchImageRequest, CancellationToken)
            // Create client
            ImagesClient imagesClient = await ImagesClient.CreateAsync();

            // Initialize request argument(s)
            PatchImageRequest request = new PatchImageRequest
            {
                RequestId     = "",
                Image         = "",
                Project       = "",
                ImageResource = new Image(),
            };
            // Make the request
            Operation response = await imagesClient.PatchAsync(request);

            // End snippet
        }
        /// <summary>Snippet for InsertAsync</summary>
        public async Task InsertRequestObjectAsync()
        {
            // Snippet: InsertAsync(InsertImageRequest, CallSettings)
            // Additional: InsertAsync(InsertImageRequest, CancellationToken)
            // Create client
            ImagesClient imagesClient = await ImagesClient.CreateAsync();

            // Initialize request argument(s)
            InsertImageRequest request = new InsertImageRequest
            {
                RequestId     = "",
                ForceCreate   = false,
                Project       = "",
                ImageResource = new Image(),
            };
            // Make the request
            Operation response = await imagesClient.InsertAsync(request);

            // End snippet
        }
示例#17
0
        /// <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
        }