Example #1
0
        public void AddItems(
            ErrorList list)
        {
            if (list != null) {
                try {
                    for (int i = 0; i < list.Count; i++) {
                        Error err = (Error) list[i];

                        this.maxSeverity = err.Type > this.maxSeverity ? err.Type : this.maxSeverity;
                        this.errNumbers.Add(err.Id);
                        this.errFormFields.Add(err.FormField);
                        base.Add(err);
                    }
                } catch (Exception ex) {
                    LogManager.GetCurrentClassLogger().Error(
                        errorMessage => errorMessage("ErrorList: AddItems: "), ex);
                }
            }
        }
        /// <summary>Adds and Error to the Errors Collection.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns> event name for the next transisiton
        /// </returns>
        /// <exception cref="ApplicationException">
        /// </exception>
        public string Execute(
            TransitionContext context)
        {
            string retEvent = Events.Error;
            MvcRequest request = context.Request;

            try {
                        //  if ErrorId not specified on the state, check for request parameter or use state ID
                if (string.IsNullOrEmpty(ErrorId)) {
                    if (!string.IsNullOrEmpty(ErrorIdParamNameIn) && !string.IsNullOrEmpty(request[ErrorIdParamNameIn])) {
                        ErrorId = request[ErrorIdParamNameIn];
                    } else {
                            //  if error id was not set use the current state id.
                        ErrorId = context.CurrentState.Id.ToString();
                    }
                }

                ErrorList errors;

                        //  if the request contains the error list, append to it, else create a new one
                if (request.Items[ErrorsItemNameIn] != null
                        && request.Items[ErrorsItemNameIn] is ErrorList
                        && request.GetItem<ErrorList>(ErrorsItemNameIn) != null) {

                    errors = request.GetItem<ErrorList>(ErrorsItemNameIn);
                } else {
                    errors = new ErrorList(DictionaryManager.GetDictionaryManager().GetDictionary(context.Site));
                }

                Error err = errors.getError(Convert.ToInt64(ErrorId));

                        //  check for parameter replacement placeholders in the message
                        //  placeholders are of the form: {[param_name]}
                MatchCollection parameterMatches = Regex.Matches(err.Message, @"\{\[([\w-]+)\]\}");

                        //  if there are parameter placeholders, replace them with the
                        //  parameter values
                if (parameterMatches.Count > 0) {
                    foreach (Match match in parameterMatches) {
                        err.Message = err.Message.Replace(match.Value, request[match.Groups[1].Value.EvaluatePropertyValue()]);
                    }
                }

                if (Index.HasValue && (Index.Value < errors.Count)) {
                    errors.Insert(Index.Value, err);
                } else {
                    errors.Add(err);
                }

                request.Items[ErrorsItemNameOut] = errors;

                retEvent = Events.Ok;
            } catch (Exception e) {
                LogManager.GetCurrentClassLogger().Error(
                    errorMessage => errorMessage("Error occured in Execution of the Action."), e);
            }

            return retEvent;
        }
        /// <summary>
        /// Executes the action to perform the validation.
        /// </summary>
        /// <param name="context">The <c>TransitionContext</c> in which the action is executing.</param>
        /// <returns>The event resulting from the action's execution.</returns>
        public string Execute(
            TransitionContext context)
        {
            string retEvent = Events.Error;
            MvcRequest request = context.Request;

            try {
                string[] validatorNames = ValidatorName.Split(VALIDATOR_NAME_DELIMITER);

                bool passed = true;
                foreach (string validatorName in validatorNames) {
                            //  get the Validator from the ValidatorManager
                    Model.Rules.Validator validator = ValidatorManager.GetInstance().GetValidator(validatorName);

                    if (validator == null) {
                        throw new MissingMemberException(string.Format(
                                "No validator found for '{0}'.", validatorName));
                    }

                            //  evaluate the validator
                    ValidationResult result = validator.Evaluate(request);

                            //  if the validation failed, build an ErrorList and add
                            //  it to the request for the page
                    if (!result.Passed && (result.Errors != null)) {
                        ErrorList errors;

                                //  if the request contains the error list, append to it, else create a new one
                        if (request.Items[ErrorsItemNameIn] != null &&
                                request.Items[ErrorsItemNameIn] is ErrorList &&
                                request.GetItem<ErrorList>(ErrorsItemNameIn) != null) {

                            errors = request.GetItem<ErrorList>(ErrorsItemNameIn);
                        } else {
                            errors = new ErrorList(DictionaryManager.GetDictionaryManager().GetDictionary(context.Site));
                        }

                        foreach (ValidationError err in result.Errors) {
                            errors.Add(err.ErrorId);
                        }

                                //  add the errors to the request to propagate back to the page
                        request.Items[ErrorsItemNameOut] = errors;
                    }

                    passed = (passed && result.Passed);
                }

                retEvent = passed ? Events.Pass : Events.Fail;
            } catch (Exception ex) {
                LogManager.GetCurrentClassLogger().Error(error => error("Error in Execute."), ex);
            }

            return retEvent;
        }