public static Expression GetEnumeratorExpression(
            DbExpression predicate,
            DbModificationCommandTree commandTree,
            DbContainer container,
            out ITable table)
        {
            TransformVisitor visitor = new TransformVisitor(container.TypeConverter);

            visitor.TableProvider = container;

            // Get the source expression
            ConstantExpression source =
                visitor.Visit(commandTree.Target.Expression) as ConstantExpression;

            // This should be a constant expression
            if (source == null)
            {
                throw new InvalidOperationException();
            }

            table = source.Value as ITable;

            // Get the the type of the elements of the table
            Type elementType = TypeHelper.GetElementType(source.Type);

            // Create context
            ParameterExpression context = Expression.Parameter(elementType, "context");

            using (visitor.CreateVariable(context, commandTree.Target.VariableName))
            {
                // Create the predicate expression
                LambdaExpression predicateExpression =
                    Expression.Lambda(
                        visitor.Visit(predicate),
                        context);

                // Create Where expression
                LinqMethodExpressionBuilder queryMethodBuilder =
                    new LinqMethodExpressionBuilder();

                return(queryMethodBuilder.Where(source, predicateExpression));
            }
        }
        static GameObject FindFirstGameObjectThatMatchesFileID(Transform searchRoot, UInt64 fileID)
        {
            GameObject result           = null;
            var        transformVisitor = new TransformVisitor();

            transformVisitor.VisitAndAllowEarlyOut(searchRoot,
                                                   (transform, userdata) =>
            {
                UInt64 id = GetPrefabOrVariantFileID(transform.gameObject);
                if (id == fileID)
                {
                    result = transform.gameObject;
                    return(false); // stop searching
                }
                return(true);      // continue searching
            }
                                                   , null);

            return(result);
        }
        static Scene LoadOrCreatePreviewScene(string environmentEditingScenePath)
        {
            Scene previewScene;

            if (!string.IsNullOrEmpty(environmentEditingScenePath))
            {
                previewScene = EditorSceneManager.OpenPreviewScene(environmentEditingScenePath);
                var roots   = previewScene.GetRootGameObjects();
                var visitor = new TransformVisitor();
                foreach (var root in roots)
                {
                    visitor.VisitAll(root.transform, AppendEnvironmentName, null);
                }
            }
            else
            {
                previewScene = CreateDefaultPreviewScene();
            }

            return(previewScene);
        }
예제 #4
0
        public int ExecuteNonQuery(ActionContext context)
        {
            // Get the source table
            ITable table = DbCommandActionHelper.GetTable(this.commandTree, context.DbContainer);

            // Collect the SetClause DbExpressions into a dictionary
            IDictionary <string, DbExpression> setClauses =
                DbCommandActionHelper.GetSetClauseExpressions(this.commandTree.SetClauses);

            // Collection for collection member bindings
            IList <MemberBinding> memberBindings = new List <MemberBinding>();
            TransformVisitor      transform      = new TransformVisitor(context.DbContainer.TypeConverter);

            // Initialize member bindings
            foreach (PropertyInfo property in table.EntityType.GetProperties())
            {
                Expression setter = null;

                // Check if member has set clause
                if (setClauses.ContainsKey(property.Name))
                {
                    setter = transform.Visit(setClauses[property.Name]);
                }

                // If setter was found, insert it
                if (setter != null)
                {
                    // Type correction
                    setter = ExpressionHelper.CorrectType(setter, property.PropertyType);

                    // Register binding
                    memberBindings.Add(Expression.Bind(property, setter));
                }
            }

            CreateAndInsertEntity(table, memberBindings, context.Transaction);

            return(1);
        }
예제 #5
0
        public DbDataReader ExecuteDataReader(ActionContext context)
        {
            FieldDescription[] returningFields = DbCommandActionHelper.GetReturningFields(this.commandTree.Returning);
            IList <IDictionary <string, object> > returningEntities = new List <IDictionary <string, object> >();

            ITable table = null;

            Expression expr             = DbCommandActionHelper.GetEnumeratorExpression(this.commandTree.Predicate, this.commandTree, context.DbContainer, out table);
            IQueryable entitiesToUpdate = DatabaseReflectionHelper.CreateTableQuery(expr, context.DbContainer.Internal);

            Type type = TypeHelper.GetElementType(table.GetType());

            // Collect the SetClause DbExpressions into a dictionary
            IDictionary <string, DbExpression> setClauses = DbCommandActionHelper.GetSetClauseExpressions(this.commandTree.SetClauses);

            // Collection for collection member bindings
            IList <MemberBinding> memberBindings = new List <MemberBinding>();

            TransformVisitor transform = new TransformVisitor(context.DbContainer.TypeConverter);

            // Setup context for the predicate
            ParameterExpression param = Expression.Parameter(type, "context");

            using (transform.CreateVariable(param, this.commandTree.Target.VariableName))
            {
                // Initialize member bindings
                foreach (PropertyInfo property in type.GetProperties())
                {
                    Expression setter = null;

                    // Check if member has set clause
                    if (setClauses.ContainsKey(property.Name))
                    {
                        setter = transform.Visit(setClauses[property.Name]);
                    }

                    // If setter was found, insert it
                    if (setter != null)
                    {
                        // Type correction
                        setter = ExpressionHelper.CorrectType(setter, property.PropertyType);

                        memberBindings.Add(Expression.Bind(property, setter));
                    }
                }
            }

            Expression updater =
                Expression.Lambda(
                    Expression.MemberInit(Expression.New(type), memberBindings),
                    param);

            IEnumerable <object> updatedEntities = DatabaseReflectionHelper.UpdateEntities(entitiesToUpdate, updater, context.Transaction);
            int affectedRecords = 0;

            foreach (object entity in updatedEntities)
            {
                affectedRecords++;
                Dictionary <string, object> returningEntity =
                    DbCommandActionHelper.CreateReturningEntity(context, returningFields, entity);

                returningEntities.Add(returningEntity);
            }

            return(new EffortDataReader(
                       returningEntities,
                       affectedRecords,
                       returningFields,
                       context.DbContainer));
        }