public async Task <Target> GetTarget(string targetId) { var client = await ProductSearchClient.CreateAsync(); Product product = await this.GetProduct(client, targetId); return(await this.LoadReferenceImagesAndMapToTarget(client, product, 100)); }
//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); }