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)); } }
private static void StringCriteriaTreatment(StringCriteria criteria, List <Expression> expressionList, Type propertyType, ParameterExpression entityParameter, PropertyInfo entityProperty) { if (!propertyType.Equals(typeof(string))) { return; } if (criteria.Equal != null) { expressionList.Add(AddEqualStringExpression(entityParameter, entityProperty, criteria.Equal, false)); } if (criteria.EqualList != null) { foreach (string value in criteria.EqualList) { expressionList.Add(AddEqualStringExpression(entityParameter, entityProperty, value, criteria.IgnoreCase)); } } if (criteria.NotEqual != null) { expressionList.Add(AddNotEqualStringExpression(entityParameter, entityProperty, criteria.NotEqual, false)); } if (criteria.NotEqualList != null) { foreach (string value in criteria.NotEqualList) { expressionList.Add(AddNotEqualStringExpression(entityParameter, entityProperty, value, criteria.IgnoreCase)); } } if (criteria.StartsWithList != null) { foreach (string value in criteria.StartsWithList) { if (value != null) { expressionList.Add(AddStartsWithStringExpression(entityParameter, entityProperty, value, criteria.IgnoreCase)); } } } if (criteria.EndsWithList != null) { foreach (string value in criteria.NotEqualList) { if (value != null) { expressionList.Add(AddEndsWithStringExpression(entityParameter, entityProperty, value, criteria.IgnoreCase)); } } } if (criteria.ContainsList != null) { foreach (string value in criteria.NotEqualList) { if (value != null) { expressionList.Add(AddContainsStringExpression(entityParameter, entityProperty, value, criteria.IgnoreCase)); } } } }
public override void Apply(StringCriteria criteria) { if (DateStart != DateTime.MinValue) { criteria.Add(string.Format("Created >= '{0}'", DateStart)); } base.Apply(criteria); }
public void SerializeCriteriaSuccess() { UnitTestContext context = GetContext(); var criteria = new StringCriteria { Value = "success" }; var buffer = MobileFormatter.Serialize(criteria); var actual = (StringCriteria)MobileFormatter.Deserialize(buffer); context.Assert.AreEqual(criteria.Value, actual.Value); context.Assert.Success(); context.Complete(); }
public void Initialize() { SimilarRules = null; AndChecked = true; NewRule = null; if (Description != null) { Description.PropertyChanged -= OnCriteriaValuePropertyChanged; } if (Reference1 != null) { Reference1.PropertyChanged -= OnCriteriaValuePropertyChanged; } if (Reference2 != null) { Reference2.PropertyChanged -= OnCriteriaValuePropertyChanged; } if (Reference3 != null) { Reference3.PropertyChanged -= OnCriteriaValuePropertyChanged; } if (Amount != null) { Amount.PropertyChanged -= OnCriteriaValuePropertyChanged; } if (TransactionType != null) { TransactionType.PropertyChanged -= OnCriteriaValuePropertyChanged; } Description = new StringCriteria { Applicable = true }; Description.PropertyChanged += OnCriteriaValuePropertyChanged; Reference1 = new StringCriteria(); Reference1.PropertyChanged += OnCriteriaValuePropertyChanged; Reference2 = new StringCriteria(); Reference2.PropertyChanged += OnCriteriaValuePropertyChanged; Reference3 = new StringCriteria(); Reference3.PropertyChanged += OnCriteriaValuePropertyChanged; Amount = new DecimalCriteria(); Amount.PropertyChanged += OnCriteriaValuePropertyChanged; TransactionType = new StringCriteria(); TransactionType.PropertyChanged += OnCriteriaValuePropertyChanged; }
public void ShouldFilterIgnoreCaseCorrectly() { var table = new List <Person>(); table.Add(new Person { Name = "Truman" }); table.Add(new Person { Name = "Leat" }); var stringCriteria = new StringCriteria { StartsWith = "t" }; var result = table.AsQueryable().Filter(x => x.Name, stringCriteria); result.Count().Should().Be(1); result.First().Name.Should().Be("Truman"); }
public void ShouldFilterContainsIgnoreCaseCorrectly() { var table = new List <Person>(); table.Add(new Person { Name = "Scott" }); table.Add(new Person { Name = "Leat" }); var stringCriteria = new StringCriteria { Contains = "A" }; var result = table.AsQueryable().Filter(x => x.Name, stringCriteria); result.Count().Should().Be(1); result.First().Name.Should().Be("Leat"); }
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); }
public override void Apply(StringCriteria criteria) { if (!string.IsNullOrEmpty(Query)) { criteria.AddJoin(string.Format("INNER JOIN FREETEXTTABLE(Post, (Title, Body), '{0}') AS KEY_TBL ON Post.Post_Id = KEY_TBL.[KEY]", Renderer.SqlEncode(Query))); } if (TopicId != 0) { criteria.Add(string.Format("EXISTS (SELECT * FROM PostTopic WHERE PostTopic.Post_Id = Post.Post_Id AND PostTopic.Topic_Id = {0})", TopicId)); } if (DateStart != DateTime.MinValue) { criteria.Add(string.Format("Created >= '{0}'", DateStart)); } if (DateEnd != DateTime.MaxValue) { criteria.Add(string.Format("Created <= '{0}'", DateEnd)); } if (PublishedOnly) { criteria.Add("Publish = 1"); } if (DisplayedOnly) { criteria.Add("Display = 1"); } if (string.IsNullOrEmpty(Query)) { criteria.AddOrder("Sticky", WebServiceQuerySortDirection.Descending); } base.Apply(criteria); }
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; }
protected virtual void AddCriteria(IEnumerable <StringCriterion> stringCriteria) { StringCriteria.AddRange(stringCriteria); }
protected virtual void AddCriterion(StringCriterion stringCriterion) { StringCriteria.Add(stringCriterion); }