예제 #1
0
        public IList <RuleDefinition> FindRulesByCriteria(RuleCriteria criteria, IList <int> items)
        {
            Debug.Assert(criteria != null);
            Debug.Assert(criteria.ConditionCriteria1 != null);
            //--

            var cmd = GetSqlServerCommand("FindItemsByCriteria.sql");

            cmd.Parameters.AddWithValue(RuleCriteria.Cols.FIELD_1, criteria.ConditionCriteria1.Field);
            cmd.Parameters.AddWithValue(RuleCriteria.Cols.VALUE_1, criteria.ConditionCriteria1.Value);
            cmd.Parameters.AddInParameter(ITEMS_ID, items);

            if (criteria.ConditionCriteria2 != null)
            {
                cmd.Parameters.AddWithValue(RuleCriteria.Cols.FIELD_2, criteria.ConditionCriteria2.Field);
                cmd.Parameters.AddWithValue(RuleCriteria.Cols.VALUE_2, criteria.ConditionCriteria2.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue(RuleCriteria.Cols.FIELD_2, null);
                cmd.Parameters.AddWithValue(RuleCriteria.Cols.VALUE_2, null);
            }

            return(new List <RuleDefinition>(cmd.ReadList <RuleDefinition>()));
        }
예제 #2
0
        public IList <RuleDefinition> FindRulesByCriteria(RuleCriteria criteria, IList <int> items)
        {
            Debug.Assert(criteria != null);
            //---
            IList <RuleDefinition> ret = new List <RuleDefinition>();

            foreach (int itemId in items)
            {
                IList <RuleDefinition> rules = (inMemoryRuleStore.Where(r => r.Value.Id.Equals(itemId)).Select(kp => kp.Value)).ToList();

                foreach (RuleDefinition rule in rules)
                {
                    Dictionary <string, RuleConditionDefinition> conditions = (inMemoryConditionStore.Where(r => r.Value.RudId.Equals(rule.Id)).Select(kp => kp.Value)).ToDictionary(r => r.Field);

                    int match = 0;
                    RuleConditionDefinition currentRule1 = conditions[criteria.ConditionCriteria1.Field];

                    if (currentRule1 != null && currentRule1.Expression.Equals(criteria.ConditionCriteria1.Value))
                    {
                        match++;
                    }

                    if (criteria.ConditionCriteria2 != null)
                    {
                        RuleConditionDefinition currentRule2 = conditions[criteria.ConditionCriteria2.Field];
                        if (currentRule2 != null && currentRule2.Expression.Equals(criteria.ConditionCriteria2.Value))
                        {
                            match++;
                        }
                    }

                    int expectedMatch = criteria.ConditionCriteria2 != null ? 2 : 1;

                    if (match == expectedMatch)
                    {
                        ret.Add(rule);
                        break;
                    }
                }
            }

            return(ret);
        }
예제 #3
0
파일: RuleManager.cs 프로젝트: JabX/kinetix
        public IList <int> FindItemsByCriteria(RuleCriteria criteria, IList <int> items)
        {
            IList <RuleDefinition> rules = _ruleStorePlugin.FindRulesByCriteria(criteria, items);

            return(rules.Select(r => r.ItemId).Cast <int>().Distinct().ToList());
        }