2017-12-08 15:04:47 +09:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2018-05-03 03:32:42 +09:00
|
|
|
|
using BTCPayServer.Rating;
|
2017-12-08 15:04:47 +09:00
|
|
|
|
|
|
|
|
|
namespace BTCPayServer.Services.Rates
|
|
|
|
|
{
|
|
|
|
|
public class FallbackRateProvider : IRateProvider
|
|
|
|
|
{
|
|
|
|
|
IRateProvider[] _Providers;
|
2018-05-03 03:32:42 +09:00
|
|
|
|
public bool Used { get; set; }
|
2017-12-08 15:04:47 +09:00
|
|
|
|
public FallbackRateProvider(IRateProvider[] providers)
|
|
|
|
|
{
|
|
|
|
|
if (providers == null)
|
|
|
|
|
throw new ArgumentNullException(nameof(providers));
|
|
|
|
|
_Providers = providers;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-03 03:32:42 +09:00
|
|
|
|
public async Task<ExchangeRates> GetRatesAsync()
|
2017-12-08 15:04:47 +09:00
|
|
|
|
{
|
2018-05-03 03:32:42 +09:00
|
|
|
|
Used = true;
|
2017-12-08 15:04:47 +09:00
|
|
|
|
foreach (var p in _Providers)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return await p.GetRatesAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
2018-05-03 03:32:42 +09:00
|
|
|
|
catch(Exception ex) { Exceptions.Add(ex); }
|
2017-12-08 15:04:47 +09:00
|
|
|
|
}
|
2018-05-03 03:32:42 +09:00
|
|
|
|
return new ExchangeRates();
|
2017-12-08 15:04:47 +09:00
|
|
|
|
}
|
2018-05-03 03:32:42 +09:00
|
|
|
|
|
|
|
|
|
public List<Exception> Exceptions { get; set; } = new List<Exception>();
|
2017-12-08 15:04:47 +09:00
|
|
|
|
}
|
|
|
|
|
}
|