Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValidationEventArgs"/> class.
 /// </summary>
 /// <param name="value">The value that contains the warning or error.</param>
 /// <param name="message">The actual warning or error message.</param>
 /// <param name="action">The action of the validation event.</param>
 /// <param name="type">The type of validation.</param>
 internal ValidationEventArgs(object value, string message, ValidationEventAction action, ValidationType type)
 {
     Value   = value;
     Message = message;
     Action  = action;
     Type    = type;
 }
Esempio n. 2
0
        /// <summary>
        /// Process an validation message.
        /// </summary>
        /// <param name="bindingObject">The binding object which will be used as key in dictionary with error messages. Allowed to be <c>null</c> if <see cref="ValidationEventAction.ClearAll"/>.</param>
        /// <param name="message">The actual warning or error message.</param>
        /// <param name="action">An error event action. See <see cref="ValidationErrorEventAction"/>.</param>
        /// <param name="type">The validation type.</param>
        private void ProcessValidationMessage(object bindingObject, string message, ValidationEventAction action, ValidationType type)
        {
            if ((action != ValidationEventAction.ClearAll) && (bindingObject is null))
            {
                Log.Warning("Null-values are not allowed when not using ValidationEventAction.ClearAll");
                return;
            }

            if (_objectsToIgnore.Contains(bindingObject) && (action != ValidationEventAction.ClearAll))
            {
                Log.Debug("Object '{0}' is in the ignore list, thus messages will not be handled", bindingObject);
                return;
            }

            var messages = (type == ValidationType.Warning) ? _warnings : _errors;

            lock (_lock)
            {
                switch (action)
                {
                case ValidationEventAction.Added:
                case ValidationEventAction.Refresh:
                    if (!messages.TryGetValue(bindingObject, out var addBindingObjectMessages))
                    {
                        addBindingObjectMessages = new List <string>();
                        messages.Add(bindingObject, addBindingObjectMessages);
                    }

                    if (!addBindingObjectMessages.Contains(message))
                    {
                        addBindingObjectMessages.Add(message);
                    }
                    break;

                case ValidationEventAction.Removed:
                    if (messages.TryGetValue(bindingObject, out var removeBindingObjectMessages))
                    {
                        removeBindingObjectMessages.Remove(message);
                    }
                    break;

                case ValidationEventAction.ClearAll:
                    if (bindingObject != null)
                    {
                        messages.Remove(bindingObject);
                    }
                    else
                    {
                        messages.Clear();
                    }
                    break;
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Raises an validation warning or error event.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="message">A message.</param>
 /// <param name="action">A action for handling the error event.</param>
 /// <param name="type">The type.</param>
 private void RaiseBusinessValidationWarningOrError(object value, string message, ValidationEventAction action, ValidationType type)
 {
     Validation.SafeInvoke(this, () => new ValidationEventArgs(value, message, action, type));
 }
Esempio n. 4
0
        /// <summary>
        /// Process an validation message.
        /// </summary>
        /// <param name="bindingObject">The binding object which will be used as key in dictionary with error messages. Allowed to be <c>null</c> if <see cref="ValidationEventAction.ClearAll"/>.</param>
        /// <param name="message">The actual warning or error message.</param>
        /// <param name="action">An error event action. See <see cref="ValidationErrorEventAction"/>.</param>
        /// <param name="type">The validation type.</param>
        private void ProcessValidationMessage(object bindingObject, string message, ValidationEventAction action, ValidationType type)
        {
            if ((action != ValidationEventAction.ClearAll) && (bindingObject == null))
            {
                Log.Warning("Null-values are not allowed when not using ValidationEventAction.ClearAll");
                return;
            }

            if (_objectsToIgnore.Contains(bindingObject) && (action != ValidationEventAction.ClearAll))
            {
                Log.Debug("Object '{0}' is in the ignore list, thus messages will not be handled", bindingObject);
                return;
            }

            Dictionary<object, List<string>> messages = (type == ValidationType.Warning) ? _warnings : _errors;

            lock (_lock)
            {
                switch (action)
                {
                    case ValidationEventAction.Added:
                    case ValidationEventAction.Refresh:
                        if (!messages.ContainsKey(bindingObject))
                        {
                            messages.Add(bindingObject, new List<string>());
                        }

                        if (!messages[bindingObject].Contains(message))
                        {
                            messages[bindingObject].Add(message);
                        }
                        break;

                    case ValidationEventAction.Removed:
                        if (messages.ContainsKey(bindingObject))
                        {
                            messages[bindingObject].Remove(message);
                        }
                        break;

                    case ValidationEventAction.ClearAll:
                        if (bindingObject != null)
                        {
                            messages.Remove(bindingObject);
                        }
                        else
                        {
                            messages.Clear();
                        }
                        break;
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Raises an validation warning or error event.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="message">A message.</param>
 /// <param name="action">A action for handling the error event.</param>
 /// <param name="type">The type.</param>
 private void RaiseBusinessValidationWarningOrError(object value, string message, ValidationEventAction action, ValidationType type)
 {
     Validation.SafeInvoke(this, new ValidationEventArgs(value, message, action, type));
 }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValidationEventArgs"/> class.
 /// </summary>
 /// <param name="value">The value that contains the warning or error.</param>
 /// <param name="message">The actual warning or error message.</param>
 /// <param name="action">The action of the validation event.</param>
 /// <param name="type">The type of validation.</param>
 internal ValidationEventArgs(object value, string message, ValidationEventAction action, ValidationType type)
 {
     Value = value;
     Message = message;
     Action = action;
     Type = type;
 }