/// <summary> /// Validates the specified benchmark settings. /// </summary> /// <param name="benchmarkSettings">The benchmark settings.</param> /// <exception cref="ConfigurationException">Configuration not valid</exception> private static void Validate(BenchmarkSettingsSection benchmarkSettings) { if (benchmarkSettings.CardinalityPowers == null || benchmarkSettings.CardinalityPowers.Length == 0) { throw new ConfigurationException($"'{nameof(benchmarkSettings.CardinalityPowers)}' be a non-empty array of integers"); } if (benchmarkSettings.CardinalityPowers.Any(v => v < BenchmarkServiceConfiguration.MinCardinalityPower || v > BenchmarkServiceConfiguration.MaxCardinalityPower)) { throw new ConfigurationException($"'{nameof(benchmarkSettings.CardinalityPowers)}' must not contain any values less than {BenchmarkServiceConfiguration.MinCardinalityPower} or greater than {BenchmarkServiceConfiguration.MaxCardinalityPower}"); } if (benchmarkSettings.ContainerTypes == null || benchmarkSettings.ContainerTypes.Length == 0) { throw new ConfigurationException($"'{nameof(benchmarkSettings.ContainerTypes)}' must be a non-empty array of '{nameof(BenchmarkContainerType)}'"); } if (benchmarkSettings.Operations == null || benchmarkSettings.Operations.Count == 0) { throw new ConfigurationException($"'{nameof(benchmarkSettings.Operations)}' must be a non-empty map of '{nameof(BenchmarkOperation)}:int'"); } if (benchmarkSettings.Operations.Values.Any(v => v < 0)) { throw new ConfigurationException($"'{nameof(benchmarkSettings.Operations)}' must not contain any values less than 0"); } }
/// <summary> /// Initializes a new instance of the <see cref="BenchmarkServiceConfiguration"/> class. /// </summary> /// <param name="configuration">The configuration.</param> private BenchmarkServiceConfiguration(IConfiguration configuration) { BenchmarkSettingsSection benchmarkSettings = configuration.GetSection(BenchmarkSettingsSection.SectionName) .Get <BenchmarkSettingsSection>(); BenchmarkServiceConfiguration.Validate(benchmarkSettings); this.Cardinalities = benchmarkSettings.CardinalityPowers.Select(BenchmarkServiceConfiguration.GetCardinalityFromPower); this.ContainerTypes = benchmarkSettings.ContainerTypes; this.Seed = benchmarkSettings.Seed; this.Operations = benchmarkSettings.Operations; }