private static void IsSimilarRulePreconditions(SimilarMatchedRule rule, DecimalCriteria amount, StringCriteria description, StringCriteria[] references, StringCriteria transactionType) { if (rule == null) { throw new ArgumentNullException(nameof(rule)); } if (amount == null) { throw new ArgumentNullException(nameof(amount)); } if (description == null) { throw new ArgumentNullException(nameof(description)); } if (references == null) { throw new ArgumentNullException(nameof(references)); } if (transactionType == null) { throw new ArgumentNullException(nameof(transactionType)); } }
public bool IsRuleSimilar(SimilarMatchedRule rule, DecimalCriteria amount, StringCriteria description, StringCriteria[] references, StringCriteria transactionTypeName) { IsSimilarRulePreconditions(rule, amount, description, references, transactionTypeName); var matchedByResults = new bool[6]; matchedByResults[0] = amount.IsEqualButNotBlank(rule.Amount); matchedByResults[1] = description.IsEqualButNotBlank(rule.Description); matchedByResults[2] = references[0].IsEqualButNotBlank(rule.Reference1); matchedByResults[3] = references[1].IsEqualButNotBlank(rule.Reference2); matchedByResults[4] = references[2].IsEqualButNotBlank(rule.Reference3); matchedByResults[5] = transactionTypeName.IsEqualButNotBlank(rule.TransactionType); var match = matchedByResults[0]; match |= matchedByResults[1]; match |= matchedByResults[2]; match |= matchedByResults[3]; match |= matchedByResults[4]; match |= matchedByResults[5]; if (match) { this.logger.LogInfo( l => l.Format("Rule Match: {0} Existing Rule:{1} Criteria:{2}", match, rule, description)); rule.AmountMatched = matchedByResults[0] && amount.Applicable; rule.DescriptionMatched = matchedByResults[1] && description.Applicable; rule.Reference1Matched = matchedByResults[2] && references[0].Applicable; rule.Reference2Matched = matchedByResults[3] && references[1].Applicable; rule.Reference3Matched = matchedByResults[4] && references[2].Applicable; rule.TransactionTypeMatched = matchedByResults[5] && transactionTypeName.Applicable; return rule.AmountMatched || rule.DescriptionMatched || rule.Reference1Matched || rule.Reference2Matched || rule.Reference3Matched || rule.TransactionTypeMatched; } return false; }