Beispiel #1
0
        public Result <string, string> GetName(
            [NotNull] IDictionary <string, object> settings,
            [NotNull] ConfigurationGeneratorPreferences configGenerationPreferences)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            if (configGenerationPreferences == null)
            {
                throw new ArgumentNullException(nameof(configGenerationPreferences));
            }

            var configurationNameToken = configGenerationPreferences.ConfigurationNameSetting;

            object value;

            if (settings.TryGetValue(configurationNameToken, out value) &&
                value != null)
            {
                string configurationName = value.ToString();
                _tokenUsageTracker.OnTokenUsed(configurationName, configurationNameToken);
                return(Result <string, string> .CreateSuccessResult(configurationName));
            }

            return(Result <string, string> .CreateFailureResult($"Failed to get configuration name, as specified setting was not found: {configurationNameToken}"));
        }
Beispiel #2
0
        public IResult <IReadOnlyCollection <IConfiguration>, Error> CreateConfigurations(
            [NotNull] ConfigurationGeneratorPreferences configGenerationPreferences,
            [NotNull] IEnumerable <IDictionary <string, object> > loadedSettings)
        {
            var configurations = new List <IConfiguration>();

            foreach (var settings in loadedSettings)
            {
                var result = _configurationNameSelector.GetName(settings, configGenerationPreferences);
                if (result.Success)
                {
                    configurations.Add(new Configuration(result.Value, settings));
                }
                else
                {
                    return(Result <IReadOnlyCollection <IConfiguration>, Error> .CreateFailureResult(
                               new ConfigurationGeneratorError(
                                   ConfigurationGeneratorErrorCodes.UnknownConfigurationNameSetting,
                                   $"Failed to get name for one or more configurations: {result.Error}")));
                }
            }

            return(Result <IReadOnlyCollection <IConfiguration>, Error> .CreateSuccessResult(configurations));
        }