Ejemplo n.º 1
0
        private void BuildSPCommand()
        {
            object value;

            string[] strArrays = Regex.Replace(Regex.Replace(this.Text, "[\\s]+", " "), " *, *", ",").Trim().Split(new char[] { ' ' });
            if ((int)strArrays.Length < 1)
            {
                throw new Exception("sentense is wrong");
            }
            this.Text = strArrays[0];
            if ((int)strArrays.Length > 1)
            {
                string[] strArrays1 = strArrays[1].Split(new char[] { ',' });
                for (int i = 0; i < (int)strArrays1.Length; i++)
                {
                    string              str                  = strArrays1[i];
                    string[]            strArrays2           = str.Split(new char[] { '=' });
                    MapperParameterItem mapperParameterItem  = this.Parameter.Add(strArrays2[0]);
                    MapperParameterItem mapperParameterItem1 = mapperParameterItem;
                    ParameterSource     parameterSource      = this.parameterSource.Find((ParameterSource p) => p.Name.MatchDataName(strArrays2[0]));
                    if (parameterSource != null)
                    {
                        value = parameterSource.Value;
                    }
                    else
                    {
                        value = null;
                    }
                    mapperParameterItem1.Value = value;
                    if (!strArrays2[1].StartsWith("@"))
                    {
                        mapperParameterItem.Direction = ParameterDirection.Input;
                        mapperParameterItem.Value     = strArrays2[1].Trim(new char[] { '\'' });
                    }
                    else if (strArrays2[1].LastIndexOf("<table>") > 0)
                    {
                        mapperParameterItem.IsTable = true;
                        ValueTable dataTable = mapperParameterItem.Value.ToString().ToDataTable();
                        dataTable.TableName       = strArrays2[0];
                        mapperParameterItem.Value = dataTable;
                    }
                    else if (strArrays2[1].LastIndexOf("<out>") <= 0)
                    {
                        mapperParameterItem.Direction = ParameterDirection.Input;
                    }
                    else
                    {
                        mapperParameterItem.Direction = ParameterDirection.Output;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static bool Evaluate(string expression, List <ParameterSource> source)
        {
            bool?  isOperand;
            string str;
            string str1;
            string name;
            List <ExpressionToken>  expressionTokens  = new List <ExpressionToken>();
            Stack <ExpressionToken> expressionTokens1 = new Stack <ExpressionToken>();
            StringReader            stringReader      = new StringReader(expression);

Label0:
            while (stringReader.Peek() >= 0)
            {
                ExpressionToken expressionToken = ExpressionEvaluator.ReadToken(stringReader);
                expressionToken.SetCode();
                isOperand = expressionToken.IsOperand;
                if ((isOperand.GetValueOrDefault() ? isOperand.HasValue : false))
                {
                    expressionTokens.Add(expressionToken);
                }
                else if (expressionToken.Name == "(")
                {
                    expressionTokens1.Push(expressionToken);
                }
                else if (expressionToken.Name != ")")
                {
                    while (expressionTokens1.Count > 0)
                    {
                        ExpressionToken expressionToken1 = expressionTokens1.Peek();
                        if (expressionToken1.OpCode.Order > expressionToken.OpCode.Order)
                        {
                            break;
                        }
                        expressionTokens1.Pop();
                        expressionTokens.Add(expressionToken1);
                    }
                    expressionTokens1.Push(expressionToken);
                }
                else
                {
                    while (expressionTokens1.Count > 0)
                    {
                        ExpressionToken expressionToken2 = expressionTokens1.Pop();
                        if (expressionToken2.Name == "(")
                        {
                            goto Label0;
                        }
                        expressionTokens.Add(expressionToken2);
                    }
                }
            }
            while (expressionTokens1.Count > 0)
            {
                expressionTokens.Add(expressionTokens1.Pop());
            }
            foreach (ExpressionToken expressionToken3 in expressionTokens)
            {
                isOperand = expressionToken3.IsOperand;
                if ((isOperand.GetValueOrDefault() ? !isOperand.HasValue : true))
                {
                    ExpressionToken expressionToken4 = expressionTokens1.Pop();
                    ExpressionToken expressionToken5 = expressionTokens1.Pop();
                    bool            flag             = true;
                    string          str2             = null;
                    double          num = 0;
                    if (expressionToken4.Name == "null")
                    {
                        flag = false;
                    }
                    else if (expressionToken4.Name == "empty")
                    {
                        str2 = "";
                        flag = false;
                    }
                    else if (expressionToken4.Name == "true")
                    {
                        str2 = "true";
                        flag = false;
                    }
                    else if (expressionToken4.Name == "false")
                    {
                        str2 = "false";
                        flag = false;
                    }
                    else if (!expressionToken4.Name.StartsWith("'"))
                    {
                        if (source != null)
                        {
                            ParameterSource parameterSource = source.Find((ParameterSource p) => p.Name.MatchDataName(expressionToken4.Name));
                            if (parameterSource != null)
                            {
                                str = parameterSource.Value.ToString();
                            }
                            else
                            {
                                str = null;
                            }
                        }
                        else
                        {
                            str = null;
                        }
                        str2 = str;
                        if (str2 == null)
                        {
                            flag = false;
                        }
                        else if (!double.TryParse(str2, out num))
                        {
                            flag = false;
                        }
                    }
                    else
                    {
                        str2 = expressionToken4.Name.Trim(new char[] { '\'' });
                        flag = false;
                    }
                    string str3 = null;
                    double num1 = 0;
                    if (expressionToken5.Name == "null")
                    {
                        flag = false;
                    }
                    else if (expressionToken5.Name == "empty")
                    {
                        str3 = "";
                        flag = false;
                    }
                    else if (expressionToken5.Name == "true")
                    {
                        str3 = "true";
                        flag = false;
                    }
                    else if (expressionToken5.Name == "false")
                    {
                        str3 = "false";
                        flag = false;
                    }
                    else if (!expressionToken5.Name.StartsWith("'"))
                    {
                        if (source != null)
                        {
                            ParameterSource parameterSource1 = source.Find((ParameterSource p) => p.Name.MatchDataName(expressionToken5.Name));
                            if (parameterSource1 != null)
                            {
                                object value = parameterSource1.Value;
                                if (value != null)
                                {
                                    str1 = value.ToString();
                                }
                                else
                                {
                                    str1 = null;
                                }
                            }
                            else
                            {
                                str1 = null;
                            }
                        }
                        else
                        {
                            str1 = null;
                        }
                        str3 = str1;
                        if (str3 == null)
                        {
                            flag = false;
                        }
                        else if (!double.TryParse(str3, out num1))
                        {
                            flag = false;
                        }
                    }
                    else
                    {
                        str3 = expressionToken5.Name.Trim(new char[] { '\'' });
                        flag = false;
                    }
                    bool   flag1  = false;
                    string opCode = expressionToken3.OpCode;
                    if (expressionToken3.OpCode == ExpressionOpCode.And || expressionToken3.OpCode == ExpressionOpCode.Or)
                    {
                        if (opCode == "and")
                        {
                            flag1 = (str2 != "true" ? false : str3 == "true");
                        }
                        else if (opCode == "or")
                        {
                            flag1 = (str2 == "true" ? true : str3 == "true");
                        }
                    }
                    else if (flag)
                    {
                        switch (opCode)
                        {
                        case "==":
                        {
                            flag1 = num == num1;
                            break;
                        }

                        case "!=":
                        case "<>":
                        {
                            flag1 = num != num1;
                            break;
                        }

                        case ">=":
                        {
                            flag1 = num >= num1;
                            break;
                        }

                        case "<=":
                        {
                            flag1 = num <= num1;
                            break;
                        }

                        case ">":
                        {
                            flag1 = num > num1;
                            break;
                        }

                        case "<":
                        {
                            flag1 = num < num1;
                            break;
                        }
                        }
                    }
                    else if (opCode == "==")
                    {
                        flag1 = str2 == str3;
                    }
                    else if (opCode == "!=" || opCode == "<>")
                    {
                        flag1 = str2 != str3;
                    }
                    else if (opCode == ">=")
                    {
                        flag1 = str3.CompareTo(str2) >= 0;
                    }
                    else if (opCode == "<=")
                    {
                        flag1 = str3.CompareTo(str2) <= 0;
                    }
                    else if (opCode == ">")
                    {
                        flag1 = str3.CompareTo(str2) > 0;
                    }
                    else if (opCode == "<")
                    {
                        flag1 = str3.CompareTo(str2) < 0;
                    }
                    expressionTokens1.Push(new ExpressionToken()
                    {
                        Name = (flag1 ? "true" : "false")
                    });
                }
                else
                {
                    expressionTokens1.Push(expressionToken3);
                }
            }
            ExpressionToken expressionToken6 = expressionTokens1.Peek();

            if (expressionToken6 != null)
            {
                name = expressionToken6.Name;
            }
            else
            {
                name = null;
            }
            return(name == "true");
        }
Ejemplo n.º 3
0
        private static List <ParameterSource> ConvertParameterSource(MapperProvider provider, object[] source)
        {
            if (source == null)
            {
                source = new object[0];
            }
            for (int i = 0; i < (int)source.Length; i++)
            {
                if (source[i] == null)
                {
                    source[i] = new ParameterSource();
                }
            }
            List <ParameterSource> parameterSources = new List <ParameterSource>((int)source.Length);

            parameterSources.AddRange(provider.Parameter);
            object[] objArray = source;
            for (int j = 0; j < (int)objArray.Length; j++)
            {
                object obj = objArray[j];
                if (!(obj is ValueObject))
                {
                    if (!(obj is Dictionary <string, object>))
                    {
                        goto Label1;
                    }
                    Dictionary <string, object> strs = obj as Dictionary <string, object>;
                    Dictionary <string, object> .KeyCollection.Enumerator enumerator = strs.Keys.GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext())
                        {
                            string current = enumerator.Current;
                            parameterSources.Add(new ParameterSource()
                            {
                                Name  = current,
                                Value = strs[current]
                            });
                        }
                        goto Label0;
                    }
                    finally
                    {
                        ((IDisposable)enumerator).Dispose();
                    }
                }
                else
                {
                    System.Type type = obj.GetType();
                    parameterSources.Add(new ParameterSource()
                    {
                        Name  = type.Name,
                        Value = type
                    });
                }
Label1:
                ParamterTypeAttribute customAttribute = obj.GetType().GetTypeInfo().GetCustomAttribute <ParamterTypeAttribute>();
                PropertyInfo[] properties = ((customAttribute == null ? obj.GetType() : customAttribute.ParamterType)).GetProperties();
                for (int k = 0; k < (int)properties.Length; k++)
                {
                    PropertyInfo propertyInfo = properties[k];
                    if (propertyInfo.GetCustomAttribute <IgnoreAttribute>() == null)
                    {
                        parameterSources.Add(new ParameterSource()
                        {
                            Name   = propertyInfo.Name,
                            Column = propertyInfo.GetCustomAttribute <ColumnAttribute>(),
                            Value  = propertyInfo.GetValue(obj)
                        });
                    }
                }
                Label0 :;
            }
            return(parameterSources);
        }