public static ApiHttpClient GetClient(Configuration config) { var client = new ApiHttpClient(new Uri(config.Api.Endpoint), () => new ApiTokenParameter { ClientInfo = "eRecruiter.ApplicantImport", Key = config.Api.Key, MandatorId = config.Api.MandatorId }, () => TokenCache); return client; }
private bool IsEndpointValid(Configuration configuration) { // endpoint needs to be a valid URL try { // ReSharper disable once ObjectCreationAsStatement new Uri(configuration.Api.Endpoint); } catch { Program.WriteError(string.Format("'{0}' is not a valid endpoint URI.", configuration.Api.Endpoint)); return false; } // endpoint must respond to ping var apiClient = ApiClientFactory.GetClient(configuration); try { new PingRequest().LoadResult(apiClient); } catch (Exception ex) { Program.WriteError("API endpoint not found: " + ex.Message); return false; } // endpoint must return valid mandator response try { new MandatorRequest().LoadResult(apiClient); } catch (Exception ex) { Program.WriteError("Unable to access API: " + ex.Message); return false; } return true; }
public Configuration ReadAndVerify(out bool hasErrors, out bool hasWarnings) { hasWarnings = false; Configuration configuration; // parse the JSON and check if we get a filled configuration back try { configuration = JsonConvert.DeserializeObject<Configuration>( File.ReadAllText(_commandLineArguments.ConfigurationFile)); if (configuration == null || configuration.Api == null || configuration.Columns == null || configuration.Columns.Any(x => x == null)) { throw new ApplicationException("Configuration invalid or missing."); } } catch (Exception ex) { Program.WriteError("Unable to deserialize JSON: " + ex.Message); configuration = new Configuration(); hasErrors = true; return configuration; } hasErrors = !IsEndpointValid(configuration); if (hasErrors) { return configuration; } var apiClient = ApiClientFactory.GetClient(configuration); hasWarnings = !IsEntireConfigurationValid(configuration) || !IsEveryColumnValid(configuration, apiClient); return configuration; }
// run once for every type of column private bool IsEntireConfigurationValid(Configuration configuration) { var result = true; // ReSharper disable once LoopCanBeConvertedToQuery foreach (ColumnType c in Enum.GetValues(typeof (ColumnType))) { var column = ColumnFactory.GetColumn(new Configuration.Column {Header = "Some_Header", Type = c}); result = column.IsEntireConfigurationValid(configuration) && result; } return result; }
// run once for every configured column private bool IsEveryColumnValid(Configuration configuration, ApiHttpClient apiClient) { var result = true; // ReSharper disable once LoopCanBeConvertedToQuery foreach (var c in configuration.Columns) { var column = ColumnFactory.GetColumn(c); result = column.IsColumnConfigurationValid(apiClient) && result; } return result; }
public CsvStubService(Configuration configuration) { _configuration = configuration; }
public ImportService(Configuration configuration, Csv csv) { _csv = csv; _configuration = configuration; }
public CsvService([NotNull] CommandLineArguments commandLineArguments, [NotNull] Configuration configuration) { _commandLineArguments = commandLineArguments; _configuration = configuration; _apiClient = ApiClientFactory.GetClient(configuration); }