Beispiel #1
0
        protected override void Validate()
        {
            if (this.NeedValidation == true)
            {
                DESchemaPropertyValidatorContext context = DESchemaPropertyValidatorContext.Current;

                try
                {
                    context.Target    = this.Data;
                    context.Container = this._Container;

                    ValidationResults validationResult = new ValidationResults();

                    if (this.Data.Status == SchemaObjectStatus.Normal)
                    {
                        validationResult = this.Data.Validate();
                    }

                    //haoyk 2014-2-8
                    if (this.SaveMemberData && this.Members.Any())
                    {
                        this.Members.Where(p => p.Status == SchemaObjectStatus.Normal).ForEach(p =>
                        {
                            ValidationResults results = p.Validate();

                            if (results != null && results.Any())
                            {
                                results.ForEach(validationResult.AddResult);
                            }
                        });
                    }

                    ExceptionHelper.TrueThrow(validationResult.ResultCount > 0, validationResult.ToString());

                    CheckStatus();
                }
                finally
                {
                    DESchemaPropertyValidatorContext.Clear();
                }
            }
        }
Beispiel #2
0
 public ICollection <ValidationMessageModel> Validate(T source, string ruleset)
 {
     try
     {
         IObjectValidator <T> sourceMapped = MappingFrom(source);
         string            rule            = string.IsNullOrEmpty(ruleset) ? string.Empty : ruleset;
         Validator         validator       = ValidationFactory.CreateValidator <E>(rule);
         ValidationResults results         = validator.Validate(sourceMapped);
         ICollection <ValidationMessageModel> validationResults = new Collection <ValidationMessageModel>();
         results.ForEach(x => validationResults.Add(new ValidationMessageModel()
         {
             Message = x.Message, Key = x.Tag, MessageCode = 0
         }));
         return(validationResults);
     }
     catch (Exception ex)
     {
         _logger.WriteError(ex, LogCategories);
         throw new DSWException(string.Concat("Object Validator - unexpected exception was thrown while invoking validate: ", ex.Message), ex, DSWExceptionCode.VA_Anomaly);
     }
 }