示例#1
0
        private void UpdateOptions(object source, ConfigurationPropertyWithOptionsModelDefinition model)
        {
            var optionSet = optionSetFactory.Build(model);
            var orignal   = model.GetPropertyValue(source);

            optionSet.TryGetValue(orignal, out var actualValue);
            model.SetPropertyValue(source, actualValue);
        }
        private object GetConfigPropertyValueFromInput(JObject source, ConfigurationPropertyWithOptionsModelDefinition propertyModel)
        {
            var    key       = source.GetValue(propertyModel.ConfigurationPropertyName.ToLowerCamelCase()).ToObject <string>();
            var    optionSet = optionSetFactory.Build(propertyModel);
            object option    = null;

            optionSet.TryGetValue(key, out option);
            return(option);
        }
        private object GetOptionConfigPropertyValueFromInput(JObject source, IOptionPropertyDefinition propertyModel, ConfigurationIdentity configIdentity, IEnumerable <ConfigurationSet> requiredConfigurationSets)
        {
            var        key       = source.GetValue(propertyModel.ConfigurationPropertyName.ToLowerCamelCase()).ToObject <string>();
            IOptionSet optionSet = optionSetFactory.Build(propertyModel, configIdentity, requiredConfigurationSets);
            object     option    = null;

            optionSet.TryGetValue(key, out option);
            return(option);
        }
        private ValidationResult ValidateProperty(object target, ConfigurationPropertyWithOptionsModelDefinition propertyModel)
        {
            var errors        = new List <string>();
            var propertyValue = propertyModel.GetPropertyValue(target);
            var options       = optionSetFactory.Build(propertyModel);

            if (!options.OptionKeyInSet(propertyValue))
            {
                errors.Add(string.Format(ValidationStrings.OptionNotFound, propertyModel.ConfigurationPropertyName));
            }
            return(new ValidationResult(errors));
        }
        private async Task BuildOptions(ConfigurationSet result, ConfigurationSetModel setDefinition, Type setType, IEnumerable <ConfigurationSet> configurationSets, ConfigurationIdentity identity)
        {
            var configurationDependencies = configurationSets.Concat(new[] { result }).ToArray();

            foreach (var option in GetOptionsInOrder(setDefinition))
            {
                IOptionSet optionSet;
                if (option is ReadOnlyConfigurationOptionModel readonlyModel)
                {
                    optionSet = optionSetFactory.Build(readonlyModel, identity);
                }
                else
                {
                    optionSet = await BuildOptionSetCollection(option, configurationDependencies, identity);
                }

                option.SetConfigurationOnConfigurationSet(result, optionSet);
            }
        }
        private ValidationResult ValidateProperty(object target, IOptionPropertyDefinition propertyModel, ConfigurationIdentity configIdentity, IEnumerable <ConfigurationSet> configurationSets)
        {
            var errors        = new List <string>();
            var propertyValue = propertyModel.GetPropertyValue(target);
            var options       = optionSetFactory.Build(propertyModel, configIdentity, configurationSets);

            if (propertyModel is ConfigurationPropertyWithOptionValueModelDefinition valueModel)
            {
                if (!options.ContainsKey(propertyValue))
                {
                    errors.Add(ValidationStrings.OptionNotFound(propertyModel.ConfigurationPropertyName));
                }
            }
            else if (!options.OptionKeyInSet(propertyValue))
            {
                errors.Add(ValidationStrings.OptionNotFound(propertyModel.ConfigurationPropertyName));
            }
            return(new ValidationResult(errors));
        }
示例#7
0
        private ConfigurationPropertyPayload BuildProperty(IOptionPropertyDefinition value, ConfigurationIdentity configIdentity, IEnumerable <ConfigurationSet> requiredConfigurationSets)
        {
            var optionSet = optionSetFactory.Build(value, configIdentity, requiredConfigurationSets);

            return(new ConfigurationPropertyPayload
            {
                PropertyName = value.ConfigurationPropertyName.ToLowerCamelCase(),
                PropertyDisplayName = value.PropertyDisplayName,
                PropertyType = propertyTypeProvider.GetPropertyType(value),
                PropertyDescription = value.PropertyDescription,
                Options = optionSet.OptionSelections.ToDictionary(k => k.Key, v => v.DisplayValue)
            });
        }
        private ConfigurationPropertyPayload BuildProperty(ConfigurationPropertyWithOptionsModelDefinition value)
        {
            var optionSet = optionSetFactory.Build(value);

            return(new ConfigurationPropertyPayload
            {
                PropertyName = value.ConfigurationPropertyName.ToLowerCamelCase(),
                PropertyDisplayName = value.PropertyDisplayName,
                PropertyType = propertyTypeProvider.GetPropertyType(value),
                PropertyDescription = value.PropertyDescription,
                Options = optionSet.OptionSelections.ToDictionary(k => k.Key, v => v.DisplayValue)
            });
        }