Ejemplo n.º 1
0
        /// <summary>
        /// Executes the inner rule from the outer rules context.
        /// Creates a chained context and if CanRunRule will execute the inner rule.
        /// </summary>
        /// <param name="innerRule">The inner rule.</param>
        public void ExecuteRule(IBusinessRule innerRule)
        {
            var chainedContext = GetChainedContext(innerRule);

            if (BusinessRules.CanRunRule(innerRule, chainedContext.ExecuteContext))
            {
                innerRule.Execute(chainedContext);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes the inner rule from the outer rules context.
        /// Creates a chained context and if CanRunRule will execute the inner rule.
        /// </summary>
        /// <param name="innerRule">The inner rule.</param>
        public void ExecuteRule(IBusinessRuleBase innerRule)
        {
            var chainedContext = GetChainedContext(innerRule);

            if (BusinessRules.CanRunRule(ApplicationContext, innerRule, chainedContext.ExecuteContext))
            {
                if (innerRule is IBusinessRule syncRule)
                {
                    syncRule.Execute(chainedContext);
                }
                else if (innerRule is IBusinessRuleAsync asyncRule)
                {
                    asyncRule.ExecuteAsync(chainedContext).ContinueWith((t) => { chainedContext.Complete(); });
                }
                else
                {
                    throw new ArgumentOutOfRangeException(innerRule.GetType().FullName);
                }
            }
        }