Beispiel #1
0
        /// <summary>
        /// Compiles a collection of rules into a session factory.
        /// </summary>
        /// <param name="ruleDefinitions">Rules to compile.</param>
        /// <param name="cancellationToken">Enables cooperative cancellation of the rules compilation.</param>
        /// <returns>Session factory.</returns>
        /// <exception cref="RuleCompilationException">Any fatal error during rules compilation.</exception>
        /// <seealso cref="IRuleRepository"/>
        public ISessionFactory Compile(IEnumerable <IRuleDefinition> ruleDefinitions, CancellationToken cancellationToken)
        {
            IReteBuilder reteBuilder   = new ReteBuilder(_aggregatorRegistry);
            var          compiledRules = new List <ICompiledRule>();

            foreach (var ruleDefinition in ruleDefinitions)
            {
                try
                {
                    var compiledRule = CompileRule(reteBuilder, ruleDefinition);
                    compiledRules.AddRange(compiledRule);
                }
                catch (Exception e)
                {
                    throw new RuleCompilationException("Failed to compile rule", ruleDefinition.Name, e);
                }

                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }
            }

            INetwork network = reteBuilder.Build();
            var      factory = new SessionFactory(network, compiledRules);

            return(factory);
        }
Beispiel #2
0
        /// <summary>
        /// Compiles a collection of rules into a session factory.
        /// </summary>
        /// <param name="ruleDefinitions">Rules to compile.</param>
        /// <returns>Session factory.</returns>
        /// <exception cref="RuleCompilationException">Any fatal error during rules compilation.</exception>
        /// <seealso cref="IRuleRepository"/>
        public ISessionFactory Compile(IEnumerable<IRuleDefinition> ruleDefinitions)
        {
            var reteBuilder = new ReteBuilder();
            foreach (var ruleDefinition in ruleDefinitions)
            {
                try
                {
                    CompileRule(reteBuilder, ruleDefinition);
                }
                catch (Exception e)
                {
                    throw new RuleCompilationException("Failed to compile rule", ruleDefinition.Name, e);
                }
            }

            INetwork network = reteBuilder.Build();
            var factory = new SessionFactory(network);
            return factory;
        }
Beispiel #3
0
        /// <summary>
        /// Compiles a collection of rules into a session factory.
        /// </summary>
        /// <param name="ruleDefinitions">Rules to compile.</param>
        /// <returns>Session factory.</returns>
        /// <exception cref="RuleCompilationException">Any fatal error during rules compilation.</exception>
        /// <seealso cref="IRuleRepository"/>
        public ISessionFactory Compile(IEnumerable <IRuleDefinition> ruleDefinitions)
        {
            IReteBuilder reteBuilder = new ReteBuilder();

            foreach (var ruleDefinition in ruleDefinitions)
            {
                try
                {
                    CompileRule(reteBuilder, ruleDefinition);
                }
                catch (Exception e)
                {
                    throw new RuleCompilationException("Failed to compile rule", ruleDefinition.Name, e);
                }
            }

            INetwork network = reteBuilder.Build();
            var      factory = new SessionFactory(network);

            return(factory);
        }