Exemplo n.º 1
0
        /// <summary>
        /// Create a new instance of the <see cref="Setting{TSetting}"/>
        /// </summary>
        /// <param name="settingStore"><see cref="ISettingStore"/> used for loading and saving settings</param>
        /// <param name="eventAggregator"><see cref="IEventAggregator"/> used to notify subscribers about settings changes</param>
        public Setting(ISettingStore settingStore, IEventAggregator eventAggregator)
        {
            _settingStore = settingStore ?? throw new ArgumentNullException(nameof(settingStore));
            _eventAggregator = eventAggregator ?? throw new ArgumentNullException(nameof(eventAggregator));

            CurrentSetting = _settingStore.Load<TSetting>();
        }
Exemplo 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
            });
        }