Esempio n. 1
0
        public async Task RunCacheJob(SearchCacheModel model)
        {
            List <Task <SearchResultOverview> > searchJobs = new List <Task <SearchResultOverview> >();

            var criteria = JsonConvert.DeserializeObject <SearchCriteria>(JsonConvert.SerializeObject(model.Criteria));

            criteria.Page = model.PageFrom;

            await SearchServiceProvider.RetrieveSearchServices(webServices, cache, criteria);

            var pages = new List <int>();

            for (int from = model.PageFrom; from <= model.PageTo; from++)
            {
                if (!await existItemSearch(criteria, from))
                {
                    pages.Add(from);
                }
            }

            var resultsTask = SearchDispatcher.Search(webServices, pages.ToArray());

            var uncertain = JsonConvert.DeserializeObject <Item[]>(await getUncertain(criteria));

            var results = await resultsTask;

            results.Items.AddRange(uncertain);

            //Cache the pages asked
            int index = 1;

            foreach (int page in pages)
            {
                criteria.Page = page;
                await cacheItemSearch(criteria, SearchFormatter.FormatResults(index++, results).Results);
            }

            var leftOver = results.Items.Skip((results.Items.Count / SearchFormatter.ResultsPerPage) * SearchFormatter.ResultsPerPage);

            //Cache the states of the web services
            await cacheServices(webServices);

            await cacheUncertain(criteria, leftOver);
        }
Esempio n. 2
0
        public async Task <SearchResultOverview> SearchItems(SearchCriteria search)
        {
            //Check for cached item list
            string key = RedisKeyConvert.Serialize(search);

            SearchResultOverview result = null;

            try
            {
                storeSearchHistory(search);

                if (await cache.Exists(key))
                {
                    var cachedResult = JsonConvert.DeserializeObject <SearchResultOverview>(await cache.GetString(key));

                    result = cachedResult;
                }
                else
                {
                    await SearchServiceProvider.RetrieveSearchServices(services, cache, search, allNew : true);

                    var results = await SearchDispatcher.Search(services, new int[] { search.Page });

                    var formattedResults = SearchFormatter.FormatResults(0, results);

                    await searchCache.CacheSearch(search, services, formattedResults.Results);

                    result = formattedResults.Results;
                }

                searchCache.StartCacheJob(search, null);
            }
            catch (Exception e)
            {
                await raven.CaptureNetCoreEventAsync(e);
            }

            return(result);
        }