Ejemplo n.º 1
0
        public async Task CreateAsync(VendorDto vendor)
        {
            var search = await GetSearchAsync(vendor);

            await SearchRepository.CreateAsync(search);
        }
Ejemplo n.º 2
0
        public async Task <SearchResponse> SearchAsync(SearchRequest request)
        {
            try
            {
                List <SearchResultItem> results = null;
                var response = new SearchResponse();

                string key = string.Format("SearchResults_{0}", HttpUtility.UrlEncode(request.QueryWord));
                response.QueryWord = request.QueryWord;

                if (false == _cache.TryGetValue(key, out results))
                {
                    var    enteredDate = DateTime.Now;
                    string error       = string.Empty;

                    foreach (var crawler in _crawlers)
                    {
                        var crawlingRequest = buildCrawlingRequest(request);
                        var crawlingResult  = await crawler.CrawleAsync(crawlingRequest);

                        if (crawlingResult == null)
                        {
                            error = string.Format("Error occurred while crawling {0} search engine.", crawler.SearchEngine);
                            _logger.Error(error);
                            return(SearchResponse.FromError(error));
                        }

                        results = new List <SearchResultItem>();
                        foreach (var item in crawlingResult.SearchResults)
                        {
                            item.EnteredDate = enteredDate;
                            var resultItem = await _repository.CreateAsync(item);

                            if (resultItem == null)
                            {
                                error = "Error occurred while saving search result item in DB";
                                _logger.Error(error);
                            }
                            else
                            {
                                results.Add(resultItem);
                            }
                        }

                        response.Results.AddRange(results);
                    }

                    var cacheEntryOptions = new MemoryCacheEntryOptions()
                                            .SetSlidingExpiration(TimeSpan.FromHours(1));

                    _cache.Set(key, response.Results, cacheEntryOptions);
                }
                else
                {
                    response.Results.AddRange(results);
                }

                return(response);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                return(SearchResponse.FromException(ex));
            }
        }
Ejemplo n.º 3
0
        public async Task CreateAsync(Discount discount)
        {
            var search = await GetSearchAsync(discount);

            await SearchRepository.CreateAsync(search);
        }