Exemple #1
0
        public async Task<ProductsWithRanking> GetProductsByKeywordAsync(string keyword, PagingOptions options)
        {
            using (var log = RequestLogger.Current.BeginJungoLog(this))
            {
                ProductsWithRanking kwProds;
                try
                {
                    var billboard = await Billboard.GetAsync(Client).ConfigureAwait(false);
                    // nudge, nudge: gives us back a baby srch result, not the full ProductWithRanking
                    var kwUri = Billboard.ResolveTemplate(billboard.Products, Billboard.Templates.ProductsKeywordQuery,
                        new {keyword, pageNumber = options.Page, pageSize = options.PageSize, sort = options.Sort});
                    var response =
                        await Client.GetCacheableAsync<ProductsWithRankingResponse>(kwUri).ConfigureAwait(false);
                    if (response == null || response.Products == null || response.Products.Product == null) return new ProductsWithRanking {Product = new ProductWithRanking[0]};
                    kwProds = response.Products;
                }
                catch (Exception exc)
                {
                    throw log.LogException(exc);
                }

                // fire up parallel calls to get papa products
                var prods = new Task<Product>[kwProds.Product.Length];
                for (var idx = 0; idx < kwProds.Product.Length; idx++)
                    prods[idx] = GetProductAsync(kwProds.Product[idx]);
                // wait for all
                // put papa prods into keywords response
                var exceptions = new List<Exception>();
                for (var idx = 0; idx < prods.Length; idx++)
                {
                    try
                    {
                        var response = await prods[idx].ConfigureAwait(false);
                        if (response != null)
                            kwProds.Product[idx].InjectFrom(response);
                    }
                    catch (Exception exc)
                    {
                        exceptions.Add(exc);
                    }
                }
                if (exceptions.Any())
                    throw log.LogException(new AggregateException(exceptions));
                return kwProds;
            }
        }
        public async Task<CatalogPageViewModel> SearchProductByCategoryAsync(long categoryId, PagingOptions pagingOptions)
        {
            var category = await _catalogApi.GetCategoryAsync(_catalogApi.GetCategoryUri(categoryId)).ConfigureAwait(false);
            var categoryViewModel = CreateCategoryViewModel(category, categoryId);
            if (pagingOptions == null) pagingOptions = new PagingOptions();

            if (categoryViewModel == null)
            {

                var viewModel = new CatalogPageViewModel
                {
                    CategoryId = categoryId,
                    Products = new Products { Product = new Product[0] }
                };
                viewModel.SetPageTitle("Catalog");
                return viewModel;
            }

            Products searchResult;
            try
            {
                searchResult = await _catalogApi.GetProductsForCategoryAsync(category, pagingOptions).ConfigureAwait(false);
            }
            catch (Exception)
            {
                searchResult = new Products { Product = new Product[0] };
            }

            var viewMod = new CatalogPageViewModel
            {
                Title = categoryViewModel.DisplayName,
                CategoryId = categoryId,
                Products = searchResult,
                KeyWords = categoryViewModel.Keywords,
                TotalPages = searchResult.TotalResultPages,
                TotalResults = searchResult.TotalResults,
                PageSize = pagingOptions.PageSize ?? DefaultPageSize,
                CurrentPage = pagingOptions.Page ?? FirstPage,
                SeoTitleTag = categoryViewModel.Attributes.ValueByName("Custom Title"),
                SeoMetaDescription = categoryViewModel.Attributes.ValueByName("Meta Description"),
                SeoMetaKeywords = categoryViewModel.Attributes.ValueByName("Meta Keywords")
            };
            viewMod.SetPageTitle(categoryViewModel.DisplayName);

            return viewMod;
        }
Exemple #3
0
 public async Task<Products> GetProductsForCategoryAsync(Category category, PagingOptions options)
 {
     using (var log = RequestLogger.Current.BeginJungoLog(this))
     {
         try
         {
             var uri = Billboard.ResolvePagingOptions(category.Products.Uri, options);
             var prodResponse = await Client.GetCacheableAsync<ProductsResponse>(uri).ConfigureAwait(false);
             if (prodResponse == null) return null;
             var catProds = prodResponse.Products;
             catProds.Product = (await GetProductsAsync(catProds.Product).ConfigureAwait(false)).ToArray();
             return catProds;
         }
         catch (Exception exc)
         {
             throw log.LogException(exc);
         }
     }
 }
Exemple #4
0
 public static string ResolvePagingOptions(string uri, PagingOptions options)
 {
     return (options == null) ? 
         ResolveExpandAll(uri) :
         ResolveTemplate(uri, Templates.PagingOptionsQuery, new { pageNumber = options.Page, pageSize = options.PageSize, sort = options.Sort });
 }