Пример #1
0
        protected static bool EvaluateBlock(string block, Part part)
        {
            block = block.ToLower();
            // The meat of the evaluation is done here
            if (block.Contains(" "))
            {
                string[] parts = block.Split(new char[1] {
                    ' '
                });
                if (parts.Length < 3)
                {
                    return(false);
                }

                string qualifier = parts[0];
                string op        = parts[1];
                string term      = parts[2];
                string term1     = "";
                string term2     = "";

                if (term.Contains("-"))
                {
                    term1 = term.Split(new char[1] {
                        '-'
                    })[0];
                    term2 = term.Split(new char[1] {
                        '-'
                    })[1];
                }
                // try to get the interop value for this operator
                ITestFlightInterop interop = TestFlightUtil.GetInteropModule(part);
                if (interop == null)
                {
                    return(false);
                }
                InteropValue val;
                val = interop.GetInterop(qualifier);
                if (val.valueType == InteropValueType.INVALID)
                {
                    return(false);
                }
                switch (op)
                {
                case "=":
                    switch (val.valueType)
                    {
                    case InteropValueType.BOOL:
                        if (bool.Parse(val.value) == bool.Parse(term))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case InteropValueType.FLOAT:
                        if (float.Parse(val.value) == float.Parse(term))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case InteropValueType.INT:
                        if (int.Parse(val.value) == int.Parse(term))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case InteropValueType.STRING:
                        if (val.value.ToLower() == term)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    break;

                case "!=":
                    switch (val.valueType)
                    {
                    case InteropValueType.BOOL:
                        if (bool.Parse(val.value) != bool.Parse(term))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case InteropValueType.FLOAT:
                        if (float.Parse(val.value) != float.Parse(term))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case InteropValueType.INT:
                        if (int.Parse(val.value) != int.Parse(term))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case InteropValueType.STRING:
                        if (val.value.ToLower() != term)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    break;

                case "<":
                    switch (val.valueType)
                    {
                    case InteropValueType.FLOAT:
                        if (float.Parse(val.value) < float.Parse(term))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case InteropValueType.INT:
                        if (int.Parse(val.value) < int.Parse(term))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    break;

                case ">":
                    switch (val.valueType)
                    {
                    case InteropValueType.FLOAT:
                        if (float.Parse(val.value) > float.Parse(term))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case InteropValueType.INT:
                        if (int.Parse(val.value) > int.Parse(term))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    break;

                case "<=":
                    switch (val.valueType)
                    {
                    case InteropValueType.FLOAT:
                        if (float.Parse(val.value) <= float.Parse(term))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case InteropValueType.INT:
                        if (int.Parse(val.value) <= int.Parse(term))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    break;

                case ">=":
                    switch (val.valueType)
                    {
                    case InteropValueType.FLOAT:
                        if (float.Parse(val.value) >= float.Parse(term))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case InteropValueType.INT:
                        if (int.Parse(val.value) >= int.Parse(term))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    break;

                case "<>":
                    switch (val.valueType)
                    {
                    case InteropValueType.FLOAT:
                        if (float.Parse(val.value) > float.Parse(term1) && float.Parse(val.value) < float.Parse(term2))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case InteropValueType.INT:
                        if (int.Parse(val.value) > int.Parse(term1) && int.Parse(val.value) < int.Parse(term1))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    break;

                case "<=>":
                    switch (val.valueType)
                    {
                    case InteropValueType.FLOAT:
                        if (float.Parse(val.value) >= float.Parse(term1) && float.Parse(val.value) <= float.Parse(term2))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case InteropValueType.INT:
                        if (int.Parse(val.value) >= int.Parse(term1) && int.Parse(val.value) <= int.Parse(term1))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    break;
                }
                return(false);
            }
            else
            {
                // if there are no "parts" to this block, then it must be just a simple part name or an alias
                if (block == part.name.ToLower())
                {
                    return(true);
                }
                if (block == TestFlightUtil.GetFullPartName(part).ToLower())
                {
                    return(true);
                }
                return(false);
            }
        }
        public static bool EvaluateBlock(string block, Part part)
        {
            block = block.ToLower();
            // The meat of the evaluation is done here
            if (block.Contains(" "))
            {
                string[] parts = block.Split(new char[1] {
                    ' '
                });
                if (parts.Length < 3)
                {
                    return(false);
                }

                string qualifier = parts[0];
                string op        = parts[1];
                string term      = parts[2];
                string term1     = "";
                string term2     = "";

                if (term.Contains("-"))
                {
                    term1 = term.Split(new char[1] {
                        '-'
                    })[0];
                    term2 = term.Split(new char[1] {
                        '-'
                    })[1];
                }
                // try to get the interop value for this operator
                ITestFlightInterop interop = TestFlightUtil.GetInteropModule(part);
                if (interop == null)
                {
                    return(false);
                }
                var val = interop.GetInterop(qualifier);
                if (val.valueType == InteropValueType.INVALID)
                {
                    return(false);
                }
                switch (op)
                {
                case "=":
                    switch (val.valueType)
                    {
                    case InteropValueType.BOOL:
                        return(bool.Parse(val.value) == bool.Parse(term));

                    case InteropValueType.FLOAT:
                        return(Math.Abs(float.Parse(val.value) - float.Parse(term)) < .0001);

                    case InteropValueType.INT:
                        return(int.Parse(val.value) == int.Parse(term));

                    case InteropValueType.STRING:
                        return(string.Equals(val.value, term, StringComparison.InvariantCultureIgnoreCase));
                    }
                    break;

                case "!=":
                    switch (val.valueType)
                    {
                    case InteropValueType.BOOL:
                        return(bool.Parse(val.value) != bool.Parse(term));

                    case InteropValueType.FLOAT:
                        return(Math.Abs(float.Parse(val.value) - float.Parse(term)) > .0001);

                    case InteropValueType.INT:
                        return(int.Parse(val.value) != int.Parse(term));

                    case InteropValueType.STRING:
                        return(!string.Equals(val.value, term, StringComparison.InvariantCultureIgnoreCase));
                    }
                    break;

                case "<":
                    switch (val.valueType)
                    {
                    case InteropValueType.FLOAT:
                        return(float.Parse(val.value) < float.Parse(term));

                    case InteropValueType.INT:
                        return(int.Parse(val.value) < int.Parse(term));
                    }
                    break;

                case ">":
                    switch (val.valueType)
                    {
                    case InteropValueType.FLOAT:
                        return(float.Parse(val.value) > float.Parse(term));

                    case InteropValueType.INT:
                        return(int.Parse(val.value) > int.Parse(term));
                    }
                    break;

                case "<=":
                    switch (val.valueType)
                    {
                    case InteropValueType.FLOAT:
                        return(float.Parse(val.value) <= float.Parse(term));

                    case InteropValueType.INT:
                        return(int.Parse(val.value) <= int.Parse(term));
                    }
                    break;

                case ">=":
                    switch (val.valueType)
                    {
                    case InteropValueType.FLOAT:
                        return(float.Parse(val.value) >= float.Parse(term));

                    case InteropValueType.INT:
                        return(int.Parse(val.value) >= int.Parse(term));
                    }
                    break;

                case "<>":
                    switch (val.valueType)
                    {
                    case InteropValueType.FLOAT:
                        return(float.Parse(val.value) > float.Parse(term1) && float.Parse(val.value) < float.Parse(term2));

                    case InteropValueType.INT:
                        return(int.Parse(val.value) > int.Parse(term1) && int.Parse(val.value) < int.Parse(term1));
                    }
                    break;

                case "<=>":
                    switch (val.valueType)
                    {
                    case InteropValueType.FLOAT:
                        return(float.Parse(val.value) >= float.Parse(term1) && float.Parse(val.value) <= float.Parse(term2));

                    case InteropValueType.INT:
                        return(int.Parse(val.value) >= int.Parse(term1) && int.Parse(val.value) <= int.Parse(term1));
                    }
                    break;
                }
                return(false);
            }
            else
            {
                return(false);
            }
        }