Ejemplo n.º 1
0
        public List <CodeFile> GetReferences(FileSearcher fileSearcher)
        {
            var    files   = new List <CodeFile>();
            string content = GetContents();

            var componentRefs = GetComponentReferences(content);

            foreach (var comp in componentRefs)
            {
                string   relativePath = comp.RelativePath.Replace('.', FileSystem.Path.DirectorySeparatorChar) + ".cfc";
                CodeFile foundFile    = fileSearcher.LocateFile(relativePath);
                if (foundFile != null)
                {
                    files.Add(foundFile);
                }
            }

            var includeRefs      = GetIncludedFiles(content);
            var currentDirectory = FileSystem.Path.GetDirectoryName(FileName);

            foreach (var include in includeRefs)
            {
                CodeFile foundFile = null;
                if (FileSystem.Path.IsPathRooted(include.RelativePath))
                {
                    foundFile = fileSearcher.LocateFile(include.RelativePath.Substring(1, include.RelativePath.Length - 1));
                }
                else
                {
                    string path = FileSystem.Path.Combine(currentDirectory, include.RelativePath);
                    if (FileSystem.File.Exists(path))
                    {
                        foundFile = new CodeFile(path, FileSystem);
                    }
                }

                if (foundFile != null)
                {
                    files.Add(foundFile);
                }
            }//foreach included reference

            //Find Application File
            var appFile = fileSearcher.GetApplicationFile(FileName);

            if (appFile != null)
            {
                files.Add(appFile);
            }

            return(files);
        }
Ejemplo n.º 2
0
        private void Run()
        {
            var fileSystem = new FileSystem();

            string webRoot = "";

            do
            {
                System.Console.Write("Enter the Web Root directory: ");
                webRoot = System.Console.ReadLine();
                if (!fileSystem.Directory.Exists(webRoot))
                {
                    System.Console.WriteLine("Directory does not exist.");
                }
            } while (!fileSystem.Directory.Exists(webRoot));

            var searcher = new FileSearcher(fileSystem, webRoot);

            string input = "";

            do
            {
                System.Console.Write("Enter a root directory, or q to quit: ");
                input = System.Console.ReadLine();

                if (input != "q")
                {
                    if (fileSystem.Directory.Exists(input))
                    {
                        searcher.AddRootDirectory(input);
                    }
                    else
                    {
                        System.Console.WriteLine("Directory does not exist.");
                    }
                }
            } while (input != "q");

            IEnumerable <CodeFile> files = searcher.GetAllFiles();

            foreach (CodeFile file in files)
            {
                var node = new Node(file);
                _graph.Nodes.Add(node);
                _filesToProcess.Enqueue(node);
            }

            while (_filesToProcess.Count > 0)
            {
                Node node = _filesToProcess.Dequeue();
                if (!_processedNodes.Contains(node) && node.CodeFile.Exists)
                {
                    var references = node.CodeFile.GetReferences(searcher);
                    foreach (var reference in references)
                    {
                        var  refNode = new Node(reference);
                        Node foundNode;
                        if (_graph.Nodes.TryGetValue(refNode, out foundNode))
                        {
                            node.Edges.Add(foundNode);
                        }
                        else
                        {
                            System.Console.Error.WriteLine("Unknown file " + refNode.CodeFile.FileName);
                        }
                    }
                    _processedNodes.Add(node);
                }
            }

            System.Console.WriteLine("Found " + _graph.Nodes.Count + " nodes.");

            System.Console.Write("Enter output file: ");
            string outputFile = System.Console.ReadLine();
            string data       = _graph.ToJson();

            fileSystem.File.WriteAllText(outputFile, data);

            System.Console.WriteLine("Press Enter to Exit...");
            System.Console.ReadKey();
        }