Esempio n. 1
0
        public void CheckProviders()
        {
            var lst = _providers.GetCalendarProviders();

            Assert.IsTrue(lst.Count > 0);
            foreach (var provider in lst)
            {
                var rs = provider.GetAmountForDate(new DateTime(2017, 7, 1));
                provider.SetAmountToDate(new DateTime(2017, 7, 1), rs);
            }
        }
Esempio n. 2
0
        public bool UpdateCalendarsFromPlan(DateTime?date = null)
        {
            var res = false;
            var dt  = date ?? _convertor.GetActualDateTime(DateTime.UtcNow);

            try
            {
                var plan = _storage.GetActualPlan(dt);
                if (plan != null)
                {
                    var transactions = _storage.GetTransactions(plan.StartDate, plan.EndDate);
                    foreach (var provider in _providers.GetCalendarProviders())
                    {
                        try
                        {
                            var ct = _convertor.GetActualDateTime(plan.StartDate);
                            while (ct.Date <= dt.Date)
                            {
                                var trs = transactions
                                          .Where(z => z.TransactionDate.Date == ct.Date && z.BaseCurrencyAmount < 0)
                                          .Sum(z => - 1 * z.BaseCurrencyAmount);
                                provider.SetAmountToDate(ct, trs);
                                ct = ct.AddDays(1);
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.Write(Severities.Error, $"Cannont update calendar throw {provider.GetType()} provider", ex);
                        }
                    }
                    res = true;
                }
            }
            catch (Exception e)
            {
                _logger.Write(Severities.Error, "Cannot update calendars", e);
            }
            return(res);
        }