Exemple #1
0
        // Methods
        public override bool Evaluate(Activity activity, IServiceProvider provider)
        {
            Activity        parent      = activity;
            RuleDefinitions definitions = null;

            while (parent != null)
            {
                definitions = (RuleDefinitions)parent.GetValue(RuleDefinitions.RuleDefinitionsProperty);

                if (definitions != null)
                {
                    break;
                }

                parent = parent.Parent;
            }

            if (definitions == null)
            {
                Console.WriteLine("No definition");
                return(false);
            }

            //Console.WriteLine ("Definition {0} at {1}", definitions, parent);
            RuleValidation validation = new RuleValidation(activity.GetType(), null);
            RuleExecution  execution  = new RuleExecution(validation, parent);
            RuleCondition  condition  = definitions.Conditions [ConditionName];

            //Console.WriteLine ("Condition {0}", condition);
            return(condition.Evaluate(execution));
        }
Exemple #2
0
        public override bool Evaluate(Activity activity, IServiceProvider provider)
        {
            if (activity == null)
            {
                throw new ArgumentNullException("activity");
            }
            if (string.IsNullOrEmpty(this._condition))
            {
                throw new InvalidOperationException(SR.GetString(SR.Error_MissingConditionName, activity.Name));
            }

            RuleDefinitions defs = null;

            if (string.IsNullOrEmpty(this.declaringActivityId))
            {
                // No Runtime Initialization.
                CompositeActivity declaringActivity = null;
                defs = RuleConditionReference.GetRuleDefinitions(activity, out declaringActivity);
            }
            else
            {
                // Runtime Initialized.
                defs = (RuleDefinitions)activity.GetActivityByName(declaringActivityId).GetValue(RuleDefinitions.RuleDefinitionsProperty);
            }

            if ((defs == null) || (defs.Conditions == null))
            {
                throw new InvalidOperationException(SR.GetString(SR.Error_MissingRuleConditions));
            }

            RuleCondition conditionDefinitionToEvaluate = defs.Conditions[this._condition];

            if (conditionDefinitionToEvaluate != null)
            {
                Activity       contextActivity = System.Workflow.Activities.Common.Helpers.GetEnclosingActivity(activity);
                RuleValidation validation      = new RuleValidation(contextActivity);
                if (!conditionDefinitionToEvaluate.Validate(validation))
                {
                    string message = string.Format(CultureInfo.CurrentCulture, Messages.ConditionValidationFailed, this._condition);
                    throw new InvalidOperationException(message);
                }

                RuleExecution context = new RuleExecution(validation, contextActivity, provider as ActivityExecutionContext);
                return(conditionDefinitionToEvaluate.Evaluate(context));
            }
            else
            {
                // no condition, so defaults to true
                return(true);
            }
        }
Exemple #3
0
        public override bool Evaluate(Activity activity, IServiceProvider provider)
        {
            if (activity == null)
            {
                throw new ArgumentNullException("activity");
            }
            if (string.IsNullOrEmpty(this._condition))
            {
                throw new InvalidOperationException(SR.GetString("Error_MissingConditionName", new object[] { activity.Name }));
            }
            RuleDefinitions ruleDefinitions = null;

            if (string.IsNullOrEmpty(this.declaringActivityId))
            {
                CompositeActivity declaringActivity = null;
                ruleDefinitions = GetRuleDefinitions(activity, out declaringActivity);
            }
            else
            {
                ruleDefinitions = (RuleDefinitions)activity.GetActivityByName(this.declaringActivityId).GetValue(RuleDefinitions.RuleDefinitionsProperty);
            }
            if ((ruleDefinitions == null) || (ruleDefinitions.Conditions == null))
            {
                throw new InvalidOperationException(SR.GetString("Error_MissingRuleConditions"));
            }
            RuleCondition condition = ruleDefinitions.Conditions[this._condition];

            if (condition == null)
            {
                return(true);
            }
            Activity       enclosingActivity = Helpers.GetEnclosingActivity(activity);
            RuleValidation validation        = new RuleValidation(enclosingActivity);

            if (!condition.Validate(validation))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ConditionValidationFailed, new object[] { this._condition }));
            }
            RuleExecution execution = new RuleExecution(validation, enclosingActivity, provider as ActivityExecutionContext);

            return(condition.Evaluate(execution));
        }