Example #1
0
        protected override ValidationResult IsValid(object value,
                                                    ValidationContext validationContext)
        {
            ICurrencyCodesResolver currencyCodeResolver = (ICurrencyCodesResolver)validationContext.GetService(typeof(ICurrencyCodesResolver));

            if (!currencyCodeResolver.IsExists(value.ToString()))
            {
                return(new ValidationResult($"Currency code: {value} is unknown"));
            }

            return(ValidationResult.Success);
        }
        public CurrencyConverterService(CurrencyConverterConfiguration currencyConverterConfiguration, ICurrencyCodesResolver currencyCodesResolver, ILogger <CurrencyConverterService> logger)
        {
            if (currencyConverterConfiguration.UpdateCacheOnErrorIntervalSec > currencyConverterConfiguration.CacheExpirationTimeoutSec)
            {
                throw new Exception($"UpdateCacheIntervalOnError has to be considerably lesser than ExpirationTimeout. UpdateCacheOnErrorIntervalSec: [{currencyConverterConfiguration.UpdateCacheOnErrorIntervalSec}], CacheExpirationTimeoutSec: [{currencyConverterConfiguration.CacheExpirationTimeoutSec}]");
            }

            _apiAddress                 = currencyConverterConfiguration.ApiAddress;
            _comparableCurrencyCode     = currencyCodesResolver.Resolve(currencyConverterConfiguration.ComparableCurrencyCode);
            _expirationTimeout          = TimeSpan.FromSeconds(currencyConverterConfiguration.CacheExpirationTimeoutSec);
            _halfOfTheExpirationTimeout = TimeSpan.FromSeconds(currencyConverterConfiguration.CacheExpirationTimeoutSec / 2);
            _updateCacheIntervalOnError = TimeSpan.FromSeconds(currencyConverterConfiguration.UpdateCacheOnErrorIntervalSec);
            _currencyCodesResolver      = currencyCodesResolver;
            _readerWriterLockSlim       = new ReaderWriterLockSlim();
            _isWorking = true;
            RebuildCache().Wait();
            _rebuildCacheThread = new Thread(RebuildCacheHandler);
            _rebuildCacheThread.IsBackground = true;
            _rebuildCacheThread.Start();
            _logger = logger;
        }
Example #3
0
 public AccountController(IAccountService accountService, ICurrencyCodesResolver currencyCodesResolver)
 {
     _accountService        = accountService;
     _currencyCodesResolver = currencyCodesResolver;
 }
 public BalanceVM(Balance balance, ICurrencyCodesResolver currencyCodesResolver)
 {
     CurrencyCode = currencyCodesResolver.Resolve(balance.CurrencyCode);
     Balance      = balance.Money;
 }
 public AccountService(IDbManager dbManager, ICurrencyCodesResolver currencyCodesResolver, ICurrencyConverterService currencyConverterService)
 {
     _dbManager                = dbManager;
     _currencyCodesResolver    = currencyCodesResolver;
     _currencyConverterService = currencyConverterService;
 }