Ejemplo n.º 1
0
        public async Task <IReadOnlyCollection <Currency> > GetAsync(
            DateTime startDate, DateTime endDate, params string[] codes)
        {
            if (codes == null || endDate < startDate)
            {
                return(new Currency[0]);
            }

            DbCurrencyValue[] currencyValues;

            using (var context = _conetextFactory.Create())
            {
                var currencyValuesRq = context.DbCurrencyValues
                                       .Include(e => e.Currency)
                                       .Where(e => startDate <= e.Date && e.Date <= endDate)
                                       .Where(e => codes.Contains(e.Currency.Code));

                if (codes.Any())
                {
                    currencyValuesRq = currencyValuesRq
                                       .Where(e => codes.Contains(e.Currency.Code));
                }

                currencyValues = await currencyValuesRq.ToArrayAsync();
            }

            var result = currencyValues
                         .AsParallel()
                         .Select(e => _currecyFactory.Create(e.Currency.Code, e.Amount, e.Rate, e.Date))
                         .ToArray();

            return(result);
        }
Ejemplo n.º 2
0
        private static async Task Load(ICurrencyRepository curencyRepository,
                                       ICurrecyFactory currecyFactory,
                                       IEnumerable <CnbCurrencyHistory> recordsToHandle)
        {
            var currecies = recordsToHandle
                            .Select(e => currecyFactory.Create(e.Code, e.Amount, e.Rate, e.Date))
                            .ToArray();

            await curencyRepository.SaveAsync(currecies);
        }
Ejemplo n.º 3
0
        private void Timer_Elapsed(object sender, ElapsedEventArgs eaArgs)
        {
            var timer = (System.Timers.Timer)sender;
            var date  = DateTime.Today;

            timer.Stop();
            try
            {
                var currentCureciesTask = _currencyDataProvier.GetCurrentCurrencyAsync(
                    date, async e =>
                {
                    var currency = _currecyFactory.Create(e.Code, e.Amount, e.Rate, date);
                    await _currencyRepository.SaveAsync(currency);
                });
                currentCureciesTask.Wait();
            }
            catch (Exception e)
            {
                _logger.LogError(e, "GetCurrentCurrencyAsync ERROR!");
            }

            timer.Start();
        }