public AnalysisController(IHostingEnvironment env,
                           /*IAnalysisRepository repository,*/
                           /*ExcelAnalyzer excelAnalyzer,*/
                           ILogger <AnalysisController> logger)
 {
     _env    = env;
     _logger = logger;
     //_repository = repository;
     // skipping the dependency injection because it seems to be broken in the Google Cloud
     _logger?.LogInformation("Starting AnalysisController");
     _repository = AnalysisRepositoryFactory.CreateRepository(GetDbContextOptions());
     //_excelAnalyzer = excelAnalyzer;
     _excelAnalyzer = new ExcelAnalyzer(_repository);
 }
        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());
        }