/// <summary> /// Convert FilterRule to our custom FilterRuleBuilder which will be displayed in form controls /// </summary> /// <param name="param">Parameter to which the FilterRule is applied.</param> /// <param name="rule">FilterRule to be converted.</param> /// <returns>Custom FilterRuleBuilder data converted from FilterRule</returns> public static FilterRuleBuilder CreateFilterRuleBuilder(BuiltInParameter param, FilterRule rule) { // Maybe FilterRule is inverse rule, we need to find its inner rule(FilterValueRule) // Note that the rule may be inversed more than once. bool inverted = false; FilterRule innerRule = ReflectToInnerRule(rule, out inverted); if (innerRule is FilterStringRule) { FilterStringRule strRule = innerRule as FilterStringRule; FilterStringRuleEvaluator evaluator = strRule.GetEvaluator(); return(new FilterRuleBuilder(param, GetEvaluatorCriteriaName(evaluator, inverted), strRule.RuleString, strRule.RuleString.ToLower() == strRule.RuleString ? false : true)); } else if (innerRule is FilterDoubleRule) { FilterDoubleRule dbRule = innerRule as FilterDoubleRule; FilterNumericRuleEvaluator evaluator = dbRule.GetEvaluator(); return(new FilterRuleBuilder(param, GetEvaluatorCriteriaName(evaluator, inverted), dbRule.RuleValue, dbRule.Epsilon)); } else if (innerRule is FilterIntegerRule) { FilterIntegerRule intRule = innerRule as FilterIntegerRule; FilterNumericRuleEvaluator evaluator = intRule.GetEvaluator(); return(new FilterRuleBuilder(param, GetEvaluatorCriteriaName(evaluator, inverted), intRule.RuleValue)); } else if (innerRule is FilterElementIdRule) { FilterElementIdRule idRule = innerRule as FilterElementIdRule; FilterNumericRuleEvaluator evaluator = idRule.GetEvaluator(); return(new FilterRuleBuilder(param, GetEvaluatorCriteriaName(evaluator, inverted), idRule.RuleValue)); } // // for other rule, not supported yet throw new System.NotImplementedException("The filter rule is not recognizable and supported yet!"); }
//Private Method private static string CastFilterRule(FilterRule r) { if (r is FilterStringRule) { FilterStringRule filterRule = r as FilterStringRule; FilterStringRuleEvaluator evaluator = filterRule.GetEvaluator(); if (filterRule.GetEvaluator() is FilterStringBeginsWith) { return("FilterStringBeginsWith"); } else if (filterRule.GetEvaluator() is FilterStringContains) { return("FilterStringContains"); } else if (filterRule.GetEvaluator() is FilterStringEndsWith) { return("FilterStringEndsWith"); } else if (filterRule.GetEvaluator() is FilterStringEquals) { return("FilterStringEquals"); } else if (filterRule.GetEvaluator() is FilterStringGreaterOrEqual) { return("FilterStringGreaterOrEqual"); } else if (filterRule.GetEvaluator() is FilterStringLess) { return("FilterStringLess"); } else if (filterRule.GetEvaluator() is FilterStringLessOrEqual) { return("FilterStringLessOrEqual"); } } else if (r is FilterIntegerRule || r is FilterDoubleRule || r is FilterGlobalParameterAssociationRule) { FilterIntegerRule filterRule = r as FilterIntegerRule; FilterNumericRuleEvaluator evaluator = filterRule.GetEvaluator(); if (filterRule.GetEvaluator() is FilterNumericEquals) { return("FilterNumericEquals"); } else if (filterRule.GetEvaluator() is FilterNumericGreater) { return("FilterNumericGreater"); } else if (filterRule.GetEvaluator() is FilterNumericGreaterOrEqual) { return("FilterNumericGreaterOrEqual"); } else if (filterRule.GetEvaluator() is FilterNumericLess) { return("FilterNumericLess"); } else if (filterRule.GetEvaluator() is FilterNumericLessOrEqual) { return("FilterNumericLessOrEqual"); } } else if (r is FilterInverseRule) { FilterInverseRule filterRule = r as FilterInverseRule; FilterRule innerRule = filterRule.GetInnerRule(); return(CastFilterRule(innerRule) + "_InnerRule"); } else if (r is SharedParameterApplicableRule) { return("SharedParameterApplicableRule"); } ; return(null); }