Exemple #1
0
        public void DataInitialization()
        {
            if (!_dataInitialized)
            {
                lock (_dataInitializationLock)
                {
                    if (!_dataInitialized)
                    {
                        var result           = true;
                        var fiatCurrencies   = GetSupportedFiatCurrencies();
                        var cryptoCurrencies = new List <CryptoCurrency>();

                        // Handle Fiat currencies
                        var fiatPopulateSuccess = _fiatRepository.InsertOrUpdateFiatCurrencies(fiatCurrencies);
                        result = result && fiatPopulateSuccess;

                        // Handle crypto currencies
                        if (_cryptoRepository.CountAll() < 1)
                        {
                            if (!cryptoCurrencies.Any())
                            {
                                cryptoCurrencies.AddRange(_httpAPI.GetAllCryptoCurrencies());
                            }

                            var cryptoPopulateResult = _cryptoRepository.PopulateCryptoCurrencies(cryptoCurrencies);
                            result = result && cryptoPopulateResult;
                        }

                        // Handle exchange markets
                        if (_exchangeRepository.CountAll() < 1)
                        {
                            if (!cryptoCurrencies.Any())
                            {
                                cryptoCurrencies.AddRange(_httpAPI.GetAllCryptoCurrencies());
                            }

                            List <Currency> mergedCurrencyList = new List <Currency>(cryptoCurrencies);
                            mergedCurrencyList.AddRange(fiatCurrencies);

                            var exchanges = _httpAPI.GetAllExchanges(mergedCurrencyList);
                            var exchangePopulateResult = _exchangeRepository.PopulateExchangeMarkets(exchanges);

                            result = result && exchangePopulateResult;
                        }

                        // Add demo user
                        var demoUser = GetDemoUser();
                        if (!_userRepository.Exists(x => x.Email == demoUser.Email))
                        {
                            var key = _userRepository.Create(demoUser);
                            result = result && (demoUser.Email == (string)key);
                        }

                        _dataInitialized = result;
                    }
                }
            }
        }