public bool IsRuleMatch(ParsedRule rule, BankTransaction bankTransaction) { string columnValue = null; if (rule.IsColumnInExtensions) { if (bankTransaction.Extensions != null) { var extensions = JToken.Parse(bankTransaction.Extensions); var column = extensions[rule.Column]; if (column != null) { columnValue = column.Value <string>(); } } } else { columnValue = GetStaticColumnValue(rule.Column, bankTransaction); } if (columnValue != null) { if (rule.RuleType == RuleType.Contains) { if (columnValue.ToLower().Contains(rule.Value.ToLower())) { logger.LogInformation("Found rule for event {0} (Order: {1})", bankTransaction.Title, bankTransaction.Order); return(true); } } } return(false); }
public ParsedRule Parse(RuleViewModel rule) { var splittedString = rule.RuleDefinition.Split(" ", StringSplitOptions.RemoveEmptyEntries); if (splittedString.Length < 3) { logger.LogWarning($"Invalid rule {rule.RuleDefinition}"); return(null); } var parsedRule = new ParsedRule { Id = rule.Id, BankTransactionTypeId = rule.BankTransactionTypeId, Column = splittedString[0].Replace("Extensions.", "").Trim(), IsColumnInExtensions = splittedString[0].StartsWith("Extensions."), RuleType = Enum.Parse <RuleType>(splittedString[1].Trim()), Value = string.Join(" ", splittedString.Skip(2)), GroupName = rule.GroupName, RuleName = rule.RuleName }; return(parsedRule); }