示例#1
0
        public bool IsRuleValid(long idActivityDefinition, object item, RuleConstants constants)
        {
            IList <RuleDefinition> rules   = _ruleStorePlugin.FindRulesByItemId(idActivityDefinition);
            RuleContext            context = new RuleContext(item, constants);

            return(_ruleValidatorPlugin.IsRuleValid(idActivityDefinition, rules, context));
        }
示例#2
0
        public RuleContext(object obj, RuleConstants constants)
        {
            context = new Dictionary <string, string>();

            BeanDefinition definition = BeanDescriptor.GetDefinition(obj.GetType());
            BeanPropertyDescriptorCollection properties = definition.Properties;

            foreach (BeanPropertyDescriptor bean in properties)
            {
                context[bean.PropertyName] = bean.GetValue(obj).ToString();
            }

            if (constants != null)
            {
                foreach (KeyValuePair <string, string> keyValue in constants.GetValues())
                {
                    context.Add(keyValue);
                }
            }
        }
示例#3
0
        public RuleContext(object obj, RuleConstants constants)
        {
            context = new Dictionary <string, object>();

            PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(obj);

            foreach (PropertyDescriptor propDesc in pdc)
            {
                object val = propDesc.GetValue(obj);

                if (val != null)
                {
                    object value;
                    if (val is IList)
                    {
                        IList valList = (IList)val;
                        value = valList.Cast <object>().Select(v => v.ToString()).ToList();
                    }
                    else if (val is decimal)
                    {
                        value = val;
                    }
                    else
                    {
                        value = val.ToString();
                    }
                    context[propDesc.Name] = value;
                }
            }

            if (constants != null)
            {
                foreach (KeyValuePair <string, string> keyValue in constants.GetValues())
                {
                    context.Add(keyValue.Key, keyValue.Value);
                }
            }
        }
 public void UpdateConstants(long key, RuleConstants ruleConstants)
 {
     Debug.Assert(ruleConstants != null);
     //---
     inMemoryRuleStore[key] = ruleConstants;
 }
示例#5
0
 public void AddConstants(int key, RuleConstants ruleConstants)
 {
     _ruleConstantsStorePlugin.AddConstants(key, ruleConstants);
 }
示例#6
0
 public void AddConstants(int key, RuleConstants ruleConstants)
 {
     Debug.Assert(ruleConstants != null);
     //---
     inMemoryRuleStore[key] = ruleConstants;
 }
示例#7
0
        public IList <AccountUser> SelectAccounts(long idActivityDefinition, object item, RuleConstants constants)
        {
            IList <SelectorDefinition> selectors = _ruleStorePlugin.FindSelectorsByItemId(idActivityDefinition);
            RuleContext context = new RuleContext(item, constants);

            return(_ruleSelectorPlugin.SelectAccounts(idActivityDefinition, selectors, context));
        }