public ImmutableList(IEnumerable <T> values, IValueValidator <T> optionalValueValidator)
        {
            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            Node node = null;

            foreach (var value in values)
            {
                if (optionalValueValidator != null)
                {
                    optionalValueValidator.EnsureValid(value);
                }
                if (node == null)
                {
                    node = new Node(value, null);
                }
                else
                {
                    node = new Node(value, node);
                }
            }
            _tail = node;
            _optionalValueValidator = optionalValueValidator;
            _allValues = null;
        }
Exemple #2
0
 private static IValueValidator <T> GetValidator(IValueValidator <T> optionalValueValidator)
 {
     if (optionalValueValidator == null)
     {
         return(_defaultValidator);
     }
     return(new Validator(optionalValueValidator));
 }
Exemple #3
0
 /// <summary>
 /// Constructs a validator for checking that a value is less than, or optionally equal to, a <paramref name="margin"/>.
 /// </summary>
 /// <param name="margin">The margin that a value must be less than or optionally equal to.</param>
 /// <param name="orEqualTo">If true, the validator checks that a value is less than or equal to <paramref name="margin"/>. If false, it checks that a value is only less than <paramref name="margin"/>.</param>
 /// <param name="validator">A validator of the same type that can be combined with this one.</param>
 /// <exception cref="ArgumentNullException">Thrown if margin is null.</exception>
 public LesserValidator(T margin, bool orEqualTo = false, IValueValidator <IComparable <T> > validator = null)
     : base(validator)
 {
     if (margin == null)
     {
         throw new ArgumentNullException(nameof(margin));
     }
     this.margin    = margin;
     this.orEqualTo = orEqualTo;
 }
Exemple #4
0
        /// <summary>
        /// Create a totally customized Config instance.
        /// Generally you will not need this constructor.
        /// </summary>
        /// <param name="cache">The <see cref="IValueCache"/> instance to be used by this Config instance.</param>
        /// <param name="source">The <see cref="IValueSource"/> instance to be used by this Config instance.</param>
        /// <param name="transformer">The <see cref="IValueTransformer"/> instance to be used by this Config instance.</param>
        /// <param name="validator">The <see cref="IValueValidator"/> instance to be used by this Config instance.</param>
        /// <param name="coercer">The <see cref="IValueCoercer"/> instance to be used by this Config instance.</param>
        protected Config(IValueCache cache, IValueSource source, IValueTransformer transformer, IValueValidator validator, IValueCoercer coercer)
        {
            Cache       = cache;
            Source      = source;
            Transformer = transformer;
            Validator   = validator;
            Coercer     = coercer;

            // Pre-cache all the properties on this instance
            _properties = GetType()
                          .GetMembers(BindingFlags.Instance | BindingFlags.Public)
                          .OfType <PropertyInfo>()
                          .Where(p => p.CanRead)
                          .ToDictionary(p => p.Name);
        }
        public string RequestValueAndSaving(string name, IValueValidator validator, IValueProvider valueProvider)
        {
            var result = validator.Validate(valueProvider?.Get(name));

            while (!result.IsValid)
            {
                Console.WriteLine(Resources.PleaseEnterValue, name);
                result = validator.Validate(Console.ReadLine());
                if (!result.IsValid)
                {
                    Console.WriteLine(result.Value);
                    continue;
                }

                RequestValueSaving(name, result.Value, valueProvider);
            }

            return(result.Value);
        }
        public ImmutableList(IEnumerable <T> values, IValueValidator <T> optionalValueValidator)
        {
            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            Node node = null;

            foreach (var value in values)
            {
                if (optionalValueValidator != null)
                {
                    optionalValueValidator.EnsureValid(value);
                }
                node = new Node {
                    Value = value, Previous = node, Count = (node?.Count ?? 0) + 1
                };
            }
            _tail = node;
            _optionalValueValidator = optionalValueValidator;
            _allValues = null;
        }
 public CheckboxInputType(IValueValidator validator)
     : base(validator)
 {
     
 }
Exemple #8
0
 public ComboboxInputType(ILocalizableComboboxItemSource itemSource, IValueValidator validator)
     : base(validator)
 {
     ItemSource = itemSource;
 }
Exemple #9
0
 public SingleLineStringInputType(IValueValidator validator)
     : base(validator)
 {
 }
Exemple #10
0
 /// <summary>
 /// Constructs a validator for checking a value's length.
 /// </summary>
 /// <param name="length">The desired value's length.</param>
 /// <param name="validator">A string validator that can be combined with this one.</param>
 public LengthValidator(uint length, IValueValidator <string> validator = null)
     : base(validator)
 {
     this.length = length;
 }
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="validator">验证器</param>
 public SingleLineStringInputType(IValueValidator validator)
     : base(validator)
 {
 }
Exemple #12
0
 private NonNullImmutableList(Node tail, IValueValidator <T> optionalValueValidator)
     : base(tail, GetValidator(optionalValueValidator))
 {
     _optionalValueValidator = optionalValueValidator;
 }
Exemple #13
0
 public ConfigWrapper(IValueCache cache, IValueSource source, IValueTransformer transformer, IValueValidator validator, IValueCoercer coercer)
     : base(cache, source, transformer, validator, coercer)
 {
 }
Exemple #14
0
 /// <summary>
 /// Constructs a validator for checking a value's pattern.
 /// </summary>
 /// <param name="regex">The regular expression to use.</param>
 /// <param name="validator">A string validator that can be combined with this one.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="regex"/> is null.</exception>
 public RegexValidator(Regex regex, IValueValidator <string> validator = null)
     : base(validator)
 {
     this.regex = regex ?? throw new ArgumentNullException(nameof(regex));
 }
 /// <summary>
 /// This will throw an exception if any of the values are null, valueValidator is optional (may be null)
 /// </summary>
 public static NonNullImmutableList <T> ToNonNullImmutableList <T>(this IEnumerable <T> data, IValueValidator <T> valueValidator) where T : class
 {
     return(new NonNullImmutableList <T>(data, valueValidator));
 }
 /// <summary>
 /// valueValidator is optional (may be null)
 /// </summary>
 public static ImmutableList <T> ToImmutableList <T>(this IEnumerable <T> data, IValueValidator <T> valueValidator)
 {
     return(new ImmutableList <T>(data, valueValidator));
 }
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="itemSource">项目源</param>
 /// <param name="validator">验证器</param>
 public ComboboxInputType(ILocalizableComboboxItemSource itemSource, IValueValidator validator)
     : base(validator)
 {
     ItemSource = itemSource;
 }
        public void CanParseManifest_PropertyEditors()
        {
            const string json = @"{'propertyEditors': [
    {
        alias: 'Test.Test1',
        name: 'Test 1',
        editor: {
            view: '~/App_Plugins/MyPackage/PropertyEditors/MyEditor.html',
            valueType: 'int',
            hideLabel: true,
            validation: {
                'required': true,
                'Regex': '\\d*'
            }
        },
        prevalues: {
                fields: [
                    {
                        label: 'Some config 1',
                        key: 'key1',
                        view: '~/App_Plugins/MyPackage/PropertyEditors/Views/pre-val1.html',
                        validation: {
                            required: true
                        }
                    },
                    {
                        label: 'Some config 2',
                        key: 'key2',
                        view: '~/App_Plugins/MyPackage/PropertyEditors/Views/pre-val2.html'
                    }
                ]
            }
    },
    {
        alias: 'Test.Test2',
        name: 'Test 2',
        isParameterEditor: true,
        defaultConfig: { key1: 'some default val' },
        editor: {
            view: '~/App_Plugins/MyPackage/PropertyEditors/MyEditor.html',
            valueType: 'int',
            validation: {
                required : true,
                regex : '\\d*'
            }
        }
    }
]}";

            PackageManifest manifest = _parser.ParseManifest(json);

            Assert.AreEqual(2, manifest.PropertyEditors.Length);

            IDataEditor editor = manifest.PropertyEditors[1];

            Assert.IsTrue((editor.Type & EditorType.MacroParameter) > 0);
            Assert.IsNotEmpty(editor.DefaultConfiguration);
            Assert.AreEqual("some default val", editor.DefaultConfiguration["key1"]);

            editor = manifest.PropertyEditors[0];
            Assert.AreEqual("Test.Test1", editor.Alias);
            Assert.AreEqual("Test 1", editor.Name);
            Assert.IsFalse((editor.Type & EditorType.MacroParameter) > 0);

            IDataValueEditor valueEditor = editor.GetValueEditor();

            Assert.AreEqual(_ioHelper.ResolveUrl("/App_Plugins/MyPackage/PropertyEditors/MyEditor.html"), valueEditor.View);
            Assert.AreEqual("int", valueEditor.ValueType);
            Assert.IsTrue(valueEditor.HideLabel);

            // these two don't make much sense here
            //// valueEditor.RegexValidator;
            //// valueEditor.RequiredValidator;

            List <IValueValidator> validators = valueEditor.Validators;

            Assert.AreEqual(2, validators.Count);
            IValueValidator validator = validators[0];
            var             v1        = validator as RequiredValidator;

            Assert.IsNotNull(v1);
            Assert.AreEqual("Required", v1.ValidationName);
            validator = validators[1];
            var v2 = validator as RegexValidator;

            Assert.IsNotNull(v2);
            Assert.AreEqual("Regex", v2.ValidationName);
            Assert.AreEqual("\\d*", v2.Configuration);

            // this is not part of the manifest
            IDictionary <string, object> preValues = editor.GetConfigurationEditor().DefaultConfiguration;

            Assert.IsEmpty(preValues);

            IConfigurationEditor preValueEditor = editor.GetConfigurationEditor();

            Assert.IsNotNull(preValueEditor);
            Assert.IsNotNull(preValueEditor.Fields);
            Assert.AreEqual(2, preValueEditor.Fields.Count);

            ConfigurationField f = preValueEditor.Fields[0];

            Assert.AreEqual("key1", f.Key);
            Assert.AreEqual("Some config 1", f.Name);
            Assert.AreEqual(_ioHelper.ResolveUrl("/App_Plugins/MyPackage/PropertyEditors/Views/pre-val1.html"), f.View);
            List <IValueValidator> fvalidators = f.Validators;

            Assert.IsNotNull(fvalidators);
            Assert.AreEqual(1, fvalidators.Count);
            var fv = fvalidators[0] as RequiredValidator;

            Assert.IsNotNull(fv);
            Assert.AreEqual("Required", fv.ValidationName);

            f = preValueEditor.Fields[1];
            Assert.AreEqual("key2", f.Key);
            Assert.AreEqual("Some config 2", f.Name);
            Assert.AreEqual(_ioHelper.ResolveUrl("/App_Plugins/MyPackage/PropertyEditors/Views/pre-val2.html"), f.View);
            fvalidators = f.Validators;
            Assert.IsNotNull(fvalidators);
            Assert.AreEqual(0, fvalidators.Count);
        }
Exemple #19
0
 public NonNullImmutableList(IValueValidator <T> optionalValueValidator)
     : base((Node)null, GetValidator(optionalValueValidator))
 {
     _optionalValueValidator = optionalValueValidator;
 }
 public FreeTextStringValueType(IValueValidator validator)
     : base(validator)
 {
 }
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="validator">值验证器</param>
 protected InputTypeBase(IValueValidator validator)
 {
     Attributes = new Dictionary<string, object>();
     Validator = validator;
 }
Exemple #22
0
 public NonNullImmutableList(IEnumerable <T> values, IValueValidator <T> optionalValueValidator)
     : base(values, GetValidator(optionalValueValidator))
 {
     _optionalValueValidator = optionalValueValidator;
 }
Exemple #23
0
        public static void IsValid <T>(string paramName, T paramValue, IValueValidator <T> validator)
        {
            Argument.IsNotNull("validator", validator);

            IsValid(paramName, paramValue, validator.IsValid(paramValue));
        }
Exemple #24
0
 protected InputTypeBase(IValueValidator validator)
 {
     Attributes = new Dictionary <string, object>();
     Validator  = validator;
 }
Exemple #25
0
 public CheckboxInputType(IValueValidator validator)
     : base(validator)
 {
 }
Exemple #26
0
 public void IsValidInvokation <T>(T value, IValueValidator <T> validator)
 {
     Argument.IsValid(() => value, validator);
 }
Exemple #27
0
        public static void IsValid <T>([InvokerParameterName] string paramName, T paramValue, IValueValidator <T> validator)
        {
            IsNotNull(nameof(validator), validator);

            IsValid(paramName, paramValue, validator.IsValid(paramValue));
        }
Exemple #28
0
 /// <summary>
 /// Constructs a nested validator decorator.
 /// </summary>
 /// <param name="validator">The nested validator. Supply null to terminate the validator nesting.</param>
 public ValidatorDecorator(IValueValidator <T> validator) => _validator = validator;
Exemple #29
0
        public static void IsValid <T>(Expression <Func <T> > expression, IValueValidator <T> validator)
        {
            var parameterInfo = expression.GetParameterInfo();

            IsValid(parameterInfo.Name, parameterInfo.Value, validator);
        }
Exemple #30
0
 public static bool IsValid <TValue>(this IValueValidator <TValue> validator, TValue value)
 => validator.IsValid(Option.None <object>(), value);
Exemple #31
0
 public ToggleStringValueType(IValueValidator validator)
     : base(validator)
 {
 }
Exemple #32
0
 public ValuesController(IValueValidator valueValidator)
 {
     _valueValidator = valueValidator;
 }
Exemple #33
0
 public SelectionStringValueType(IValueValidator validator)
     : base(validator)
 {
 }
Exemple #34
0
 /// <summary>
 /// Constructs a validator for checking a value's ending.
 /// </summary>
 /// <param name="end">The desired way a value must end with.</param>
 /// <param name="caseSensitive">Specifies if <paramref name="end"/> is checked in a case sensitive manner.</param>
 /// <param name="validator">A string validator that can be combined with this one.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="end"/> is null.</exception>
 public EndsWithValidator(string end, bool caseSensitive = true, IValueValidator <string> validator = null)
     : base(validator)
 {
     this.end           = end ?? throw new ArgumentNullException(nameof(end));
     this.caseSensitive = caseSensitive;
 }