protected override async Task ExecuteAsync(CancellationToken stoppingToken) { Task <bool> loginTask; if (!string.IsNullOrEmpty(_config.LoginCookie)) { _logger.LogInformation("Logging in with login cookie"); loginTask = _httpClient.Authenticate(_config.LoginCookie); } else if (!string.IsNullOrEmpty(GetPassword()) && !string.IsNullOrEmpty(GetUserName())) { _logger.LogInformation("Logging in with username and password"); loginTask = _httpClient.Authenticate(GetUserName(), GetPassword()); } else { await HandleError("No authentication provided!"); return; } if (!await loginTask) { await HandleError("Authentication for fetching grades failed!"); return; } _logger.LogDebug("Execution started"); _logger.LogInformation($"Storing and saving results to {SaveFilePath}"); var parser = new GradingParser(_httpClient); var degrees = LoadFromFile().ToArray(); while (!stoppingToken.IsCancellationRequested) { try { var task = UpdateExamResults(parser, degrees); task.Wait(stoppingToken); degrees = task.Result.ToArray(); SaveToFile(degrees); } catch (Exception e) { await HandleError(e); } await Task.Delay(15 * 60 * 1000, stoppingToken); } }
private static bool Authenticate(LsfHttpClient httpClient) { Console.Write("Please enter your lsf username: "******"Please enter your lsf password: "******"Authentication failed!"); return(false); } return(true); }