Esempio n. 1
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);
     }
 }
 /// <summary>
 /// Create the model action context using existing errors or message collection.
 /// If empty, a default instance will be created.
 /// </summary>
 /// <param name="errors">Error collection</param>
 /// <param name="messages">Message collection</param>
 public ActionContext(object item, IValidationResults errors, IStatusResults messages)
     : this(errors, messages)
 {
     Item     = item;
     Errors   = errors == null ? new ValidationResults() : errors;
     Messages = messages == null ? new ValidationResults() : errors;
 }
 /// <summary>
 /// Initialize the scaffold context.
 /// </summary>
 /// <param name="errors"></param>
 /// <param name="messages"></param>
 /// <param name="entityName"></param>
 /// <param name="parentControlId"></param>
 public ScaffoldContext(IValidationResults errors, IStatusResults messages, string entityName, string entityId, string parentControlId)
     : base(errors, messages)
 {
     EntityName      = entityName;
     ParentControlId = parentControlId;
     EntityId        = entityId;
 }
Esempio n. 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 message)
 {
     if (isError)
     {
         results.Add(string.Empty, message, null);
     }
     return(!isError);
 }
Esempio n. 5
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);
 }
Esempio n. 6
0
        /// <summary>
        /// Builds a single error message from a list of action results.
        /// </summary>
        /// <param name="actionResults"></param>
        /// <param name="onlyBuildFromErrors"></param>
        /// <param name="resultSeparator"></param>
        /// <returns></returns>
        public static string BuildSingleErrorMessage(IStatusResults results, string resultSeparator)
        {
            StringBuilder buffer = new StringBuilder();

            foreach (IStatusResult entry in results)
            {
                buffer.Append(entry.ToString() + resultSeparator);
            }
            return(buffer.ToString());
        }
        /// <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 exception by getting the error description from the <paramref name="resources"/> using
 /// the key specified by <paramref name="errorDescriptorKey"/>. Adds the error to <paramref name="errors"/>.
 /// </summary>
 /// <param name="errorDescriptor">The name of key to use to get the localized errors from resources. </param>
 /// <param name="resources">The localized resources that contains the error string.</param>
 /// <param name="errors">The list of errors to add to the error string to.</param>
 /// <param name="ex">The exception to handle.</param>
 /// <param name="args">Array of strings to report in the error.</param>
 public static void Handle(string errorDescriptorKey, ILocalizationResourceProvider resources, IStatusResults errors, Exception ex, string[] args)
 {
     _localizedProvider.Handle(errorDescriptorKey, resources, errors, ex, args);
 }
Esempio n. 9
0
 protected override void InternalHandle(object error, Exception exception, IStatusResults errorResults, object[] arguments)
 {
     Logger.Info("This is from the custom exception handler");
     base.InternalHandle(error, exception, errorResults, arguments);
 }
 /// <summary>
 /// Initialize the action context.
 /// </summary>
 /// <param name="item"></param>
 /// <param name="errorList"></param>
 /// <param name="messages"></param>
 public ImportExportActionContext(T item, IList <T> items, IValidationResults errors, IStatusResults messages)
     : base(item, errors, messages)
 {
     _items = items;
 }
 /// <summary>
 /// Create the model action context using existing errors or message collection.
 /// If empty, a default instance will be created.
 /// </summary>
 /// <param name="errors">Error collection</param>
 /// <param name="messages">Message collection</param>
 public ActionContext(IValidationResults errors, IStatusResults messages)
 {
     Errors   = errors == null ? new ValidationResults() : errors;
     Messages = messages == null ? new ValidationResults() : messages;
 }
 /// <summary>
 /// Create the model action context using existing errors or message collection.
 /// If empty, a default instance will be created.
 /// </summary>
 /// <param name="errors">Error collection</param>
 /// <param name="messages">Message collection</param>
 public ActionContext(IValidationResults errors, IStatusResults messages, int id)
     : this(errors, messages)
 {
     Id = id;
 }
        /// <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);
            }
        }
        /// <summary>
        /// Handles the specified error.
        /// </summary>
        /// <param name="error">The error.</param>
        /// <param name="exception">The exception.</param>
        /// <param name="errorResults">The error results.</param>
        /// <param name="arguments">The arguments.</param>
        private static void InternalHandle(object error, Exception exception, string handler, IStatusResults errorResults, object[] arguments)
        {
            if (handler == null)
            {
                _provider.Handle(error, exception, errorResults, arguments);
                return;
            }

            if (!_namedHandlers.ContainsKey(handler))
            {
                throw new ArgumentException("Unknown exception handler : " + handler);
            }

            IErrorManager exceptionManager = _namedHandlers[handler];

            exceptionManager.Handle(error, exception, errorResults, arguments);
        }
 /// <summary>
 /// Handles the specified error.
 /// </summary>
 /// <param name="error">The error.</param>
 /// <param name="exception">The exception.</param>
 /// <param name="errorResults">The error results.</param>
 /// <param name="arguments">The arguments.</param>
 public static void Handle(object error, Exception exception, string handler, IStatusResults errorResults, object[] arguments)
 {
     InternalHandle(error, exception, handler, errorResults, arguments);
 }
 /// <summary>
 /// Handles the specified error.
 /// </summary>
 /// <param name="error">The error.</param>
 /// <param name="exception">The exception.</param>
 /// <param name="errorResults">The error results.</param>
 /// <param name="arguments">The arguments.</param>
 public static void Handle(object error, Exception exception, IStatusResults errorResults)
 {
     InternalHandle(error, exception, null, errorResults, null);
 }
Esempio n. 17
0
 /// <summary>
 /// Create the model action context using existing errors or message collection.
 /// If empty, a default instance will be created.
 /// </summary>
 /// <param name="errors">Error collection</param>
 /// <param name="messages">Message collection</param>
 public ActionContext(IValidationResults errors, IStatusResults messages) : base(errors, messages)
 {
 }
Esempio n. 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BoolMessageItem&lt;T&gt;"/> class.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <param name="success">if set to <c>true</c> [success].</param>
 /// <param name="message">The message.</param>
 public BoolResult(T item, bool success, string message, IValidationResults errors, IStatusResults messages)
     : base(item, success, message)
 {
     _errors   = errors;
     _messages = messages;
 }
        /// <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);
            }
        }
 /// <summary>
 /// Handles the specified error.
 /// </summary>
 /// <param name="error">The error.</param>
 /// <param name="exception">The exception.</param>
 /// <param name="errorResults">The error results.</param>
 public virtual void Handle(object error, Exception exception, IStatusResults errorResults)
 {
     Handle(error, exception, errorResults, null);
 }
 /// <summary>
 /// Initialize the action context.
 /// </summary>
 /// <param name="item"></param>
 /// <param name="errorList"></param>
 /// <param name="messages"></param>
 public ActionContext(T item, IValidationResults errors, IStatusResults messages)
 {
     _item     = item;
     _errors   = errors;
     _messages = messages;
 }
 /// <summary>
 /// Handles the specified error.
 /// </summary>
 /// <param name="error">The error.</param>
 /// <param name="exception">The exception.</param>
 /// <param name="errorResults">The error results.</param>
 /// <param name="arguments">The arguments.</param>
 public virtual void Handle(object error, Exception exception, IStatusResults errorResults, object[] arguments)
 {
     InternalHandle(error, exception, errorResults, arguments);
 }