Beispiel #1
0
        public ErrorValidationEvent Validate(ValidationRequest request, FlowErrorTrace parent)
        {
            ObjectBinder binder = request.Binder;
            // todo: check IComparable casting is possible
            IComparable comparableComaredObject = null;
            IComparable comparableToCheck       = null;

            // bind 1st object
            try {
                comparableToCheck = binder.Bind(Property);
            }catch (Exception e)
            {
                return(new UnableToBindEvent(parent, e, this, Property, 1));
            }

            if (ComparedObject.GetType().Equals(typeof(PropertySelection)))
            {
                // bind 2nd object
                PropertySelection selected = (PropertySelection)ComparedObject;
                try
                {
                    comparableComaredObject = binder.Bind(selected);
                }
                catch (Exception e)
                {
                    return(new UnableToBindEvent(parent, e, this, selected, 2));
                }
            }
            else
            {
                // set 2nd object
                try
                {
                    comparableComaredObject = (IComparable)ComparedObject;
                }
                catch (Exception e)
                {
                    return(new RuleRuntimeErrorEvent(parent, e, this, comparableToCheck, comparableComaredObject));
                }
            }

            // evaluate
            try
            {
                if (Operator.Evaluate(comparableToCheck, comparableComaredObject) == false)
                {
                    return(new UnsuccessfulRuleCompletionEvent(parent, this, comparableToCheck, comparableComaredObject));
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                return(new RuleRuntimeErrorEvent(parent, e, this, comparableToCheck, comparableComaredObject));
            }
        }
Beispiel #2
0
        public FlowErrorTrace Validate(ValidationRequest request)
        {
            FlowErrorTrace flowErrorTrace = new FlowErrorTrace(this);

            foreach (ValidationFlow flow in flows)
            {
                FlowErrorTrace lastFlowTrace = flow.Validate(request);
                flowErrorTrace.AddFlowErrorTrace(lastFlowTrace);
            }
            foreach (ValidationRule rule in rules)
            {
                ErrorValidationEvent validationEvent = rule.Validate(request, flowErrorTrace);
                flowErrorTrace.AddErrorValidationEvent(validationEvent);
            }

            if (flowErrorTrace.containsMajorValidationErrors())
            {
                return(flowErrorTrace);
            }
            else
            {
                return(null);
            }
        }