Esempio n. 1
0
        /// <summary>
        /// Determines whether this rule can run the specified context mode.
        /// </summary>
        /// <param name="rule">The rule.</param>
        /// <param name="contextMode">The context mode.</param>
        /// <returns>
        ///     <c>true</c> if this instance [can run rule] the specified context mode; otherwise, <c>false</c>.
        /// </returns>
        internal static bool CanRunRule(IBusinessRuleBase rule, RuleContextModes contextMode)
        {
            // default then just return true
            if (rule.RunMode == RunModes.Default)
            {
                return(true);
            }

            bool canRun = true;

            if ((contextMode & RuleContextModes.AsAffectedPoperty) > 0)
            {
                canRun &= (rule.RunMode & RunModes.DenyAsAffectedProperty) == 0;
            }

            if ((rule.RunMode & RunModes.DenyOnServerSidePortal) > 0)
            {
                canRun &= ApplicationContext.LogicalExecutionLocation != ApplicationContext.LogicalExecutionLocations.Server;
            }

            if ((contextMode & RuleContextModes.CheckRules) > 0)
            {
                canRun &= (rule.RunMode & RunModes.DenyCheckRules) == 0;
            }

            return(canRun);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the name of the entity business rule by.
        /// </summary>
        /// <param name="entityName">Name of the entity.</param>
        /// <param name="additionalDataKey">The additional data key.</param>
        /// <returns></returns>
        public IBusinessRuleBase GetEntityBusinessRuleByName(string entityName, string additionalDataKey)
        {
            ApplicationSetting appSetting = FWUtils.ConfigUtils.GetAppSettings();
            IBusinessRuleBase  obj        = (IBusinessRuleBase)FWUtils.ReflectionUtils.CreateInstance(appSetting.Project.NamespacePrefix + ".BusinessRule", entityName + "BL", appSetting.Project.NamespacePrefix + ".BusinessRules", new object[] { additionalDataKey });

            obj.Initialize(entityName, additionalDataKey);
            return(obj);
        }
Esempio n. 3
0
 private async Task ExecuteRule(IBusinessRuleBase rule, RuleContext context)
 {
     if (rule is IBusinessRule sr)
     {
         sr.Execute(context);
     }
     else if (rule is IBusinessRuleAsync ar)
     {
         await ar.ExecuteAsync(context);
     }
 }
Esempio n. 4
0
        public void GetEntityBusinessRuleByNameTest()
        {
            ProjectEntityFactory target         = new ProjectEntityFactory();
            string            entityName        = vTestCaseTester.EntityName;
            string            additionalDataKey = "";
            IBusinessRuleBase expected          = null;
            IBusinessRuleBase actual;

            actual = target.GetEntityBusinessRuleByName(entityName, additionalDataKey);
            Assert.AreNotEqual(expected, actual);
        }
Esempio n. 5
0
 /// <summary>
 /// Creates a RuleContext instance for testing.
 /// </summary>
 /// <param name="applicationContext">Current ApplicationContext</param>
 /// <param name="completeHandler">Callback for async rule.</param>
 /// <param name="rule">Reference to the rule object.</param>
 /// <param name="target">Target business object.</param>
 /// <param name="inputPropertyValues">Input property values used by the rule.</param>
 public RuleContext(ApplicationContext applicationContext, Action <IRuleContext> completeHandler, IBusinessRuleBase rule, object target, Dictionary <Csla.Core.IPropertyInfo, object> inputPropertyValues)
     : this(applicationContext, completeHandler)
 {
     Rule = rule;
     if (rule.PrimaryProperty != null)
     {
         OriginPropertyName = rule.PrimaryProperty.Name;
     }
     Target = target;
     InputPropertyValues = inputPropertyValues;
     ExecuteContext      = RuleContextModes.PropertyChanged;
 }
Esempio n. 6
0
        /// <summary>
        /// Checks the detail entity rules.
        /// </summary>
        /// <param name="detailList">The list.</param>
        /// <param name="fnName">Name of the function.</param>
        /// <param name="errors">The errors.</param>
        private void CheckDetailEntityRules(List <DetailObjectInfo> detailList, BusinessRuleErrorList errors)
        {
            if (detailList == null)
            {
                return;
            }

            foreach (var detailInfo in detailList)
            {
                string            entityName = detailInfo.EntityName;
                IBusinessRuleBase biz        = EntityFactory.GetEntityBusinessRuleByName(entityName, detailInfo.AdditionalDataKey);
                biz.CheckRules(detailInfo.EntitySet, detailInfo.FnName, errors);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Gets a new RuleContext object for a chained rule.
        /// </summary>
        /// <param name="rule">Chained rule that will use
        /// this new context.</param>
        /// <remarks>
        /// The properties from the existing RuleContext will be
        /// used to create the new context, with the exception
        /// of the Rule property which is set using the supplied
        /// IBusinessRule value.
        /// </remarks>
        public IRuleContext GetChainedContext(IBusinessRuleBase rule)
        {
            var result = new RuleContext(ApplicationContext, _completeHandler, _outputPropertyValues, _dirtyProperties, ExecuteContext);

            result.Rule = rule;
            result.OriginPropertyName  = OriginPropertyName;
            result.InputPropertyValues = InputPropertyValues;
            result.Results             = Results;

            if (!rule.IsAsync || rule.ProvideTargetWhenAsync)
            {
                result.Target = Target;
            }
            return(result);
        }
Esempio n. 8
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);
                }
            }
        }
Esempio n. 9
0
 public BusinessRuleValidationException(IBusinessRuleBase rule) : base(rule.Message)
 {
     Rule = rule;
 }
Esempio n. 10
0
        /// <summary>
        /// Associates a business rule with the business object.
        /// </summary>
        /// <param name="rule">Rule object.</param>
        /// <param name="ruleSet">Rule set name.</param>
        public void AddRule(IBusinessRuleBase rule, string ruleSet)
        {
            var typeRules = BusinessRuleManager.GetRulesForType(_target.GetType(), ruleSet);

            typeRules.Rules.Add(rule);
        }
Esempio n. 11
0
 /// <summary>
 /// Associates a business rule with the business object.
 /// </summary>
 /// <param name="rule">Rule object.</param>
 public void AddRule(IBusinessRuleBase rule)
 {
     TypeRules.Rules.Add(rule);
 }
Esempio n. 12
0
 /// <summary>
 /// Creates an instance of the object.
 /// </summary>
 /// <param name="rule">Rule object.</param>
 /// <param name="property">Property to which rule applies.</param>
 public RuleUri(IBusinessRuleBase rule, Csla.Core.IPropertyInfo property)
     : this(GetTypeName(rule), ((property == null) ? "(object)" : property.Name))
     //: this(rule.GetType().FullName, ((property == null) ? "null" : property.Name))
 {
 }
Esempio n. 13
0
        private static string GetTypeName(IBusinessRuleBase rule)
        {
            var type = rule.GetType();

            return(GetTypeName(type));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BusinessRulesCheckUtils"/> class.
 /// </summary>
 /// <param name="business">The business.</param>
 public BusinessRulesCheckUtils(IBusinessRuleBase business)
 {
     Check.Require(business != null);
     Business = business;
 }