示例#1
0
            /// <summary>
            /// Create a SimpleExpression or a BooleanExpression based on the string that this method receive
            /// </summary>
            /// <param name="SimpleExpression"></param>
            /// <returns></returns>
            public static BooleanOperand Create(string ExpressionToEvaluate)
            {
                Regex re;
                Match m;

                re = new Regex(@"(?<exp1>.*)\s*(?<op>[&][&]|[|][|])\s*(?<exp2>.*)\s*");
                m  = re.Match(ExpressionToEvaluate);
                if (m.Success)                  // complex expression ==> a=1 && b>4
                {
                    // exp2 is a simple expression for sure
                    BooleanOperand      exp2     = BooleanOperand.Create(m.Groups["exp2"].Value);
                    BooleanOperatorType Operator = BooleanExpression.GetBooleanOperator(m.Groups["op"].Value);
                    BooleanOperand      exp1     = BooleanOperand.Create(m.Groups["exp1"].Value);

                    BooleanExpression be = new BooleanExpression(exp1, Operator, exp2);

                    return(be);
                }

                // At this point it's a simple expression
                re = new Regex(@"(?:(?<left>\w+)\s*(?<op>[=]|[>]|[<]|[<][=]|[>][=])\s*(?<right>[\x22]?\w+[\x22]?))");
                m  = re.Match(ExpressionToEvaluate);
                if (!m.Success)
                {
                    throw new Exception("Invalid SimpleExpression: " + ExpressionToEvaluate);
                }

                string             Property           = m.Groups["left"].Value;
                string             Value              = m.Groups["right"].Value;
                SimpleOperatorType ExpressionOperator = SimpleExpression.GetExpressionOperator(m.Groups["op"].Value);

                SimpleExpression simple = new SimpleExpression(Property, ExpressionOperator, Value);

                return(simple);
            }
示例#2
0
        private string GetBooleanOperator(BooleanOperatorType type)
        {
            switch (type)
            {
            case BooleanOperatorType.Equals:
                return(" = ");

            case BooleanOperatorType.GreaterThan:
                return(" > ");

            case BooleanOperatorType.GreaterThanOrEqual:
                return(" >= ");

            case BooleanOperatorType.LessThan:
                return(" < ");

            case BooleanOperatorType.LessThanOrEqual:
                return(" <= ");

            case BooleanOperatorType.Like:
                return(" LIKE ");

            case BooleanOperatorType.NotEqual:
                return(" <> ");

            case BooleanOperatorType.NotGreaterThan:
                return(" !> ");

            case BooleanOperatorType.NotLessThan:
                return(" !< ");

            default:
                throw new NotSupportedException();
            }
        }
示例#3
0
            public static BooleanOperatorType GetBooleanOperator(string OperatorValue)
            {
                BooleanOperatorType Op = BooleanOperatorType.And;

                switch (OperatorValue)
                {
                case "&&":
                    Op = BooleanOperatorType.And;
                    break;

                case "||":
                    Op = BooleanOperatorType.Or;
                    break;
                }
                return(Op);
            }
示例#4
0
            public BooleanExpression(string Left, BooleanOperand Right)
            {
                Regex re = new Regex(@"(?:(?<exp>\S+)\s*(?<op>[&][&]|[|][|])\s*)|(?:(?<op>[&][&]|[|][|])\s*(?<exp>\S+)\s*)");
                Match m  = re.Match(Left);

                if (!m.Success)
                {
                    throw new Exception("Invalid SimpleExpression: " + Left);
                }

                //SimpleExpression exp = new SimpleExpression(m.Groups["exp"].Value);
                BooleanOperand exp = BooleanOperand.Create(m.Groups["exp"].Value);

                this.Left  = exp;
                this.Right = Right;

                string op = m.Groups["op"].Value;

                BooleanOperator = BooleanExpression.GetBooleanOperator(op);
            }
示例#5
0
        public static dynamic GetTSObject(BooleanOperatorType dynEnum)
        {
            var tsType = TSActivator.CreateInstance("Tekla.Structures.Filtering.BooleanOperatorType").GetType();

            switch (dynEnum)
            {
            case BooleanOperatorType.IS_EQUAL:
                return(System.Enum.Parse(tsType, "IS_EQUAL"));

            case BooleanOperatorType.IS_NOT_EQUAL:
                return(System.Enum.Parse(tsType, "IS_NOT_EQUAL"));

            case BooleanOperatorType.BOOLEAN_OR:
                return(System.Enum.Parse(tsType, "BOOLEAN_OR"));

            case BooleanOperatorType.BOOLEAN_AND:
                return(System.Enum.Parse(tsType, "BOOLEAN_AND"));

            default:
                throw new DynamicAPIException(dynEnum.ToString() + "- enum value is not implemented");
            }
        }
示例#6
0
 public BooleanExpression(BooleanOperand Left, string Operator, BooleanOperand Right)
 {
     _Left            = Left;
     _BooleanOperator = BooleanExpression.GetBooleanOperator(Operator);
     _Right           = Right;
 }
示例#7
0
 public BooleanExpression(BooleanOperand Left, BooleanOperatorType Operator, BooleanOperand Right)
 {
     _Left            = Left;
     _BooleanOperator = Operator;
     _Right           = Right;
 }