Beispiel #1
0
        /// <summary>
        /// Gets the interceptor options.
        /// </summary>
        /// <typeparam name="TOwner">The type of the owner.</typeparam>
        /// <param name="frameworkCommandInfo">The framework command info.</param>
        /// <returns>Options object to add to Command.</returns>
        public object GetInterceptorOptions <TOwner> (IFrameworkCommandInfo frameworkCommandInfo)
        {
            IRuleSelector ruleSelector;

            if (frameworkCommandInfo is IRuleCommandInfo)
            {
                ruleSelector = (frameworkCommandInfo as IRuleCommandInfo).RuleSelector;
            }
            else
            {
                ruleSelector =
                    new SelectAllRulesInRuleSetSelector(
                        frameworkCommandInfo.Name.EndsWith("RuleSet") ? frameworkCommandInfo.Name : frameworkCommandInfo.Name + "RuleSet");
            }

            IRuleEngine <TOwner> ruleEngine = null;
            var triedCreateRuleEngine       = false;

            var context = new RuleEngineContext <TOwner> (( TOwner )frameworkCommandInfo.Owner, ruleSelector);

            var ruleExecutor = new RuleExecutor
            {
                ExecuteRules = o =>
                {
                    if (!triedCreateRuleEngine)
                    {
                        triedCreateRuleEngine = true;
                        ruleEngine            = _ruleEngineFactory.CreateRuleEngine <TOwner>();
                    }
                    if (ruleEngine != null)
                    {
                        context.Refresh();
                        if (o != null)
                        {
                            context.WorkingMemory.AddContextObject(o);
                            if (context.RuleSelector is ITakeParameter)
                            {
                                (context.RuleSelector as ITakeParameter).Parameter = o;
                            }
                        }
                        return(ruleEngine.ExecuteRules(context));
                    }
                    return(new RuleExecutionResult(Enumerable.Empty <RuleViolation> ()));
                }
            };

            return(ruleExecutor);
        }
Beispiel #2
0
        /// <summary>
        /// Exectutes rules that are part of a Rule Set in the Rule Collection of the Rule Engine.
        /// </summary>
        /// <param name="subject">Subject the rules are run against.</param>
        /// <param name="ruleSetName">The Rule Set name of the rules to execute..</param>
        /// <returns>A <see cref="RuleExecutionResult"/> containing the results of the execution pass.</returns>
        public RuleExecutionResult ExecuteRuleSet(TSubject subject, string ruleSetName)
        {
            var ruleSetSelector = new SelectAllRulesInRuleSetSelector(ruleSetName);

            return(ExecuteSelectedRules(subject, ruleSetSelector));
        }