/// <summary>
        /// Handle the error by formatting the error message first and then adding it
        /// to the validation errors. Then add it to the log.
        /// </summary>
        /// <param name="errorDescriptor"></param>
        /// <param name="resources"></param>
        /// <param name="errors"></param>
        /// <param name="ex"></param>
        /// <param name="args"></param>
        public void Handle(string errorDescriptor, ILocalizedResourceManager resources, IStatusResults errors, Exception ex, string[] args)
        {
            string error        = resources.GetString(errorDescriptor);
            string errorDetails = error;

            if (args != null && args.Length > 0)
            {
                foreach (string arg in args)
                {
                    errorDetails += arg + " ";
                }
            }

            // Add to validation results.
            errors.Add(errorDetails);

            // Add to log.
            if (ex == null)
            {
                Logger.Error(errorDetails);
            }
            else
            {
                Logger.Error(errorDetails, ex);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Transfers all the messages from the source to the validation results.
 /// </summary>
 /// <param name="messages"></param>
 /// <param name="results"></param>
 public static void TransferMessages(IList <string> messages, IStatusResults results)
 {
     foreach (string message in messages)
     {
         results.Add(string.Empty, message, null);
     }
 }
Beispiel #3
0
 /// <summary>
 /// Validates the bool condition and adds the string error
 /// to the error list if the condition is invalid.
 /// </summary>
 /// <param name="isValid">Flag indicating if invalid.</param>
 /// <param name="error">Error message</param>
 /// <param name="results"><see cref="ValidationResults"/></param>
 /// <returns>True if isError is false, indicating no error.</returns>
 public static bool Validate(bool isError, IStatusResults results, string message)
 {
     if (isError)
     {
         results.Add(string.Empty, message, null);
     }
     return(!isError);
 }
Beispiel #4
0
 /// <summary>
 /// Validates the bool condition and adds the string error
 /// to the error list if the condition is invalid.
 /// </summary>
 /// <param name="isValid">Flag indicating if invalid.</param>
 /// <param name="error">Error message</param>
 /// <param name="results"><see cref="ValidationResults"/></param>
 /// <returns>True if isError is false, indicating no error.</returns>
 public static bool Validate(bool isError, IStatusResults results, string key, string message, object target)
 {
     if (isError)
     {
         results.Add(key, message, target);
     }
     return(!isError);
 }
        /// <summary>
        /// Internal method for handling errors.
        /// </summary>
        /// <param name="error"></param>
        /// <param name="exception"></param>
        /// <param name="handler"></param>
        /// <param name="errorResults"></param>
        /// <param name="arguments"></param>
        protected virtual void InternalHandle(object error, Exception exception, IStatusResults errorResults, object[] arguments)
        {
            string fullError = error == null ? string.Empty : error.ToString();

            // Add error to list and log.
            if (errorResults != null)
            {
                errorResults.Add(fullError);
                fullError = ValidationUtils.BuildSingleErrorMessage(errorResults, Environment.NewLine);
            }

            Logger.Error(fullError, exception, arguments);
        }
        /// <summary>
        /// Handles the error by added it it the validation errors, and logging it.
        /// </summary>
        /// <param name="errorDescriptor"></param>
        /// <param name="resources"></param>
        /// <param name="errors"></param>
        public void Handle(string errorDescriptor, ILocalizedResourceManager resources, IStatusResults errors, Exception ex)
        {
            string error = resources.GetString(errorDescriptor);

            // Add to error list.
            errors.Add(error);

            // Add to log.
            if (ex == null)
            {
                Logger.Error(error);
            }
            else
            {
                Logger.Error(error, ex);
            }
        }