public void Visit(InsertIntoDirectoryStatement statement)
        {
            if (statement.Select.Args.Length != 2) //can only select one thing into a directory
            {
                Errors.Add(new OnlyTwoSelectParamForDirectory(new Semantic.LineInfo(statement.Line.Line, statement.Line.CharacterPosition)));
                return;
            }

            var domArg = VisitChild(statement.Select);

            CodeMemberMethod method = new CodeMemberMethod();
            method.Name = "InsertIntoDir_" + domArg.MethodIdentifier;
            method.Attributes = MemberAttributes.Private;

            ((Action)domArg.Tag)();

            //needs to foreach around the returned table from select like the other inserts

            method.Statements.Add(new CodeVariableDeclarationStatement(domArg.Scope.CodeDomReference,
                "resultRows",
                domArg.CodeExpression));

            var cast = new CodeCastExpression(typeof(string),
                new CodeIndexerExpression(new CodeIndexerExpression(new CodeVariableReferenceExpression("resultRows"),
                    new CodePrimitiveExpression(0)), new CodePrimitiveExpression(0)));

            method.Statements.Add(new CodeVariableDeclarationStatement(typeof(string), "filename", cast));

            cast = new CodeCastExpression(typeof(byte[]),
                new CodeIndexerExpression(new CodeIndexerExpression(new CodeVariableReferenceExpression("resultRows"),
                    new CodePrimitiveExpression(0)), new CodePrimitiveExpression(1)));

            method.Statements.Add(new CodeVariableDeclarationStatement(typeof(byte[]), "bytes", cast));

            var directoryArgs = VisitChild(statement.Directory);

            method.Statements.Add(new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("bytes"), "WriteFile",
                directoryArgs.CodeExpression, new CodeVariableReferenceExpression("filename")));

            _mainType.Type.Members.Add(method);

            var methodcall = new CodeMethodInvokeExpression(
                new CodeMethodReferenceExpression(null, method.Name));

            _codeStack.Peek().ParentStatements.Add(methodcall);
            _codeStack.Peek().CodeExpression = methodcall;
        }
Пример #2
0
 public void Visit(InsertIntoDirectoryStatement statement, CommonTree tree)
 {
     Parent(tree).Children.Add(statement);
     SetLine(statement, tree);
     VisitChildren(tree);
 }