Пример #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.boris.expr.Expr evaluate(org.boris.expr.IEvaluationContext paramIEvaluationContext, org.boris.expr.Expr[] paramArrayOfExpr) throws org.boris.expr.ExprException
        public virtual Expr evaluate(IEvaluationContext paramIEvaluationContext, Expr[] paramArrayOfExpr)
        {
            assertMinArgCount(paramArrayOfExpr, 1);
            for (sbyte b = 0; b < paramArrayOfExpr.Length; b++)
            {
                if (paramArrayOfExpr[b] is org.boris.expr.ExprEvaluatable)
                {
                    paramArrayOfExpr[b] = evalArg(paramIEvaluationContext, paramArrayOfExpr[b]);
                }
            }
            if (!(paramArrayOfExpr[0] is ExprString))
            {
                throw new ExprException("Input " + paramArrayOfExpr[0].ToString() + " is not a String.");
            }
            string str = ((ExprString)paramArrayOfExpr[0]).str;
            bool   bool1;

            for (bool1 = true; bool1 < paramArrayOfExpr.Length; bool1++)
            {
                if (paramArrayOfExpr[bool1] is ExprVariable)
                {
                    paramArrayOfExpr[bool1] = paramIEvaluationContext.evaluateVariable((ExprVariable)paramArrayOfExpr[bool1]);
                }
                if (!(paramArrayOfExpr[bool1] is ExprString) && !(paramArrayOfExpr[bool1] is org.boris.expr.ExprNumber) && !(paramArrayOfExpr[bool1] is ExprBoolean))
                {
                    throw new ExprException("Invalid Parameter Value: " + paramArrayOfExpr[bool1]);
                }
            }
            bool1 = true;
            Session session = null;
            bool    bool2   = true;

            if (paramIEvaluationContext is ExprAbstractEvaluationContext)
            {
                session = ((ExprAbstractEvaluationContext)paramIEvaluationContext).MasterDatabaseSession;
                if (session == null)
                {
                    bool1   = DatabaseDBUtil.hasOpenedSession();
                    session = DatabaseDBUtil.currentSession();
                    bool2   = DatabaseDBUtil.LocalCommunication;
                }
            }
            string[] arrayOfString = null;
            int      i             = 0;

            try
            {
                SQLQuery sQLQuery             = null;
                System.Collections.IList list = Collections.EMPTY_LIST;
                if (bool2)
                {
                    Query query;
                    sQLQuery           = session.createSQLQuery(str);
                    sQLQuery.Cacheable = true;
                    for (sbyte b2 = 1; b2 < paramArrayOfExpr.Length; b2++)
                    {
                        if (paramArrayOfExpr[b2] is ExprString)
                        {
                            query = sQLQuery.setString(b2 - true, ((ExprString)paramArrayOfExpr[b2]).str);
                        }
                        else if (paramArrayOfExpr[b2] is ExprDouble)
                        {
                            query = query.setDouble(b2 - true, ((ExprDouble)paramArrayOfExpr[b2]).doubleValue());
                        }
                        else if (paramArrayOfExpr[b2] is ExprInteger)
                        {
                            query = query.setInteger(b2 - true, ((ExprInteger)paramArrayOfExpr[b2]).intValue());
                        }
                        else if (paramArrayOfExpr[b2] is ExprBoolean)
                        {
                            query = query.setBoolean(b2 - true, ((ExprBoolean)paramArrayOfExpr[b2]).booleanValue());
                        }
                    }
                    list = query.list();
                    if (list.Count != 0)
                    {
                        object @object = list[0];
                        if (@object is BaseEntity)
                        {
                            ClassMetadata classMetadata = ((SessionImplementor)session).Factory.getClassMetadata(@object.GetType());
                            arrayOfString = classMetadata.PropertyNames;
                            if (arrayOfString == null)
                            {
                                throw new Exception("Invalid class name: " + @object.GetType());
                            }
                            i = arrayOfString.Length;
                        }
                        else if (@object is object[])
                        {
                            i = (object[])@object.length;
                        }
                        else
                        {
                            i = 1;
                        }
                    }
                }
                else
                {
                    List <object> arrayList = new List <object>();
                    for (sbyte b2 = 1; b2 < paramArrayOfExpr.Length; b2++)
                    {
                        if (paramArrayOfExpr[b2] is ExprString)
                        {
                            arrayList.Add(new HqlParameterWithValue(b2 - true, ((ExprString)paramArrayOfExpr[b2]).str));
                        }
                        else if (paramArrayOfExpr[b2] is ExprDouble)
                        {
                            arrayList.Add(new HqlParameterWithValue(b2 - true, Convert.ToDouble(((ExprDouble)paramArrayOfExpr[b2]).doubleValue())));
                        }
                        else if (paramArrayOfExpr[b2] is ExprInteger)
                        {
                            arrayList.Add(new HqlParameterWithValue(b2 - true, new long?(((ExprInteger)paramArrayOfExpr[b2]).intValue())));
                        }
                        else if (paramArrayOfExpr[b2] is ExprBoolean)
                        {
                            arrayList.Add(new HqlParameterWithValue(b2 - true, "" + ((ExprBoolean)paramArrayOfExpr[b2]).booleanValue()));
                        }
                    }
                    throw new System.ArgumentException("not implemented as a web service");
                }
                ExprArray exprArray = new ExprArray(list.Count, i);
                sbyte     b1        = 0;
                foreach (object @object in list)
                {
                    if (@object is HqlResultValue[])
                    {
                        HqlResultValue[] arrayOfHqlResultValue = (HqlResultValue[])@object;
                        for (sbyte b2 = 0; b2 < arrayOfHqlResultValue.Length; b2++)
                        {
                            setArrayValue(exprArray, arrayOfHqlResultValue[b2], b1, b2);
                        }
                    }
                    else if (@object is object[])
                    {
                        object[] arrayOfObject = (object[])@object;
                        for (sbyte b2 = 0; b2 < arrayOfObject.Length; b2++)
                        {
                            setArrayValue(exprArray, arrayOfObject[b2], b1, b2);
                        }
                    }
                    else if (@object is BaseEntity)
                    {
                        sbyte b2 = 0;
                        foreach (string str1 in arrayOfString)
                        {
                            object object1 = BlankResourceInitializer.getFieldValue((BaseEntity)@object, str1);
                            setArrayValue(exprArray, object1, b1, b2++);
                        }
                    }
                    else if (i == 1)
                    {
                        setArrayValue(exprArray, @object, b1, 0);
                    }
                    else
                    {
                        if (!bool1)
                        {
                            DatabaseDBUtil.closeSession();
                        }
                        throw new ExprException("Not a persistent class: " + @object.GetType().Name);
                    }
                    b1++;
                }
                if (!bool1)
                {
                    DatabaseDBUtil.closeSession();
                }
                return(exprArray);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());
                Console.Write(exception.StackTrace);
                if (!bool1)
                {
                    DatabaseDBUtil.closeSession();
                }
                throw new ExprException(exception.Message);
            }
        }
Пример #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.boris.expr.Expr evaluate(org.boris.expr.IEvaluationContext paramIEvaluationContext, org.boris.expr.Expr[] paramArrayOfExpr) throws org.boris.expr.ExprException
        public virtual Expr evaluate(IEvaluationContext paramIEvaluationContext, Expr[] paramArrayOfExpr)
        {
            assertMinArgCount(paramArrayOfExpr, 1);
            for (sbyte b = 0; b < paramArrayOfExpr.Length; b++)
            {
                if (paramArrayOfExpr[b] is org.boris.expr.ExprEvaluatable)
                {
                    paramArrayOfExpr[b] = evalArg(paramIEvaluationContext, paramArrayOfExpr[b]);
                }
            }
            if (!(paramArrayOfExpr[0] is ExprString))
            {
                throw new ExprException("Input " + paramArrayOfExpr[0].ToString() + " is not a String.");
            }
            string str = ((ExprString)paramArrayOfExpr[0]).str;
            bool   @bool;

            for (@bool = true; @bool < paramArrayOfExpr.Length; @bool++)
            {
                if (paramArrayOfExpr[@bool] is ExprVariable)
                {
                    paramArrayOfExpr[@bool] = paramIEvaluationContext.evaluateVariable((ExprVariable)paramArrayOfExpr[@bool]);
                }
                if (!(paramArrayOfExpr[@bool] is ExprString) && !(paramArrayOfExpr[@bool] is org.boris.expr.ExprNumber) && !(paramArrayOfExpr[@bool] is ExprBoolean))
                {
                    throw new ExprException("Invalid Parameter Value: " + paramArrayOfExpr[@bool]);
                }
            }
            @bool = true;
            Session       session       = null;
            ProjectDBUtil projectDBUtil = null;

            if (paramIEvaluationContext is ExprAbstractEvaluationContext)
            {
                session = ((ExprAbstractEvaluationContext)paramIEvaluationContext).ProjectDatabaseSession;
                if (session == null)
                {
                    projectDBUtil = ProjectDBUtil.currentProjectDBUtil();
                    if (projectDBUtil == null)
                    {
                        return(new DummyExprArray());
                    }
                    @bool   = projectDBUtil.hasOpenedSession();
                    session = projectDBUtil.currentSession();
                }
            }
            string[] arrayOfString = null;
            try
            {
                Query query = session.createQuery(str);
                query.Cacheable = true;
                for (sbyte b1 = 1; b1 < paramArrayOfExpr.Length; b1++)
                {
                    if (paramArrayOfExpr[b1] is ExprString)
                    {
                        query = query.setString(b1 - true, ((ExprString)paramArrayOfExpr[b1]).str);
                    }
                    else if (paramArrayOfExpr[b1] is ExprDouble)
                    {
                        query = query.setDouble(b1 - true, ((ExprDouble)paramArrayOfExpr[b1]).doubleValue());
                    }
                    else if (paramArrayOfExpr[b1] is ExprInteger)
                    {
                        query = query.setInteger(b1 - true, ((ExprInteger)paramArrayOfExpr[b1]).intValue());
                    }
                    else if (paramArrayOfExpr[b1] is ExprBoolean)
                    {
                        query = query.setBoolean(b1 - true, ((ExprBoolean)paramArrayOfExpr[b1]).booleanValue());
                    }
                }
                System.Collections.IList list = query.list();
                int i = 0;
                if (list.Count != 0)
                {
                    object @object = list[0];
                    if (@object is BaseEntity)
                    {
                        ClassMetadata classMetadata = ((SessionImplementor)session).Factory.getClassMetadata(@object.GetType());
                        arrayOfString = classMetadata.PropertyNames;
                        if (arrayOfString == null)
                        {
                            throw new Exception("Invalid class name: " + @object.GetType());
                        }
                        i = arrayOfString.Length;
                    }
                    else if (@object is object[])
                    {
                        i = (object[])@object.length;
                    }
                    else
                    {
                        i = 1;
                    }
                }
                ExprArray exprArray = new ExprArray(list.Count, i);
                sbyte     b2        = 0;
                foreach (object @object in list)
                {
                    if (@object is object[])
                    {
                        object[] arrayOfObject = (object[])@object;
                        for (sbyte b3 = 0; b3 < arrayOfObject.Length; b3++)
                        {
                            setArrayValue(exprArray, arrayOfObject[b3], b2, b3);
                        }
                    }
                    else if (@object is BaseEntity)
                    {
                        sbyte b3 = 0;
                        foreach (string str1 in arrayOfString)
                        {
                            object object1 = BlankResourceInitializer.getFieldValue((BaseEntity)@object, str1);
                            setArrayValue(exprArray, object1, b2, b3++);
                        }
                    }
                    else if (i == 1)
                    {
                        setArrayValue(exprArray, @object, b2, 0);
                    }
                    else
                    {
                        if (!@bool)
                        {
                            projectDBUtil.closeSession();
                        }
                        throw new ExprException("Not a persistent class: " + @object.GetType().Name);
                    }
                    b2++;
                }
                if (projectDBUtil != null && !@bool)
                {
                    projectDBUtil.closeSession();
                }
                return(exprArray);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());
                Console.Write(exception.StackTrace);
                if (!@bool)
                {
                    projectDBUtil.closeSession();
                }
                throw new ExprException(exception.Message);
            }
        }