/// <summary> /// Helper method to return the next step based on the specified /// rule. Called after we've determined that the rule applies. /// </summary> /// <returns>The rule based next.</returns> /// <param name="dbConn">connection to the underlying database</param> /// <param name="rule">the matching rule</param> public static Step GetRuleBasedNext(IDbConnection dbConn, Db.Rule rule) { if (rule == null) { throw new ArgumentNullException("rule"); } var tmp = Step.Select(dbConn, rule.NextStepId); if (tmp == null) { var msg = new StringBuilder(); msg.Append("internal error: the rule applies "); msg.Append("but we can't find next step #"); msg.Append(rule.NextStepId); msg.Append(" in the database ["); msg.Append(rule.ToString()); msg.Append("]"); throw new Exception(msg.ToString()); } return(tmp); }
/// <summary> /// Returns true iff the value in the rule satisfies the value in /// the item. /// For example, if the rule says foo!=someValue, and the item /// has the value in foo for otherValue, then this method /// returns true. /// </summary> /// <param name="rule">the rule to apply</param> /// <param name="valueInItem">The value in the item</param> public static bool Applies(Db.Rule rule , String valueInItem ) { if (rule == null) { throw new ArgumentNullException("rule"); } String valueInRule = rule.VariableValue; int value = String.Compare(valueInRule, valueInItem); switch (rule.Comparison) { case Db.Rule.Compare.Equal: return(value == 0); case Db.Rule.Compare.NotEqual: return(value != 0); case Db.Rule.Compare.Less: return(value > 0); case Db.Rule.Compare.Greater: return(value < 0); default: var msg = new StringBuilder(); msg.Append("unknown rule comparison of type "); msg.Append(rule.Comparison); msg.Append(" in rule ["); msg.Append(rule.ToString()); msg.Append("]"); throw new Exception(msg.ToString()); } }