public async Task <PlaygroundProcessor> LoadPlaygroundAsync(LoadPlaygroundRequest request) { var key = $"LoadPlaygroundAsync-{request.Ticker}-{request.StrategyId}"; if (request.RefreshCache) { _cache.Delete(key); } var processor = await _cache.Get(key, async() => await LoadPlayground(request)); if (processor.QuotesCount < 300) { var historicalData = await LoadHistoryAsync(request.Ticker); if (historicalData.Count > 300) { using (var scope = _container.BeginLifetimeScope()) { var companyService = scope.Resolve <ICompanyService>(); companyService.UpdateQuotes(new UpdateQuotesRequest(request.Ticker, historicalData)); } request.RefreshCache = true; return(await LoadPlaygroundAsync(request)); } } return(processor); }
private async Task <PlaygroundProcessor> LoadPlayground(LoadPlaygroundRequest request) { using (var scope = _container.BeginLifetimeScope()) { var configurationLoader = scope.Resolve <PlaygroundConfigurationLoader>(); var configuration = await configurationLoader.Load(request.Ticker, request.StrategyId); return(new PlaygroundProcessor(configuration)); } }