示例#1
0
        public override string Execute(TriggerItem triggerItem)
        {
            string leftValue  = LeftValue.GetValue(triggerItem);
            string rightValue = RightValue.GetValue(triggerItem);

            switch (Operator)
            {
            case ExpressionOperator.Equal:
            case ExpressionOperator.NotEqual:
                bool result = false;
                if (rightValue.StartsWith("*") && rightValue.EndsWith("*"))
                {
                    result = leftValue.Contains(rightValue.Substring(1, rightValue.Length - 2));
                }
                else if (rightValue.StartsWith("*"))
                {
                    result = leftValue.StartsWith(rightValue.Substring(1));
                }
                else if (rightValue.EndsWith("*"))
                {
                    result = leftValue.StartsWith(rightValue.Substring(0, rightValue.Length - 1));
                }
                else
                {
                    result = leftValue == rightValue;
                }
                result = (Operator == ExpressionOperator.Equal ? result : !result);
                return(result ? "1" : "0");

            case ExpressionOperator.Contains:
                return(leftValue.Contains(rightValue) ? "1" : "0");

            case ExpressionOperator.StartsWith:
                return(leftValue.StartsWith(rightValue) ? "1" : "0");

            case ExpressionOperator.EndsWith:
                return(leftValue.EndsWith(rightValue) ? "1" : "0");

            case ExpressionOperator.And:
                return(leftValue == "1" && rightValue == "1" ? "1" : "0");

            case ExpressionOperator.Or:
                return(leftValue == "1" || rightValue == "1" ? "1" : "0");

            default:
                return("0");
            }
        }
        public override int Execute(TriggerItem triggerItem)
        {
            int leftValue  = LeftValue.GetValue(triggerItem);
            int rightValue = RightValue.GetValue(triggerItem);

            switch (Operator)
            {
            case ExpressionOperator.Add:
                return(leftValue + rightValue);

            case ExpressionOperator.Subtract:
                return(leftValue - rightValue);

            case ExpressionOperator.Multiply:
                return(leftValue * rightValue);

            case ExpressionOperator.Divide:
                return(leftValue / rightValue);

            case ExpressionOperator.Equal:
                return(leftValue == rightValue ? 1 : 0);

            case ExpressionOperator.NotEqual:
                return(leftValue != rightValue ? 1 : 0);

            case ExpressionOperator.Larger:
                return(leftValue > rightValue ? 1 : 0);

            case ExpressionOperator.LargerOrEqual:
                return(leftValue >= rightValue ? 1 : 0);

            case ExpressionOperator.Smaller:
                return(leftValue < rightValue ? 1 : 0);

            case ExpressionOperator.SmallerOrEqual:
                return(leftValue <= rightValue ? 1 : 0);

            case ExpressionOperator.And:
                return((leftValue != 0) && (rightValue != 0) ? 1 : 0);

            case ExpressionOperator.Or:
                return((leftValue != 0) || (rightValue != 0) ? 1 : 0);

            default:
                return(0);
            }
        }