Пример #1
0
        public virtual async Task <ExchangeRateStatisticInfo> GetExchangeRates(DateTime startDate, DateTime endDate, string code)
        {
            var cachedResult = this.rateCache.GetExchange(code, startDate, endDate);

            if (cachedResult != null)
            {
                return(cachedResult);
            }

            (double?median, double?min, double?max) = this.GetExchangeRatesFromDB(startDate, endDate, code);

            // усилить проверку - данных может не быть только на части интервала
            if (!median.HasValue)
            {
                if (startDate.Year != endDate.Year)
                {
                    await this.integrationJob.FillCurrentRate(startDate);
                }

                await this.integrationJob.FillCurrentRate(endDate);

                (median, min, max) = this.GetExchangeRatesFromDB(startDate, endDate, code);
            }

            cachedResult = new ExchangeRateStatisticInfo
            {
                Code       = code,
                MaxRate    = max ?? 0,
                MedianRate = median ?? 0,
                MinRate    = min ?? 0
            };
            this.rateCache.AddExchange(cachedResult, startDate, endDate);

            return(cachedResult);
        }
Пример #2
0
        public virtual void AddExchange(ExchangeRateStatisticInfo info, DateTime startDate, DateTime endDate)
        {
            string key = GetKey(info.Code, startDate, endDate);

            this.cache.AddOrUpdate(key, info, (k, prevValue) => info);
        }