コード例 #1
0
        // [END vision_product_search_add_product_to_product_set]

        // [START vision_product_search_list_products_in_product_set]
        private static int ListProductsInProductSet(ListProductsInProductSetOptions opts)
        {
            var client  = ProductSearchClient.Create();
            var request = new ListProductsInProductSetRequest
            {
                // Get the full path of the product set.
                ProductSetName = new ProductSetName(opts.ProjectID,
                                                    opts.ComputeRegion,
                                                    opts.ProductSetId)
            };

            var products = client.ListProductsInProductSet(request);

            Console.WriteLine("Products in product set:");
            foreach (var product in products)
            {
                Console.WriteLine($"Product name: {product.Name}");
                Console.WriteLine($"Product id: {product.Name.Split("/").Last()}");
                Console.WriteLine($"Product display name: {product.DisplayName}");
                Console.WriteLine($"Product description: {product.Description}");
                Console.WriteLine($"Product category: {product.ProductCategory}");
                Console.WriteLine($"Product labels:");
                foreach (var label in product.ProductLabels)
                {
                    Console.WriteLine($"Label: {label}");
                }
            }

            return(0);
        }
コード例 #2
0
        public async Task <IEnumerable <Target> > GetTargets(string targetSetId, int page, int pageSize)
        {
            GoogleCredential cred = this.CreateCredentials();
            var channel           = new Channel(ProductSearchClient.DefaultEndpoint.Host, ProductSearchClient.DefaultEndpoint.Port, cred.ToChannelCredentials());

            try
            {
                var client = ProductSearchClient.Create(channel);

                ListProductsInProductSetRequest request = new ListProductsInProductSetRequest
                {
                    ProductSetName = new ProductSetName(this.options.Value.ProjectId, this.options.Value.LocationId, targetSetId),
                    PageSize       = pageSize,
                };

                PagedAsyncEnumerable <ListProductsInProductSetResponse, Product> response = client.ListProductsInProductSetAsync(request);
                IEnumerable <Product> products = await response.AsAsyncEnumerable().ToArray();

                IEnumerable <Target> targets = await Task.WhenAll(products.Select(p => this.LoadReferenceImagesAndMapToTarget(client, p, pageSize)));

                return(targets);
            }
            finally
            {
                await channel.ShutdownAsync();
            }
        }
コード例 #3
0
        //public async Task GetTargetSets()
        //{
        //    GoogleCredential cred = this.CreateCredentials();
        //    var channel = new Channel(ProductSearchClient.DefaultEndpoint.Host, ProductSearchClient.DefaultEndpoint.Port, cred.ToChannelCredentials());

        //    try
        //    {
        //        var client = ProductSearchClient.Create(channel);
        //        // var productSet = await this.GetProductSets(client, 100);

        //        // productSet.

        //    }
        //    finally
        //    {
        //        await channel.ShutdownAsync();
        //    }
        //}

        //public async Task CreateTargetSet(string targetSetId, string displayName)
        //{
        //    GoogleCredential cred = this.CreateCredentials();
        //    var channel = new Channel(ProductSearchClient.DefaultEndpoint.Host, ProductSearchClient.DefaultEndpoint.Port, cred.ToChannelCredentials());

        //    try
        //    {
        //        var client = ProductSearchClient.Create(channel);

        //        var createProductSetOptions = new CreateProductSetsOptions
        //        {
        //            ProjectID = this.options.Value.ProjectId,
        //            ComputeRegion = this.options.Value.LocationId,
        //            ProductSetId = targetSetId,
        //            ProductSetDisplayName = displayName,
        //        };
        //        var productSet = await this.CreateProductSet(client, createProductSetOptions);
        //    }
        //    finally
        //    {
        //        await channel.ShutdownAsync();
        //    }
        //}

        public async Task <IEnumerable <Target> > GetTargets(string targetSetId, int skip = 0, int take = 10)
        {
            var client = await ProductSearchClient.CreateAsync();

            var request = new ListProductsInProductSetRequest
            {
                ProductSetName = new ProductSetName(this.options.Value.ProjectId, this.options.Value.LocationId, targetSetId),
                PageSize       = take,
            };

            PagedAsyncEnumerable <ListProductsInProductSetResponse, Product> response = client.ListProductsInProductSetAsync(request);
            var page = await response.ReadPageAsync(take);

            IEnumerable <Product> products = page.ToArray();
            IEnumerable <Target>  targets  = await Task.WhenAll(products.Select(p => this.LoadReferenceImagesAndMapToTarget(client, p, 10)));

            return(targets);
        }