예제 #1
0
        private RuleDefinition GetRuleDefinition(RuleDto ruleDto)
        {
            var tokens         = _lexer.Lex(ruleDto.RuleExpression).ToList();
            var ruleDefinition = _parser.Parse(tokens);

            ruleDefinition.Id = ruleDto.Id;

            return(ruleDefinition);
        }
예제 #2
0
        public void DeleteRule(RuleDto ruleDto)
        {
            if (ruleDto == null)
            {
                throw new ArgumentNullException(nameof(ruleDto));
            }

            _ruleStore.DeleteRule(ruleDto);
        }
예제 #3
0
        public Rule <TTarget, TComparison> UpdateRule <TTarget, TComparison>(RuleDto ruleDto)
        {
            if (ruleDto == null)
            {
                throw new ArgumentNullException(nameof(ruleDto));
            }

            var updatedRule = _ruleStore.UpdateRule <TTarget, TComparison>(ruleDto);

            return(GetRule <TTarget, TComparison>(updatedRule));
        }
예제 #4
0
        public void DeleteRule(RuleDto ruleDto)
        {
            if (ruleDto == null)
            {
                throw new ArgumentNullException(nameof(ruleDto));
            }

            var toDelete = ruleDto.Clone();

            _ruleRecords.Remove(toDelete.Id);
        }
예제 #5
0
        private Rule <TTarget, TComparison> GetRule <TTarget, TComparison>(RuleDto ruleDto)
        {
            var ruleDefinition = GetRuleDefinition(ruleDto);

            return(new Rule <TTarget, TComparison>
            {
                Id = ruleDto.Id,
                Name = ruleDto.Name,
                Expression = ruleDto.RuleExpression,
                Validate = _interpreter.Interpret <TTarget, TComparison>(ruleDefinition)
            });
        }
예제 #6
0
        public RuleDto UpdateRule <TTarget, TComparison>(RuleDto ruleDto)
        {
            if (ruleDto == null)
            {
                throw new ArgumentNullException(nameof(ruleDto));
            }

            var toUpdate = ruleDto.Clone();

            if (ruleDto.Id == null || !_ruleRecords.ContainsKey(toUpdate.Id))
            {
                return(AddRule <TTarget, TComparison>(toUpdate));
            }

            DeleteRule(toUpdate);
            return(AddRule <TTarget, TComparison>(toUpdate));
        }
예제 #7
0
        public RuleDto AddRule <TTarget, TComparison>(RuleDto ruleDto)
        {
            if (ruleDto == null)
            {
                throw new ArgumentNullException(nameof(ruleDto));
            }

            var toAdd = ruleDto.Clone();

            if (string.IsNullOrWhiteSpace(ruleDto.Id))
            {
                toAdd.Id = Guid.NewGuid().ToString();
            }

            _ruleRecords.Add(toAdd.Id, toAdd);

            return(toAdd);
        }