コード例 #1
0
 internal ValidationResult(ValidationKind type, string message, bool isSuccess = true, bool isApplicable = true)
 {
     this.Type         = type;
     this.IsSuccess    = isSuccess;
     this.IsApplicable = isApplicable;
     this.Message      = message;
 }
コード例 #2
0
        private void WriteNotApplicableResult(ILWriter writer, ValidationKind kind)
        {
            var notApplicable = KnownMetadata.Methods.ValidationResult_NotApplicable;

            writer.LoadInt32((int)kind);
            writer.StaticMethodCall(notApplicable);
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValidationError"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="source">The source.</param>
 /// <param name="kind">The kind .</param>
 /// <param name="members">The members.</param>
 public ValidationError(string message, object source, ValidationKind kind, AllorsEmbeddedRelationType[] members)
 {
     this.source  = source;
     this.members = members;
     this.kind    = kind;
     this.message = message;
 }
コード例 #4
0
ファイル: Parser.cs プロジェクト: jilledille/nor-id-num
        private OperationResult CheckValidation()
        {
            OperationResult result;
            ValidationKind  validationKind = CheckValidationKind();
            bool            repeat         = CheckValidationRepeat();
            Validator       validator      = new Validator(validationKind);

            if (repeat)
            {
                result = validator.RepeatValidation();
            }
            else
            {
                if (_parameters.Count > 0)
                {
                    string number = _parameters.Dequeue();
                    result = validator.ValidateOne(number);
                }
                else
                {
                    result = new OperationResult {
                        Code = (Statuscode)(-1)
                    };
                }
            }
            return(result);
        }
コード例 #5
0
ファイル: ValidationError.cs プロジェクト: whesius/allors
 /// <summary>
 /// Initializes a new instance of the <see cref="ValidationError"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="source">The source.</param>
 /// <param name="kind">The kind .</param>
 /// <param name="members">The members.</param>
 public ValidationError(string message, object source, ValidationKind kind, string[] members)
 {
     this.source = source;
     this.members = members;
     this.kind = kind;
     this.message = message;
 }
コード例 #6
0
 internal ValidationResult(ValidationKind type, string message, bool isSuccess = true, bool isApplicable = true)
 {
     this.Type = type;
     this.IsSuccess = isSuccess;
     this.IsApplicable = isApplicable;
     this.Message = message;            
 }
コード例 #7
0
ファイル: ValidationError.cs プロジェクト: lulzzz/allors2
 /// <summary>
 /// Initializes a new instance of the <see cref="ValidationError"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="source">The source.</param>
 /// <param name="kind">The kind .</param>
 /// <param name="members">The members.</param>
 public ValidationError(string message, object source, ValidationKind kind, string[] members)
 {
     this.source  = source;
     this.members = members;
     this.kind    = kind;
     this.message = message;
 }
コード例 #8
0
        private void WriteFailureResult(ILWriter writer, ValidationKind kind, string message)
        {
            var failure = KnownMetadata.Methods.ValidationResult_Failure;

            writer.LoadInt32((int)kind);
            writer.LoadString(message);
            writer.StaticMethodCall(failure);
        }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValidationBase" /> class.
 /// </summary>
 /// <param name="validationName">Name of the validation.</param>
 /// <param name="validationType">Type of the validation.</param>
 /// <param name="validationKind">Kind of the validation.</param>
 public ValidationBase(
     string validationName,
     ValidationType validationType,
     ValidationKind validationKind)
 {
     DisplayName = validationName;
     ValidationKind = validationKind;
     ValidationType = validationType;
     SuccessfulResult = ValidationResult.SuccessfullValidationResult(validationType, validationKind);
 }
コード例 #10
0
 public BaseValidation(
     string validationName,
     ValidationType validationType,
     ValidationKind validationKind)
 {
     this.DisplayName      = validationName;
     this.ValidationKind   = validationKind;
     this.ValidationType   = validationType;
     this.SuccessfulResult = ValidationResult.SuccessfullValidationResult(validationType, validationKind);
 }
コード例 #11
0
        internal ValidationResult AddResult(string message, ValidationKind kind)
        {
            ValidationResult result = null;

            Add(result = new ValidationResult
            {
                Message   = message,
                Kind      = kind,
                Exception = new ValidationException(message)
            });
            return(result);
        }
コード例 #12
0
        public static IValidationResult Validate <T> (ValidationKind validationKind, T[] validationParameters, T checkedObject)
        {
            switch (validationKind)
            {
            case ValidationKind.Unique:
                object[] validationParametersObjectArray = new object[validationParameters.Length];
                validationParameters.CopyTo(validationParametersObjectArray, 0);
                UniqueValidator <T> validator = new UniqueValidator <T>(validationParametersObjectArray, checkedObject);
                return(validator.Validate( ));

            default: throw new NotImplementedException("Not implemented switch in ValidatorProvider.Validate()");
            }
        }
コード例 #13
0
        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>PSValidationKind.</returns>
        /// <exception cref="ArgumentException"></exception>
        private PSValidationKind Convert(ValidationKind value)
        {
            switch (value)
            {
            case ValidationKind.SystemValidation:
                return(PSValidationKind.SystemValidation);

            case ValidationKind.NamespaceValidation:
                return(PSValidationKind.NamespaceValidation);

            default:
                throw new ArgumentException(string.Format(StorageSyncResources.UnsupportedErrorFormat, value.GetType().Name, value));
            }
        }
コード例 #14
0
        private PSValidationKind Convert(ValidationKind value)
        {
            switch (value)
            {
            case ValidationKind.SystemValidation:
                return(PSValidationKind.SystemValidation);

            case ValidationKind.NamespaceValidation:
                return(PSValidationKind.NamespaceValidation);

            default:
                throw new ArgumentException($"{value.GetType().Name} value {value} is unsupported");
            }
        }
コード例 #15
0
 public ViewModelCollectionPropertyDescriptor <TOwner, TResult> Validate(
     Func <TOwner, TResult, bool> condition,
     ValidationKind kind                = ValidationKind.Error,
     string message                     = null,
     bool continueOnValidationError     = true,
     bool notifyChangeOnValidationError = true)
 {
     ValidationRecords.Add(new ValidationRecord()
     {
         Validate = (vm, x, res) => res.Validate(condition(vm, x), message, kind),
         ContinueOnValidationError     = continueOnValidationError,
         NotifyChangeOnValidationError = notifyChangeOnValidationError
     });
     return(this);
 }
コード例 #16
0
 public ViewModelCollectionPropertyDescriptor <TOwner, TResult> Validate <TValidator>(
     ValidationKind kind                = ValidationKind.Error,
     string message                     = null,
     bool continueOnValidationError     = true,
     bool notifyChangeOnValidationError = true)
     where TValidator : IValidator, new()
 {
     ValidationRecords.Add(new ValidationRecord()
     {
         Validate = (vm, x, res) => res.Validate <TValidator>(x, message, kind),
         ContinueOnValidationError     = continueOnValidationError,
         NotifyChangeOnValidationError = notifyChangeOnValidationError
     });
     return(this);
 }
コード例 #17
0
 public ViewModelPropertyDescriptor <TOwner, TResult> Validate(
     IValidator validator,
     ValidationKind kind                = ValidationKind.Error,
     string message                     = null,
     bool continueOnValidationError     = true,
     bool notifyChangeOnValidationError = true,
     ValidationErrorBehavior when       = ValidationErrorBehavior.AfterCoerce)
 {
     ValidationRecords.Add(new ValidationRecord()
     {
         Validate = (vm, x, res) => res.Validate(validator, x, message, kind),
         ContinueOnValidationError     = continueOnValidationError,
         NotifyChangeOnValidationError = notifyChangeOnValidationError,
         BehaviorOnCoerce = when
     });
     return(this);
 }
コード例 #18
0
        private static void RecordResultAndResetStopwatches(
            this List <BenchmarkResult> results,
            IReadOnlyDictionary <BenchmarkSignatureKind, Stopwatch> benchmarkKindToStopwatchMap,
            ValidationKind validationKind,
            OutcomeKind outcomeKind)
        {
            foreach (var benchmarkSignature in benchmarkKindToStopwatchMap.Keys)
            {
                var stopwatch = benchmarkKindToStopwatchMap[benchmarkSignature];

                var benchmarkResult = new BenchmarkResult
                {
                    BenchmarkSignatureKind = benchmarkSignature,
                    ValidationKind         = validationKind,
                    OutcomeKind            = outcomeKind,
                    Elapsed = stopwatch.Elapsed,
                };

                results.Add(benchmarkResult);

                stopwatch.Reset();
            }
        }
コード例 #19
0
 public BrokenAttributeValidator(Type brokenValidatorType, ValidationKind kind, string message)
 {
     //this.brokenValidatorType = brokenValidatorType;
     this.kind    = kind;
     this.message = message;
 }
コード例 #20
0
ファイル: ValidationLog.cs プロジェクト: whesius/allors
 /// <summary>
 /// Adds a new validation error.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="source">The source.</param>
 /// <param name="kind">The kind.</param>
 /// <param name="members">The members.</param>
 public void AddError(string message, object source, ValidationKind kind, params string[] members)
 {
     this.errors.Add(new ValidationError(message, source, kind, members));
 }
コード例 #21
0
 /// <summary>
 /// Adds a new validation error.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="source">The source.</param>
 /// <param name="kind">The kind.</param>
 /// <param name="members">The members.</param>
 public void AddError(string message, object source, ValidationKind kind, params string[] members)
 {
     this.errors.Add(new ValidationError(message, source, kind, members));
 }
コード例 #22
0
 public Validator(ValidationKind validationKind)
 {
     _validationKind = validationKind;
 }
コード例 #23
0
 public static IValidationResult NotApplicable(ValidationKind type)
 {
     return new ValidationResult(type, CommonResults.ValidationNotApplicable.WithValues(type.ToString()), isSuccess: false, isApplicable: false);
 }
コード例 #24
0
 public ValidationResult Validate <TValidator>(object value, string message, ValidationKind kind)
     where TValidator : IValidator, new()
 => Validate(new TValidator(), value, message, kind);
コード例 #25
0
 public static IValidationResult NotApplicable(ValidationKind type)
 {
     return(new ValidationResult(type, CommonResults.ValidationNotApplicable.WithValues(type.ToString()), isSuccess: false, isApplicable: false));
 }
コード例 #26
0
 public static IValidationResult Failure(ValidationKind type, string message)
 {
     return(new ValidationResult(type, message, isSuccess: false));
 }
コード例 #27
0
 internal void AddValidationResult(TOwner owner, string propertyName, string message, ValidationKind kind)
 {
     ValidationResults.AddResult(message, kind);
     owner.OnErrorChanged(propertyName);
 }
コード例 #28
0
 public BaseValidationAttribute(string errorMessageSnippet, ValidationKind kind)
 {
     this.ErrorMessageSnippet = errorMessageSnippet;
     this.ValidatorKind       = kind;
 }
コード例 #29
0
 public ValidationResult Validate(bool condition, string message, ValidationKind kind)
 => condition?AddResult(message, kind) : null;
コード例 #30
0
 /// <summary>
 /// Successfulls the validation result.
 /// </summary>
 /// <param name="validationType">Type of the validation.</param>
 /// <param name="validationKind">Kind of the validation.</param>
 /// <returns>IValidationResult.</returns>
 public static IValidationResult SuccessfullValidationResult(ValidationType validationType, ValidationKind validationKind)
 {
     return(new ValidationResult
     {
         Type = validationType,
         Kind = validationKind,
         Level = ResultLevel.Info,
         Result = Result.Success,
         Description = "Validation succeeded."
     });
 }
コード例 #31
0
        public ValidationResult Validate(IValidator validator, object value, string message, ValidationKind kind)
        {
            ValidationResult result = null;

            if (validator.Validate(value, message) is string msg)
            {
                Add(result = new ValidationResult
                {
                    Message   = msg,
                    Kind      = kind,
                    Exception = new ValidationException(message)
                });
            }
            return(result);
        }
コード例 #32
0
 /// <summary>
 /// Unavailables the validation.
 /// </summary>
 /// <param name="validationType">Type of the validation.</param>
 /// <param name="validationKind">Kind of the validation.</param>
 /// <param name="description">The description.</param>
 /// <returns>IValidationResult.</returns>
 public static IValidationResult UnavailableValidation(ValidationType validationType, ValidationKind validationKind, string description)
 {
     return(new ValidationResult
     {
         Type = validationType,
         Kind = validationKind,
         Level = ResultLevel.Warning,
         Result = Result.Unavailable,
         Description = description
     });
 }
コード例 #33
0
 public BaseValidationAttribute(string errorMessageSnippet, ValidationKind kind)
 {
     this.ErrorMessageSnippet = errorMessageSnippet;
     this.ValidatorKind = kind;
 }
コード例 #34
0
 /// <summary>
 /// Unauthorizeds the access dir.
 /// </summary>
 /// <param name="validationType">Type of the validation.</param>
 /// <param name="validationKind">Kind of the validation.</param>
 /// <param name="dir">The dir.</param>
 /// <returns>IValidationResult.</returns>
 public static IValidationResult UnauthorizedAccessDir(ValidationType validationType, ValidationKind validationKind, IDirectoryInfo dir)
 {
     return(new ValidationResult
     {
         Type = validationType,
         Kind = validationKind,
         Level = ResultLevel.Warning,
         Result = Result.Unavailable,
         Description = "The directory could not be validated because the user is not authorized to access it.",
         Path = dir.FullName
     });
 }
コード例 #35
0
        public static void AddValidationResult <T, TResult>(this T vm, Expression <Func <T, TResult> > propExp, string message, ValidationKind kind)
            where T : ViewModelBase <T>
        {
            var propertyName = (propExp.Body as MemberExpression).Member.Name;

            if (vm._values.TryGetValue(propertyName, out IViewModelProperty prop))
            {
                ((ViewModelProperty <T, TResult>)prop).AddValidationResult(vm, propertyName, message, kind);
            }
        }
コード例 #36
0
 public static IValidationResult Failure(ValidationKind type, string message)
 {
     return new ValidationResult(type, message, isSuccess: false);
 }