Beispiel #1
0
        /// <summary>
        /// Add a proceedural rule to this command that considers the specified perform rule. Unlike Perform above,
        /// if the perform rule returns stop, the proceedural rules will also be stopped.
        /// </summary>
        /// <param name="RuleName"></param>
        /// <param name="RuleArguments"></param>
        /// <returns>This command</returns>
        public CommandEntry AbideBy(String RuleName, params String[] RuleArguments)
        {
            GeneratedManual.AppendLine("Consider the perform rulebook '" + RuleName + "' with arguments " + String.Join(", ", RuleArguments) + " and abide by the result.");

            var rule = new Rule <PerformResult>
            {
                BodyClause = RuleDelegateWrapper <PerformResult> .MakeWrapper <PossibleMatch, Actor>(
                    (match, actor) =>
                    Core.GlobalRules.ConsiderPerformRule(RuleName, RuleArguments.Select(a => match.ValueOrDefault(a)).ToArray())
                    ),
                DescriptiveName = "Procedural rule to abide by " + RuleName
            };

            ProceduralRules.AddRule(rule);
            return(this);
        }
Beispiel #2
0
        /// <summary>
        /// Add a new procedural rule to this command that invokes a check rule. If the checkrule fails,
        /// processing of the proceedural rules is stopped.
        /// </summary>
        /// <param name="RuleName"></param>
        /// <param name="RuleArguments"></param>
        /// <returns>This command</returns>
        public CommandEntry Check(String RuleName, params String[] RuleArguments)
        {
            GeneratedManual.AppendLine("Consider the check rulebook '" + RuleName + "' with arguments " + String.Join(", ", RuleArguments));

            var rule = new Rule <PerformResult>
            {
                BodyClause = RuleDelegateWrapper <PerformResult> .MakeWrapper <PossibleMatch, Actor>(
                    (match, actor) =>
                {
                    if (Core.GlobalRules.ConsiderCheckRule(RuleName, RuleArguments.Select(a => match.ValueOrDefault(a)).ToArray()) == CheckResult.Allow)
                    {
                        return(PerformResult.Continue);
                    }
                    return(PerformResult.Stop);
                }),
                DescriptiveName = "Procedural rule to check " + RuleName
            };

            ProceduralRules.AddRule(rule);
            return(this);
        }