public async Task <IActionResult> Start(string id) { if (string.IsNullOrWhiteSpace(id)) { throw new ArgumentNullException("id"); } string oauthToken = OAuthToken; if (string.IsNullOrWhiteSpace(oauthToken)) { _logger.LogWarning($"Analysis requested but no OAuth token was provided. File id was { id }"); throw new SecurityException("No OAuth token provided in request"); } int analysisId; try { _logger.LogInformation($"Adding Google File to database for starting anaylsis: { id }"); _logger.LogInformation($"Using connection string: { _repository.ConnectionString }"); analysisId = await _repository.StartAnalysisAsync(id); } catch (Exception err) { // TODO: create proper EventIds for logging _logger?.LogError(0, err, "Unable to save new analysis to database"); throw err; } // start analyzing immediately on new thread ThreadPool.QueueUserWorkItem(async s => { _logger.LogInformation("Starting analysis for Google file { id }"); // Can't use Dependency Injection because our calling thread will // dispose the objects var excelAnalyzer = new ExcelAnalyzer( AnalysisRepositoryFactory.CreateRepository(GetDbContextOptions())); await excelAnalyzer.AnalyzeAsync(analysisId, id, oauthToken); }); return(Ok()); }
public async Task AnalyzeExcelSheetAsync() { MappingConfig.RegisterMaps(); // open test excel file string excelFile = Path.Combine( Directory.GetCurrentDirectory(), "TestBook1.xlsx"); using (var stream = new FileStream(path: excelFile, mode: FileMode.Open)) { var context = new AnalysisContext(); var repo = new AnalysisRepository(context); var analyzer = new ExcelAnalyzer(repo); await analyzer.AnalyzeAsync(1, "1", stream); } }