Beispiel #1
0
        private void InternalRun()
        {
            DateTime latestUpdated;
            var      currencyList = GetCurrencyListFromWeb(out latestUpdated);

            Log.Info(string.Format("Currency list contains {0} items", currencyList.Count()));
            if (!DatabaseHasStoredCurrencyList)
            {
                Log.Info("Currency list store to DB started...");
                StoreToDatabaseCurrencyList(currencyList);
                Log.Info("Currency list store to DB successfully completed!");
            }

            var now = DateTime.Now.Date;

            var history = RetriveCurrencyHistoriesFromWeb(currencyList, now.AddYears(-1), now);

            CurrencyRateRepository.EnsureTransaction(() =>
            {
                Log.Info(string.Format("Currency list with history data {0} items", history.Count()));
                if (history != null)
                {
                    Log.Info("Store currency historical price started");
                    StoreToDatabaseCurrencyHistory(history);
                    Log.Info("Store currency historical price successfully completed!");
                }

                var latestData = _LastCurrencyRates.Select(pair =>
                {
                    var currencyName = pair.Key;
                    var price        = pair.Value;
                    var data         = new CurrencyHistoryData(currencyName);

                    data.History.Add(new CurrencyHistoryItemData(latestUpdated, price));

                    return(data);
                }
                                                           );

                Log.Info("Store latest currency rates started");
                StoreToDatabaseCurrencyHistory(latestData);
                Log.Info("Store latest currency rates successfully completed!");
            });
        }
Beispiel #2
0
 private void StoreToDatabaseCurrencyList(IEnumerable <string> data)
 {
     CurrencyRateRepository.EnsureTransaction(() => data.ToList().ForEach(currencyName => CurrencyRateRepository.Save(new CurrencyData(currencyName))));
 }