Example #1
0
        private IValidationErrors GetErrors(IValidationErrors result, RowPresenter rowPresenter, IColumns source, bool isAsync)
        {
            IReadOnlyDictionary <RowPresenter, IDataValidationErrors> dictionary = isAsync ? _asyncErrorsByRow : _errorsByRow;

            if (dictionary != null)
            {
                IDataValidationErrors errors;
                if (dictionary.TryGetValue(rowPresenter, out errors))
                {
                    if (errors != null && errors.Count > 0)
                    {
                        result = GetErrors(result, rowPresenter, errors, source, !isAsync);
                    }
                }
            }

            if (isAsync && rowPresenter == CurrentRow)
            {
                foreach (var asyncValidator in AsyncValidators)
                {
                    var fault = asyncValidator.GetFault(source);
                    if (fault != null)
                    {
                        result = result.Add(fault);
                    }
                }
            }

            return(result);
        }
Example #2
0
 private void ValidateConfirmPassword(IValidationErrors errors)
 {
     if (!string.IsNullOrEmpty(ConfirmPassword) && Password != ConfirmPassword)
     {
         errors.Add(ErrorSeverity.Error, PasswordHelper.MatchingMessage);
     }
 }
Example #3
0
    private static void ValidatePlebStopThreshold(IValidationErrors errors, string plebStopThreshold)
    {
        if (string.IsNullOrWhiteSpace(plebStopThreshold) || string.IsNullOrEmpty(plebStopThreshold))
        {
            return;
        }

        if (plebStopThreshold.Contains(',', StringComparison.InvariantCultureIgnoreCase))
        {
            errors.Add(ErrorSeverity.Error, "Use decimal point instead of comma.");
        }
        else if (!decimal.TryParse(plebStopThreshold, out _))
        {
            errors.Add(ErrorSeverity.Error, "Invalid coinjoin threshold.");
        }
    }
Example #4
0
        public void Create(CreateUser model, IValidationErrors errors)
        {
            if (!model.Validate(errors))
            {
                return;
            }

            if (UnitOfWork.Users.Any(x => x.UserName == model.UserName))
            {
                errors.Add("UserName", "UserName is already taken");
                return;
            }

            var user = model.MapTo <User>();

            foreach (var userModule in user.UserModules)
            {
                userModule.UserId = user.Id;
            }

            var result = UserManager.Create(user, model.Password);

            if (!result.Succeeded)
            {
                errors.AddErrorsFromResult(result);
                return;
            }

            model.UserId = user.Id;
        }
        private void ValidateDustThreshold(IValidationErrors errors, string dustThreshold, bool whiteSpaceOk)
        {
            if (!whiteSpaceOk || !string.IsNullOrWhiteSpace(dustThreshold))
            {
                if (!string.IsNullOrEmpty(dustThreshold) && dustThreshold.Contains(
                        ',',
                        StringComparison.InvariantCultureIgnoreCase))
                {
                    errors.Add(ErrorSeverity.Error, "Use decimal point instead of comma.");
                }

                if (!decimal.TryParse(dustThreshold, out var dust) || dust < 0)
                {
                    errors.Add(ErrorSeverity.Error, "Invalid dust threshold.");
                }
            }
        }
Example #6
0
 private void ValidateToField(IValidationErrors errors)
 {
     if (!string.IsNullOrWhiteSpace(To) &&
         !AddressStringParser.TryParse(To, _owner.Wallet.Network, out BitcoinUrlBuilder? url))
     {
         errors.Add(ErrorSeverity.Error, "Input a valid BTC address or URL.");
     }
 }
Example #7
0
 internal static IValidationErrors Merge(this IValidationErrors result, IValidationErrors errors)
 {
     for (int i = 0; i < errors.Count; i++)
     {
         result = result.Add(errors[i]);
     }
     return(result);
 }
    private void ValidateInteger(string text, string propertyName, IValidationErrors errors)
    {
        if (int.TryParse(text, out _))
        {
            return;
        }

        errors.Add(ErrorSeverity.Error, $"Field {propertyName} is not an integer.");
    }
 private void ValidateEndPoint(IValidationErrors errors, string endPoint, int defaultPort, bool whiteSpaceOk)
 {
     if (!whiteSpaceOk || !string.IsNullOrWhiteSpace(endPoint))
     {
         if (!EndPointParser.TryParse(endPoint, defaultPort, out _))
         {
             errors.Add(ErrorSeverity.Error, "Invalid endpoint.");
         }
     }
 }
    private void ValidateCustomFee(IValidationErrors errors)
    {
        var customFeeString = CustomFee;

        if (customFeeString is null or "")
        {
            return;
        }

        if (customFeeString.Any(c => !char.IsDigit(c) && c != '.'))
        {
            errors.Add(ErrorSeverity.Error, "The field only accepts numbers.");
            return;
        }

        if (!decimal.TryParse(customFeeString, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var value))
        {
            errors.Add(ErrorSeverity.Error, "The entered fee is not valid.");
            return;
        }

        if (value < decimal.One)
        {
            errors.Add(ErrorSeverity.Error, "Cannot be less than 1 sat/vByte.");
            return;
        }

        try
        {
            _ = new FeeRate(value);
        }
        catch (OverflowException)
        {
            errors.Add(ErrorSeverity.Error, "The entered fee is too high.");
            return;
        }
    }
Example #11
0
    private void ValidateWord(IValidationErrors errors)
    {
        if (string.IsNullOrWhiteSpace(Input))
        {
            return;
        }

        if (Input.Equals(Word, StringComparison.InvariantCultureIgnoreCase))
        {
            IsConfirmed = true;
            return;
        }

        errors.Add(ErrorSeverity.Error, $"The input does not match recovery word {Index}.");
    }
Example #12
0
        private void ValidateWord(IValidationErrors errors)
        {
            if (string.IsNullOrWhiteSpace(Input))
            {
                return;
            }

            if (Input == Word)
            {
                IsConfirmed = true;
                return;
            }

            errors.Add(ErrorSeverity.Error, $"The input does not match recovery word {Index}.");
        }
Example #13
0
        public static bool Validate(this object obj, IValidationErrors errors)
        {
            var results = obj.Validate();

            if (results.Count == 0)
            {
                return(true);
            }

            foreach (var validationResult in results)
            {
                errors.Add(validationResult.MemberNames.First(), validationResult.ErrorMessage);
            }
            return(false);
        }
Example #14
0
        /// <summary>
        /// Creates an <see cref="IValidationErrors"/> object from <see cref="ValidationError"/> objects.
        /// </summary>
        /// <param name="values">The <see cref="ValidationError"/> objects.</param>
        /// <returns>The created <see cref="IValidationErrors"/> object.</returns>
        public static IValidationErrors New(params ValidationError[] values)
        {
            values.VerifyNotNull(nameof(values));

            if (values.Length == 0)
            {
                return(Empty);
            }

            IValidationErrors result = values.VerifyNotNull(0, nameof(values));

            for (int i = 1; i < values.Length; i++)
            {
                result = result.Add(values.VerifyNotNull(i, nameof(values)));
            }
            return(result);
        }
Example #15
0
        private IValidationErrors GetErrors(IValidationErrors result, RowPresenter rowPresenter, IDataValidationErrors messages, IColumns columns, bool ensureVisible)
        {
            Debug.Assert(messages != null);

            for (int i = 0; i < messages.Count; i++)
            {
                var message = messages[i];
                if (ensureVisible && !IsVisible(rowPresenter, message.Source))
                {
                    continue;
                }
                if (columns == null || columns.IsSupersetOf(message.Source))
                {
                    result = result.Add(message);
                }
            }

            return(result);
        }