Example #1
0
        private void olvFiles_FormatRow(object sender, FormatRowEventArgs e)
        {
            if (Validators.Any())
            {
                var file = e.Model as XfeFileInfo;
                if (file == null)
                {
                    return;
                }

                if (file.FileInfo.Extension != ".xml")
                {
                    return;
                }

                file.ValidationErrors.Clear();
                foreach (IValidator validator in Validators)
                {
                    file.ValidationErrors.AddRange(validator.ValidateFile(file.FileInfo.FullName));
                }

                bool passedAll = !file.ValidationErrors.Any();

                e.Item.BackColor = passedAll ? _validBackgroundColor : _invalidBackgroundColor;
                e.Item.ForeColor = passedAll ? _validForegroundColor : _invalidForegroundColor;
            }
        }
        /// <summary>
        /// Validate all child validators.
        /// </summary>
        public void Validate()
        {
            foreach (var validator in Validators)
            {
                validator.Validate();
            }

            IsValid = !Validators.Any(validator => validator.ValidationState == ValidationState.IsInvalid);
        }
 public void UseAnnotations(IEnumerable <CustomAttributeData> customAttributes)
 {
     if (!Validators.Any(d => d is LengthValidator))
     {
         CustomAttributeData attr = customAttributes.FirstOrDefault(d => d.AttributeType == typeof(StringLengthAttribute));
         if (attr != null)
         {
             int len = (int)attr.ConstructorArguments.Select(d => d.Value).FirstOrDefault();
             Validators.Add(new LengthValidator(len));
         }
     }
 }
 public void SetNumericDefaults()
 {
     if (Validators.Any(d => d is NumericTextValidator || d is RestrictNumericValidator))
     {
         if (!Validators.Any(d => d is RestrictNumericValidator))
         {
             Validators.Add(new RestrictNumericValidator());
         }
         if (!Validators.Any(d => d is LengthValidator))
         {
             AddLength(15);
         }
     }
 }
Example #5
0
        /// <summary>
        ///     Runs all the validators in the validator list against the input value
        /// </summary>
        /// <returns>Boolean indicating whether the validation was successful</returns>
        public virtual bool Validate()
        {
            bool isValid = !Validators.Any();

            foreach (Validator validator in Validators)
            {
                switch (validator.ValidatorType)
                {
                case enValidationType.Required:
                    isValid = ValidateRequired();
                    break;
                }
            }

            return(isValid);
        }
        public virtual IEnumerable <IRow> Read()
        {
            Context.Debug(() => $"Running {Transforms.Count} transforms.");
            if (Context.Entity.NeedsUpdate())
            {
                if (Context.Process.Mode != "init")
                {
                    if (Context.Entity.Version != string.Empty)
                    {
                        var version = Context.Entity.GetVersionField();
                        if (version.Type == "byte[]")
                        {
                            var min = Context.Entity.MinVersion == null ? "null" : Utility.BytesToHexViaLookup32((byte[])Context.Entity.MinVersion).TrimStart(new[] { '0' });
                            var max = Context.Entity.MaxVersion == null ? "null" : Utility.BytesToHexViaLookup32((byte[])Context.Entity.MaxVersion).TrimStart(new[] { '0' });
                            Context.Info("Change Detected: Input:{0} > Output:{1}", max, min);
                        }
                        else
                        {
                            Context.Info("Change Detected: Input:{0} > Output:{1}", Context.Entity.MaxVersion ?? "null", Context.Entity.MinVersion ?? "null");
                        }
                    }
                }
                var data = Reader == null?InputProvider.Read() : Reader.Read();

#if NETS10
                // no PLINQ
#else
                if (Context.Entity.Pipeline == "parallel.linq")
                {
                    data = data.AsParallel();
                }
#endif

                if (Transforms.Any())
                {
                    data = Transforms.Aggregate(data, (rows, t) => t.Operate(rows));
                }
                if (Validators.Any())
                {
                    data = Validators.Aggregate(data, (rows, v) => v.Operate(rows));
                }
                return(data);
            }
            Context.Info("Change Detected: No.");
            return(Enumerable.Empty <IRow>());
        }
Example #7
0
        public virtual IEnumerable <IRow> Read()
        {
            Context.Debug(() => $"Running {Transforms.Count} transforms.");
            if (Context.Entity.NeedsUpdate())
            {
                if (Context.Process.Mode != "init")
                {
                    if (Context.Entity.Version != string.Empty)
                    {
                        if (Context.Entity.GetVersionField().Type == "byte[]")
                        {
                            var min = Context.Entity.MinVersion == null ? "null" : "0x" + string.Format("{0:X}", Utility.BytesToHexString((byte[])Context.Entity.MinVersion).TrimStart(new[] { '0' }));
                            var max = Context.Entity.MaxVersion == null ? "null" : "0x" + string.Format("{0:X}", Utility.BytesToHexString((byte[])Context.Entity.MaxVersion).TrimStart(new[] { '0' }));
                            Context.Info("Change Detected: Input: {0} > Output: {1}", max, min);
                        }
                        else
                        {
                            Context.Info("Change Detected: Input: {0} > Output: {1}", Context.Entity.MaxVersion, Context.Entity.MinVersion);
                        }
                    }
                }
                var data = Reader == null?InputProvider.Read() : Reader.Read();

                if (Transforms.Any())
                {
                    data = Transforms.Aggregate(data, (rows, t) => t.Operate(rows));
                }
                if (Validators.Any())
                {
                    data = Validators.Aggregate(data, (rows, v) => v.Operate(rows));
                }
                return(data);
            }
            Context.Info("Change Detected: No.");
            return(Enumerable.Empty <IRow>());
        }
Example #8
0
 public bool HasValidators() => Validators.Any();
 public bool Has <TValidator>() where TValidator : IValidator
 {
     return(Validators.Any(d => d is TValidator));
 }
 public bool HasRequired()
 {
     return(Validators.Any(d => d is RequiredValidator));
 }