private static bool TryMatchFieldWithCondition(string fieldName, QueryFilter resultFilter, SearchConditions conditions) { List<SearchCondition> conditionList; if (!conditions.TryGetValue(fieldName, out conditionList)) { return false; } switch (conditionList.Count) { case 2: // checking for the between operator { var lessThanOrEqualCondition = conditionList.SingleOrDefault(c => c.Operator == ScanOperator.LessThanOrEqual); var greaterThanOrEqualCondition = conditionList.SingleOrDefault(c => c.Operator == ScanOperator.GreaterThanOrEqual); if ((lessThanOrEqualCondition == null) || (greaterThanOrEqualCondition == null)) { throw new InvalidOperationException("Multiple conditions for the same field are only supported for the BETWEEN case"); } if ( (lessThanOrEqualCondition.Values.Length != 1) || (greaterThanOrEqualCondition.Values.Length != 1) ) { return false; } resultFilter.AddCondition(fieldName, QueryOperator.Between, greaterThanOrEqualCondition.Values[0], lessThanOrEqualCondition.Values[0]); } break; case 1: { SearchCondition condition = conditionList[0]; // here we need to convert operators, as AWS SDK's default conversion is buggy QueryOperator queryOperator; if ( (!TryConvertScanOperatorToQueryOperator(condition.Operator, out queryOperator)) || (condition.Values.Length != 1) ) { return false; } resultFilter.AddCondition(fieldName, queryOperator, condition.Values[0]); } break; default: throw new InvalidOperationException(string.Format("Too many conditions for field {0}", fieldName)); } // removing the matched condition conditions.Remove(fieldName); return true; }
private static bool TryMatchFieldWithCondition(string fieldName, QueryFilter resultFilter, SearchConditions conditions) { List <SearchCondition> conditionList; if (!conditions.TryGetValue(fieldName, out conditionList)) { return(false); } switch (conditionList.Count) { case 2: // checking for the between operator { var lessThanOrEqualCondition = conditionList.SingleOrDefault(c => c.Operator == ScanOperator.LessThanOrEqual); var greaterThanOrEqualCondition = conditionList.SingleOrDefault(c => c.Operator == ScanOperator.GreaterThanOrEqual); if ((lessThanOrEqualCondition == null) || (greaterThanOrEqualCondition == null)) { throw new InvalidOperationException("Multiple conditions for the same field are only supported for the BETWEEN case"); } if ( (lessThanOrEqualCondition.Values.Length != 1) || (greaterThanOrEqualCondition.Values.Length != 1) ) { return(false); } resultFilter.AddCondition(fieldName, QueryOperator.Between, greaterThanOrEqualCondition.Values[0], lessThanOrEqualCondition.Values[0]); } break; case 1: { SearchCondition condition = conditionList[0]; // here we need to convert operators, as AWS SDK's default conversion is buggy QueryOperator queryOperator; if ( (!TryConvertScanOperatorToQueryOperator(condition.Operator, out queryOperator)) || (condition.Values.Length != 1) ) { return(false); } resultFilter.AddCondition(fieldName, queryOperator, condition.Values[0]); } break; default: throw new InvalidOperationException(string.Format("Too many conditions for field {0}", fieldName)); } // removing the matched condition conditions.Remove(fieldName); return(true); }