private RuleDefinition GetRuleDefinition(RuleDto ruleDto) { var tokens = _lexer.Lex(ruleDto.RuleExpression).ToList(); var ruleDefinition = _parser.Parse(tokens); ruleDefinition.Id = ruleDto.Id; return(ruleDefinition); }
public void DeleteRule(RuleDto ruleDto) { if (ruleDto == null) { throw new ArgumentNullException(nameof(ruleDto)); } _ruleStore.DeleteRule(ruleDto); }
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)); }
public void DeleteRule(RuleDto ruleDto) { if (ruleDto == null) { throw new ArgumentNullException(nameof(ruleDto)); } var toDelete = ruleDto.Clone(); _ruleRecords.Remove(toDelete.Id); }
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) }); }
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)); }
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); }