Exemplo n.º 1
0
        public void loadSourceFiles(List <string> filesToLoad)
        {
            TopProgressBar.maximum(filesToLoad.size());
            int count   = 0;
            int total   = filesToLoad.size();
            var o2Timer = new O2Timer("{0} files processed in".format(total)).start();

            foreach (var file in filesToLoad)
            {
                AstData.loadFile(file);
                TopProgressBar.increment(1);
                //statusMessage("loading source code files: {0}/{1} : {2}".format(count++, total, file.fileName()));
                statusMessage("loading source code files: {0}/{1}".format(count++, total));
            }
            //statusMessage(o2Timer.stop().TimeSpanString);
            o2Timer.stop().TimeSpanString.info();;
            //calculateMethodsStreams();
            //
        }
        public void build_CreateAllMethodStreamsTab(Control hostControl)
        {
            var allMethodStreamsPanel = hostControl.add_1x1("Options", "All Method Streams", false, 50);

            var sourceCode = allMethodStreamsPanel[1].add_SourceCodeViewer();            //add_MethodStreamViewer();
            var treeView   = sourceCode.insert_Left <TreeView>(300)
                             .showSelection()
                             .sort()
                             .afterSelect <string>(
                (filePath) => sourceCode.open(filePath));

            var targerFolder = PublicDI.config.getTempFolderInTempDirectory("_AllMethodStreams");

            allMethodStreamsPanel[0].parent <SplitContainer>().borderNone();
            var optionsPanel = allMethodStreamsPanel[0].parent().clear();
            var progressBar  = optionsPanel.add_ProgressBar(25, 0).align_Right(optionsPanel);

            optionsPanel.add_LabelAndTextAndButton("Target Directory", targerFolder, "Create",
                                                   (text) => {
                AstData.createAllMethodsStreams(text, progressBar, null);
                foreach (var file in targerFolder.files())
                {
                    treeView.add_Node(file.fileName(), file);
                }
                treeView.selectFirst();
            });

            progressBar.onDrop(
                (fileOrFolder) => {
                if (fileOrFolder.fileExists())
                {
                    AstData.loadFile(fileOrFolder);
                }
                else
                {
                    AstData.dispose();
                    AstData = new O2MappedAstData();
                    AstData.loadFiles(fileOrFolder.files("*.cs", true));
                }
            });
            //tabPages.Add(tabControl.add_Tab("Step 2: Create Code Streams"));
            //tabPages.Add(tabControl.add_Tab("Step 1: Create Final Findings"));


            //Create all Method Streams


            //var controls = tabPages;
            //var MethodStreamPanel  = controls[0].add_1x1("Current ","MethodStreams", false);

            /*
             * var CodeStreamPanel = controls[1].add_1x1("Create CodeStreams", "CodeStreams", false);
             * var FindingsPanel = controls[2].add_1x1("Create Findings", "Final Findings",false);
             *
             * // MethodStreamPanel
             * MethodStreamScript = MethodStreamPanel[0].add_Script(false);
             * MethodStreamViewer = MethodStreamPanel[1].add_MethodStreamViewer();
             *
             * //CodeStreamPanel
             * CodeStreamScript = CodeStreamPanel[0].add_Script(false);
             * var CodeStreamScriptResult = CodeStreamPanel[1].add_1x1("Code Streams", "Raw Findings", true, CodeStreamScript.width()/2);
             *
             * CodeStreamViewer =  CodeStreamScriptResult[0].add_CodeStreamViewer();
             * RawFindingsViewer = CodeStreamScriptResult[1].add_FindingsViewer();
             *
             *
             * //RawFindingsViewer = FindingsPanel[1].add_FindingsViewer();
             * //CodeStreamViewer = MethodStreamPanel[1].add_CodeStreamViewer();
             *
             *
             * // FindingsPanel
             * FindingsScript = FindingsPanel[0].add_Script(false);
             * FinalFindingsViewer = FindingsPanel[1].add_FindingsViewer();
             *
             * //var controls2 = host[1].add_1x1x1(true);
             *
             * // extra vars
             *
             * // script parameters
             * var scriptParameters = new Dictionary<string,object>();
             * scriptParameters.Add("methodStreamViewer", MethodStreamViewer);
             * scriptParameters.Add("codeStreamViewer", CodeStreamViewer);
             *
             * scriptParameters.Add("rawFindingsViewer", RawFindingsViewer);
             * scriptParameters.Add("finalFindingsViewer", FinalFindingsViewer);
             *
             * scriptParameters.Add("astData", AstData);
             *
             * MethodStreamScript.InvocationParameters.AddRange(scriptParameters);
             * CodeStreamScript.InvocationParameters.AddRange(scriptParameters);
             * FindingsScript.InvocationParameters.AddRange(scriptParameters);
             *
             */
        }
        public void buildGui()
        {
            //..clear();
            var topPanel = this.add_1x1("AST INode Value", "Source Code", true, 400);

            CodeViewer = topPanel[1].add_SourceCodeViewer();

            AstValueTreeView = topPanel[0].add_TreeView()
                               .sort()
                               .showSelection()
                               .beforeExpand <List <INode> >(
                (selectedNode, nodes) => {
                selectedNode.add_Nodes(nodes);
            });


            AstTypeTreeView = topPanel[0].insert_Left <GroupBox>(200)
                              .set_Text("AST INode Type")
                              .add_TreeView()
                              .sort()
                              .showSelection()
                              .afterSelect <List <INode> >(
                (iNodes) => {
                showINodes(iNodes);
            });


            INodeFilter_TextBox = AstTypeTreeView.insert_Above(40, "Filter").add_TextBox("Filter", "")
                                  .onTextChange_AlertOnRegExFail()
                                  .onEnter((value) => {
                INodeTypeFilter = value;
                loadDataInGui();
            });

            //nodeFilterTextBox.onTextChange_AlertOnRegExFail();
            //nodeTypeTextBox.onTextChange_AlertOnRegExFail();

            SelectedINodeFilter_TextBox = AstValueTreeView.insert_Above(40, "Search on selected INode Type").add_TextBox("Filter", "")
                                          .onTextChange_AlertOnRegExFail()
                                          .onEnter(
                (value) => {
                INodeValueFilter = value;
                showINodes(null);
            });
            AllINodesFilter_TextBox = AstValueTreeView.insert_Above(40, "Search on ALL INodes Type").add_TextBox("Filter", "")
                                      .onTextChange_AlertOnRegExFail()
                                      .onEnter(
                (value) => {
                INodeValueFilter = value;
                showINodes(AstData.iNodes());
            });



            AstTypeTreeView.onDrop(
                (fileOrFolder) => {
                if (fileOrFolder.fileExists())
                {
                    AstData.loadFile(fileOrFolder);
                }
                else
                {
                    AstData.loadFiles(fileOrFolder.files(true, "*.cs", "*.vb"));
                }
                loadDataInGui();
            });

            SourceCodeLines = CodeViewer.insert_Below(200, "Source Code Lines").add_TreeView().sort();

            AstData.afterSelect_ShowInSourceCodeEditor(AstValueTreeView, CodeViewer.editor());
            AstData.afterSelect_ShowInSourceCodeEditor(SourceCodeLines, CodeViewer.editor());
            AstValueTreeView.afterSelect <List <INode> >(
                (iNodes) => {
                SourceCodeLines.clear();
                var addedLines = new List <string>();
                foreach (var iNode in iNodes)
                {
                    var line = iNode.StartLocation.Line;
                    if (line > 0)
                    {
                        var file = AstData.file(iNode);
                        if (file.valid())
                        {
                            var addedLine = "{0}:{1}".format(file, line);
                            if (addedLines.contains(addedLine).isFalse())
                            {
                                addedLines.add(addedLine);
                                var fileContents = file.fileContents();
                                if (fileContents.valid())
                                {
                                    var lineText = fileContents.split_onLines()[line - 1];
                                    var location = "[{0}:{1}]      {2} ".format(file.fileName(), line, file);
                                    SourceCodeLines.add_Node(lineText, iNode)
                                    .add_Node(location);
                                }
                            }
                        }
                    }
                }
                //show.info(iNodes[0]);
                //SourceCodeLines.add_Nodes(iNodes, (iNode)=>iNode.sourceCode);
                //.showDetails();
                //"treeNode selected: {0}".info(tag.typeFullName());
            });
        }