/// <summary> ///Check if All Variables are Defined /// </summary> /// <param name="source">source</param> /// <param name="logic">logic info</param> /// <returns>true if fully defined</returns> public static bool IsAllVariablesDefined(Evaluatee source, string logic) { if (logic == null || logic.Length == 0) { return(true); } // int pos = 0; while (pos < logic.Length) { int first = logic.IndexOf('@', pos); if (first == -1) { return(true); } //int second = logic.Substring(first + 1); int second = logic.IndexOf('@', first + 1); if (second == -1) { //log.severe("No second @ in Logic: " + logic); return(false); } //string variable = logic.substring(first + 1, second - 1); string variable = logic.Substring(first + 1, second - 1); String eval = source.GetValueAsString(variable); //log.finest(variable + "=" + eval); if (eval == null || eval.Length == 0) { return(false); } // pos = second + 1; } return(true); }
/// <summary> ///Evaluate @context@=value or @context@!value or @context@^value. ///<pre> ///value: strips ' and " always (no escape or mid stream) ///value: can also be a context variable ///</pre> ///@param source /// </summary> /// <param name="source">class implementing get_ValueAsString(variable)</param> /// <param name="logic">logic tuple</param> /// <returns>true or false</returns> private static bool EvaluateLogicTuple(Evaluatee source, string logic) { StringTokenizer st = new StringTokenizer(logic.Trim(), "!=^><", true); if (st.CountTokens() != 3) { //log.warning("Logic tuple does not comply with format " // + "'@context@=value' where operand could be one of '=!^><' => " + logic); return(false); } // First Part String first = st.NextToken().Trim(); // get '@tag@' String firstEval = first.Trim(); if (first.IndexOf('@') != -1) // variable { first = first.Replace('@', ' ').Trim(); // strip 'tag' //firstEval = source.get_ValueAsString(first); // replace with it's value firstEval = source.GetValueAsString(first); if (firstEval == null) { firstEval = ""; } } firstEval = firstEval.Replace('\'', ' ').Replace('"', ' ').Trim(); // strip ' and " // Comperator String operand = st.NextToken(); // Second Part String second = st.NextToken(); // get value String secondEval = second.Trim(); if (second.IndexOf('@') != -1) // variable { second = second.Replace('@', ' ').Trim(); // strip tag //secondEval = source.get_ValueAsString(second); // replace with it's value secondEval = source.GetValueAsString(second); // replace with it's value if (secondEval == null) { secondEval = ""; } } secondEval = secondEval.Replace('\'', ' ').Replace('"', ' ').Trim(); // strip ' and " // Handling of ID compare (null => 0) if (first.IndexOf("_ID") != -1 && firstEval.Length == 0) { firstEval = "0"; } if (second.IndexOf("_ID") != -1 && secondEval.Length == 0) { secondEval = "0"; } // Logical Comparison bool result = EvaluateLogicTuple(firstEval, operand, secondEval); //if (log.isLevelFinest()) // log.finest(logic // + " => \"" + firstEval + "\" " + operand + " \"" + secondEval + "\" => " + result); // return(result); }