示例#1
0
        /// <summary>
        /// Runs the validation process.
        /// </summary>
        public ValidationStatus Validate()
        {
            if (UsePattern && patternRegex != null)
            {
                var matchStatus = patternRegex.IsMatch(value?.ToString() ?? string.Empty)
                    ? ValidationStatus.Success
                    : ValidationStatus.Error;

                if (Status != matchStatus)
                {
                    Status = matchStatus;

                    if (matchStatus == ValidationStatus.Success)
                    {
                        ValidationSucceeded?.Invoke(new ValidationSucceededEventArgs());
                    }
                    else if (matchStatus == ValidationStatus.Error)
                    {
                        ValidationFailed?.Invoke(new ValidationFailedEventArgs(null));
                    }

                    Validated?.Invoke(new ValidatedEventArgs(Status, null));

                    StateHasChanged();
                }
            }
            else
            {
                var handler = Validator;

                if (handler != null)
                {
                    Validating?.Invoke();

                    var args = new ValidatorEventArgs(value);

                    handler(args);

                    if (Status != args.Status)
                    {
                        Status = args.Status;

                        if (args.Status == ValidationStatus.Success)
                        {
                            ValidationSucceeded?.Invoke(new ValidationSucceededEventArgs());
                        }
                        else if (args.Status == ValidationStatus.Error)
                        {
                            ValidationFailed?.Invoke(new ValidationFailedEventArgs(args.ErrorText));
                        }

                        Validated?.Invoke(new ValidatedEventArgs(Status, args.ErrorText));

                        StateHasChanged();
                    }
                }
            }

            return(Status);
        }
示例#2
0
        /// <summary>
        /// Runs the validation process.
        /// </summary>
        public ValidationStatus Validate()
        {
            var handler = Validator;

            if (handler != null)
            {
                Validating?.Invoke();

                var args = new ValidatorEventArgs(value);

                handler(args);

                if (Status != args.Status)
                {
                    Status = args.Status;

                    if (args.Status == ValidationStatus.Success)
                    {
                        ValidationSucceeded?.Invoke(new ValidationSucceededEventArgs());
                    }
                    else if (args.Status == ValidationStatus.Error)
                    {
                        ValidationFailed?.Invoke(new ValidationFailedEventArgs(args.ErrorText));
                    }

                    Validated?.Invoke(new ValidatedEventArgs(Status, args.ErrorText));

                    StateHasChanged();
                }
            }

            return(Status);
        }
示例#3
0
        void SetPropertyValue <T>(T value, bool ignoreValidationResult, string memberName, Action setPropertyAction)
        {
            string result = null;

            if (ValidateProperty(memberName, value, out result) || ignoreValidationResult)
            {
                setPropertyAction();
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(memberName));
            }
            else
            {
                InvalidateProperties();
                ValidationFailed?.Invoke(this, result);
            }
        }
示例#4
0
        /// <summary>
        /// Runs the validation process.
        /// </summary>
        public ValidationStatus Validate()
        {
            var handler = Validator;

            //Status = ValidationStatus.None;

            if (handler != null)
            {
                Validating?.Invoke();

                var args = new ValidatorEventArgs(value);

                handler(args);

                if (Status != args.Status)
                {
                    Status = args.Status;

                    if (args.Status == ValidationStatus.Success)
                    {
                        ValidationSucceeded?.Invoke(new ValidationSucceededEventArgs());
                    }
                    else if (args.Status == ValidationStatus.Error)
                    {
                        ValidationFailed?.Invoke(new ValidationFailedEventArgs(args.ErrorText));
                    }

                    Validated?.Invoke(new ValidatedEventArgs(Status, args.ErrorText));

                    StateHasChanged();
                }
            }

            // force the reload of all child components
            //StateHasChanged();

            return(Status);
        }
示例#5
0
 internal void OnValidationFailed(EntityRecord record)
 {
     ValidationFailed?.Invoke(record, EventArgs.Empty);
 }