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
2 changed files with 13 additions and 9 deletions

View File

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

View File

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