Esempio n. 1
0
        public IValueCheck CreateCheck(
            CheckDefinition checkDefinition,
            FieldDefinition fieldDefinition,
            Func <FormData> formData = null,
            INZazuTableDataSerializer tableSerializer = null,
            int rowIdx = -1)
        {
            if (checkDefinition == null)
            {
                throw new ArgumentNullException(nameof(checkDefinition));
            }
            if (string.IsNullOrWhiteSpace(checkDefinition.Type))
            {
                throw new ArgumentException("check type not specified");
            }

            // lets check if the given validation type is available
            if (!_registrations.ContainsKey(checkDefinition.Type.ToLower()))
            {
                throw new NotSupportedException($"The specified check '{checkDefinition.Type}' is not supported");
            }

            var concrete = _registrations[checkDefinition.Type.ToLower()];

            Trace.WriteLine($"Found check for '{checkDefinition.Type.ToLower()}' as ({concrete.FullName})");

            // lets use reflection to create an instance
            var result = (IValueCheck)
                         Activator.CreateInstance(concrete, checkDefinition.Settings, formData, tableSerializer, rowIdx,
                                                  fieldDefinition);

            return(result);
        }
Esempio n. 2
0
 public RequiredCheck(
     IDictionary <string, string> settings,
     Func <FormData> formData,
     INZazuTableDataSerializer tableSerializer,
     int rowIdx,
     FieldDefinition field)
 {
     _fieldMissing =
         new ValueCheckResult(new ArgumentException($"{field.Prompt ?? field.Key}: The field is required"));
 }
Esempio n. 3
0
        // ReSharper disable UnusedParameter.Local
        public StringRegExCheck(
            IDictionary <string, string> settings, Func <FormData> formData,
            INZazuTableDataSerializer tableSerializer, int rowIdx,
            FieldDefinition fieldDefinition)
        {
            Settings = settings.ToDictionary(x => x.Key, x => (object)x.Value).ToObject <StringRegExCheckSettings>();

            if (string.IsNullOrWhiteSpace(Settings.Hint))
            {
                throw new ArgumentNullException(nameof(Settings.Hint));
            }
            if (string.IsNullOrWhiteSpace(Settings.RegEx))
            {
                throw new ArgumentNullException(nameof(Settings.RegEx));
            }

            _noMatch = new ValueCheckResult(false, new ArgumentException(Settings.Hint));
        }
Esempio n. 4
0
        public DateTimeComparisonCheck(
            IDictionary <string, string> settings, Func <FormData> formData,
            INZazuTableDataSerializer tableSerializer, int rowIdx,
            FieldDefinition fieldDefinition)

        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            Settings = settings.ToDictionary(x => x.Key, x => (object)x.Value)
                       .ToObject <DateTimeComparisonCheckSettings>();

            _rowIdx          = rowIdx;
            _fieldDefinition = fieldDefinition ?? throw new ArgumentNullException(nameof(fieldDefinition));
            _tableSerializer = tableSerializer ?? throw new ArgumentNullException(nameof(tableSerializer));

            _formData = formData ?? throw new ArgumentNullException(nameof(formData));
        }
Esempio n. 5
0
        // ReSharper disable UnusedParameter.Local
        public RangeCheck(
            IDictionary <string, string> settings, Func <FormData> formData,
            INZazuTableDataSerializer tableSerializer, int rowIdx,
            FieldDefinition fieldDefinition)
        {
            Settings = settings.ToDictionary(x => x.Key, x => (object)x.Value).ToObject <RangeCheckSettings>();

            if (Settings.MinInt < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(Settings.Min),
                                                      $"The specified value must be between {Settings.MinInt} and {Settings.MaxInt}");
            }
            if (Settings.MaxInt < Settings.MinInt)
            {
                throw new ArgumentOutOfRangeException(
                          $"min={Settings.MinInt} must be less than or equal to max={Settings.MaxInt}.");
            }

            _outOfRange = new ValueCheckResult(false, new ArgumentOutOfRangeException(
                                                   $"The specified value must be between {Settings.MinInt} and {Settings.MaxInt}"));
        }
Esempio n. 6
0
        // ReSharper disable UnusedParameter.Local
        public StringLengthCheck(
            IDictionary <string, string> settings, Func <FormData> formData,
            INZazuTableDataSerializer tableSerializer, int rowIdx, FieldDefinition field)
        {
            Settings = settings.ToDictionary(x => x.Key, x => (object)x.Value).ToObject <StringLengthCheckSettings>();

            if (Settings.MinInt < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(Settings.Min),
                                                      $"Minimum string length '{Settings.MinInt}' must not be negative.");
            }
            if (Settings.MaxInt < Settings.MinInt)
            {
                throw new ArgumentOutOfRangeException(
                          $"min={Settings.MinInt} must be less than or equal to max={Settings.MaxInt}.");
            }

            _valueTooShort = new ValueCheckResult(false, new ArgumentException(
                                                      $"The specified string is too short (at least {Settings.MinInt} characters)"));
            _valueTooLong = new ValueCheckResult(false, new ArgumentException(
                                                     $"The specified string is too long (at most {Settings.MaxInt} characters)"));
        }
        public static NZazuField AddChecks(
            this NZazuField field,
            IEnumerable <CheckDefinition> checkDefinitions,
            ICheckFactory checkFactory,
            Func <FormData> formData = null,
            INZazuTableDataSerializer tableSerializer = null,
            int rowIdx = -1)
        {
            if (checkDefinitions == null)
            {
                return(field);
            }

            var checks = checkDefinitions
                         .Select(x => checkFactory.CreateCheck(x, field.Definition, formData, tableSerializer, rowIdx))
                         .ToArray();

            field.Check = checks.Length == 1
                ? checks.First()
                : new AggregateCheck(checks.ToArray());

            return(field);
        }
Esempio n. 8
0
 public NZazuDataTableField(FieldDefinition definition, Func <Type, object> serviceLocatorFunc)
     : base(definition, serviceLocatorFunc)
 {
     _serializer = (INZazuTableDataSerializer)serviceLocatorFunc(typeof(INZazuTableDataSerializer));
     _factory    = (INZazuWpfFieldFactory)serviceLocatorFunc(typeof(INZazuWpfFieldFactory));
 }