Do not crash if can't load rate cache

This commit is contained in:
nicolas.dorier 2020-02-16 22:07:35 +09:00
parent 143c909812
commit c03dc48fe9
No known key found for this signature in database
GPG Key ID: 6618763EF09186FE
2 changed files with 13 additions and 9 deletions

View File

@ -115,20 +115,24 @@ namespace BTCPayServer.HostedServices
private async Task TryLoadRateCache()
{
var cache = await _SettingsRepository.GetSettingAsync<ExchangeRatesCache>();
if (cache != null)
try
{
_LastCacheDate = cache.Created;
var stateByExchange = cache.States.ToDictionary(o => o.ExchangeName);
foreach (var provider in _RateProviderFactory.Providers)
var cache = await _SettingsRepository.GetSettingAsync<ExchangeRatesCache>();
if (cache != null)
{
if (stateByExchange.TryGetValue(provider.Key, out var state) &&
provider.Value is BackgroundFetcherRateProvider fetcher)
_LastCacheDate = cache.Created;
var stateByExchange = cache.States.ToDictionary(o => o.ExchangeName);
foreach (var provider in _RateProviderFactory.Providers)
{
fetcher.LoadState(state);
if (stateByExchange.TryGetValue(provider.Key, out var state) &&
provider.Value is BackgroundFetcherRateProvider fetcher)
{
fetcher.LoadState(state);
}
}
}
}
catch { }
}
DateTimeOffset? _LastCacheDate;

View File

@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>1.0.3.157</Version>
<Version>1.0.3.158</Version>
</PropertyGroup>
</Project>