Ejemplo n.º 1
0
        public async Task <ItemsResult> GetMoreItems(SearchIndexType indexType, int itemPage)
        {
            var filename = string.Format("{0}_{1}.xml", indexType, itemPage);
            var response = await _serializer.ReadFile(CountryType.ToString(), filename);

            var result = LoadedResultType.Cached;

            if (response == null)
            {
                result   = LoadedResultType.Downloaded;
                response = await _service.ItemSearchAsync(CountryType, indexType, itemPage);

                if (string.IsNullOrEmpty(response))
                {
                    result = LoadedResultType.Failed;
                    return(new ItemsResult {
                        Result = result
                    });
                }
                _serializer.WriteFile(CountryType.ToString(), filename, response);
            }
            return(new ItemsResult
            {
                Items = _parser.Parse(response).Where(x => !x.Attributes.IsAdultProduct),
                Result = result,
            });
        }
Ejemplo n.º 2
0
        public async Task <Ranking> GetRanking(SearchIndexType indexType)
        {
            bool   cached   = false;
            string response = null;
            var    key      = string.Format("{0}:{1}", CountryType, indexType);
            var    filename = string.Format("{0}.xml", indexType);
            bool   cache;
            var    pre = _settingStore.Load <DateTime>(key, out cache);

            if (cache)
            {
                var diff = DateTime.Now - pre;
                if (diff.CompareTo(TimeSpan.FromMinutes(30)) < 0)
                {
                    response = await _serializer.ReadFile(CountryType.ToString(), filename);

                    cached = response != null;
                }
                else
                {
                    Enumerable.Range(2, 9).ForEach(async i =>
                    {
                        var deleteName = string.Format("{0}_{1}.xml", indexType, i);
                        await _serializer.DeleteFile(CountryType.ToString(), deleteName);
                    });
                }
            }

            if (response == null)
            {
                response = await _service.ItemSearchAsync(CountryType, indexType, 1);

                if (string.IsNullOrEmpty(response))
                {
                    return(null);
                }
                _serializer.WriteFile(CountryType.ToString(), filename, response);
                _settingStore.Save(key, DateTime.Now.ToString());
            }

            var items = _parser.Parse(response).Where(x => !x.Attributes.IsAdultProduct);

            return(new Ranking(this)
            {
                IndexType = indexType, Items = items, Cached = cached
            });
        }