示例#1
0
        private void RemoveValidationResult(string propertyName, IPropertyValidationRule rule)
        {
            lock (this.validationErrorsLock)
            {
                KeyValuePair <string, ICollection <ValidationResult> > errorSet =
                    this.validationErrors.FirstOrDefault(pair => pair.Key == propertyName);

                if (errorSet.Key == null)
                {
                    // There arent any validation validation errors for this property. This can be expected when a
                    // rule deems a property's value a 'valid' when it is already valid (such as the initial value).
                    return;
                }

                ValidationResult error = errorSet.Value.FirstOrDefault(e => e.RuleInstanceId == rule.RuleInstanceId);

                if (error == null)
                {
                    LoggerExtensions.LogPropertyValidationInfo(
                        "RemoveValidationResult: Failed to remove validation result for rule {0} ({1}) because it was not found in the collection for element {2} of property {3}",
                        rule.GetType().Name,
                        rule.RuleInstanceId,
                        this.TrackingId,
                        propertyName);

                    return;
                }

                errorSet.Value.Remove(error);

                if (!errorSet.Value.Any())
                {
                    this.validationErrors.Remove(errorSet.Key);
                }

                LoggerExtensions.LogPropertyValidationInfo(
                    "RemoveValidationResult: Removed result for rule {0} ({1}) on property {2}",
                    rule.GetType().Name,
                    error.RuleInstanceId,
                    error.PropertyName);

                this.ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(propertyName));
            }
        }
示例#2
0
        private void AddValidationRule(PropertyInfo propertyInfo, IPropertyValidationRule rule)
        {
            IList <IPropertyValidationRule> rulesForProperty;

            if (!this.PropertyValidationRules.TryGetValue(propertyInfo.Name, out rulesForProperty))
            {
                this.PropertyValidationRules.Add(propertyInfo.Name, rulesForProperty = new List <IPropertyValidationRule>());
            }

            rulesForProperty.Add(rule);

            LoggerExtensions.LogPropertyValidationInfo(
                "Adding validation rule {0} with Id {1} for property {2} on element {3}",
                rule.GetType().Name,
                rule.RuleInstanceId,
                propertyInfo.Name,
                this.GetType().Name);
        }
示例#3
0
        private void AddValidationResult(ValidationResult result, IPropertyValidationRule rule)
        {
            lock (this.validationErrorsLock)
            {
                if (!this.validationErrors.ContainsKey(result.PropertyName))
                {
                    this.validationErrors[result.PropertyName] = new List <ValidationResult>();
                }

                this.validationErrors[result.PropertyName].Add(result);
            }

            LoggerExtensions.LogPropertyValidationInfo(
                "AddValidationResult: Added result for rule {0} ({1}) on property {2}",
                rule.GetType().Name,
                result.RuleInstanceId,
                result.PropertyName);

            this.ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(result.PropertyName));
        }