private bool IsCommandCorrect(ICommand command, string[] args) { string verb = args[0]; IEnumerable <Attribute> attributes = command.GetType().GetCustomAttributes(true).Where(x => x is Attribute).Select(x => x as Attribute); CommandAttribute commandInfo = attributes.FirstOrDefault(x => x is CommandAttribute) as CommandAttribute; IEnumerable <ArgumentAttribute> argumentAttributes = attributes.Where(x => x is ArgumentAttribute).Select(x => x as ArgumentAttribute); if (commandInfo.CommandName == verb) { try { if (commandInfo.IsSingleArgument) { args[0] = $"--{verb}"; } command.SetArguments(DetermineArguments(argumentAttributes, args)); return(true); } catch (Exception e) { if (e is ArgumentException) { _outputHandler.Output(e.Message); return(true); } return(false); } } return(false); }
public void Go() { while (numberProvider.Next()) { outputHandler.Output(numberHandler.GetMessage(numberProvider.TheNumber)); } }
public void Run() { _outputHandler.Output(_configDisplayGenerator.BuildConfigDisplayString()); while (true) { try { _outputHandler.Output(Environment.NewLine + "Please enter city name"); var city = _inputHandler.GetCityString(); var forecast = _forecastProvider.GetForecastForCity(city).Result; _outputHandler.Output(forecast.ToString()); } catch (Exception e) { _outputHandler.Output(e.ToString()); } } }
private async Task <PKCETokenResponse> GetCallbackTokens(string code) { var initialResponse = await _oAuthClient.RequestToken(new PKCETokenRequest(_config.ClientId, code, new Uri(_redirectUri), _verifier)); _outputHandler.Output("Exchanged code for tokens."); return(initialResponse); }
private Configuration Initialise() { var directoryInfo = new DirectoryInfo(_directoryPath); if (!directoryInfo.Exists) { directoryInfo.Create(); directoryInfo.Attributes = FileAttributes.Directory; } var configFile = new FileInfo(_filePath); if (!configFile.Exists) { _outputHandler.Output("No config file was found. Creating..."); var fileStream = configFile.Create(); fileStream.Close(); // TODO: Use future input-handler to take a client id from the user var configData = new Configuration() { ClientId = "ClientId123", Tokens = new PKCETokenResponse() { AccessToken = "" } }; string jsonData = JsonSerializer.Serialize <Configuration>(configData); File.WriteAllLines(_filePath, new string[] { jsonData }); // TODO: Remove this when the input logic is available _outputHandler.Output("The file has been created. Please replace the current client-id with one of your own."); _outputHandler.Output("You can get a client id from the spotify developer site."); } return(GetConfiguration()); }
/// <summary> /// Read, execute, evaluate and output results of the execution of all test cases. /// Calls inputHandler, TestExecutor, ResultValidator and OutputHandler components. /// </summary> /// <param name="filename">The file to read test cases from</param> public static void RunTest(String filename, int state = 0, Boolean parallelExecution = true) { ComponentNullCheck(); DatabaseState = state; // Read tests from input Log("Reading tests from input"); Tuple <List <Tuple <int, string> >, List <SQLTestCase> > input = inputHandler.ReadTests(filename); // Perhaps use out parameter to count read tests testList = input.Item2; comments = input.Item1; Log("Read " + testList.Count + " tests"); // Fetch internal parameters parameterHandler.LoadParameters(filename, testList); // Run tests in parallel Log("Executing tests"); if (parallelExecution) { testExecutor.ExecutePar(testList); } else { testExecutor.ExecuteSeq(testList); } Log("Test execution finished"); // Get failed/generated tests Log("Validating tests"); Tuple <List <SQLTestCase>, List <SQLTestCase> > validationResults = resultValidator.EvaluateTests(testList); failedTests = validationResults.Item1; generatedTests = validationResults.Item2; Log("Test validation finished"); // Store iternal parameters parameterHandler.StoreParameters(); // Output Log("Writing output"); outputHandler.Output(testList, failedTests, generatedTests, comments); Log("Test run finished"); }