public void Visit(DownloadPageExpression expression)
        {
            var type = new CodeTypeReference("RuntimeTable", new CodeTypeReference("DownloadPage"));
            GenerateDownloadDeffered(expression, type, expression.Line.Line);

            _codeStack.Peek().Scope = new ScopeData<TableDescriptor> { Type = DownloadPage.Columns, CodeDomReference = type};
        }
Exemplo n.º 2
0
 public void Visit(DownloadPageExpression expression, CommonTree tree)
 {
     SetLine(expression, tree);
     Parent(tree).Children.Add(expression);
     VisitChildren(tree);
 }
        private void GenerateDownloadDeffered(DownloadPageExpression expression, CodeTypeReference returnType, int line)
        {
            var statementDomArg = VisitChild(expression.Statement);

            if (statementDomArg.Scope.CodeDomReference.BaseType == typeof(Table<>).Name)
            {
                if (statementDomArg.Tag != null)
                    ((Action)statementDomArg.Tag)(); //remove call to OnSelect
            }
            else if (statementDomArg.Scope.CodeDomReference.BaseType != typeof(string).FullName)
                Errors.Add(new DownloadRequireString(new Semantic.LineInfo(expression.Statement.Line.Line, expression.Statement.Line.CharacterPosition)));

            CodeMemberMethod method = new CodeMemberMethod();
            method.Name = "Download_" + statementDomArg.MethodIdentifier;
            method.ReturnType = returnType;

            _mainType.Type.Members.Add(method);
            GenerateCallStatement(method.Statements, line);

            CodeExpression argsExpression = null;

            int threadCount = 1;
            argsExpression = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(LazyDownloadArgs)), "CreateWebRequestArgs",
                    new CodeThisReferenceExpression(),
                    new CodePrimitiveExpression(line),
                    new CodePrimitiveExpression(threadCount),
                    statementDomArg.CodeExpression);

            if (expression.ThreadHint != null)
            {
                threadCount = expression.ThreadHint.ThreadCount;

                argsExpression = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(LazyDownloadArgs)), "CreateWebRequestArgs",
                    new CodeThisReferenceExpression(),
                    new CodePrimitiveExpression(line),
                    new CodePrimitiveExpression(threadCount),
                    statementDomArg.CodeExpression);
            }

            if(expression.JSTableHint != null)
            {
                argsExpression = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(LazyDownloadArgs)), "CreateSeleniumArgs",
                    new CodeThisReferenceExpression(),
                    new CodePrimitiveExpression(line),
                    new CodePrimitiveExpression(threadCount),
                    new CodePrimitiveExpression(expression.JSTableHint.CssWaitElement),
                    new CodePrimitiveExpression(expression.JSTableHint.CssTimeoutSeconds),
                    statementDomArg.CodeExpression);
            }

            //if in select context pick the lazy download type~
            var downloadType = Scope.Current.IsSelect ? "SelectDownloadTable" : "VariableDownloadTable";

            method.Statements.Add(new CodeMethodReturnStatement(new CodeObjectCreateExpression(new CodeTypeReference(downloadType),
                argsExpression)));

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

            _codeStack.Peek().CodeExpression = methodcall;
        }