Esempio n. 1
0
        public static EngineParameter ParseParameter(string[] args)
        {
            string includePath = null;
            string outputFile = null;
            List<string> inputFileList = new List<string>();

            for (int i = 0; i < args.Length; i++) {
                if (args[i] == "-i") {
                    i++;
                    if (args.Length > i) {
                        includePath = args[i];
                    } else {
                        throw new Exception("Include path is not specified with switch -i");
                    }
                } else
                if (args[i] == "-o") {
                    i++;
                    if (args.Length > i) {
                        outputFile = args[i];
                    } else {
                        throw new Exception("Output file is not specified with switch -o");
                    }
                }  else
                if (args[i] == "-p") {
                    i++;
                    if (args.Length > i) {
                        outputFile = args[i];
                    } else {
                        throw new Exception("Source File scan pattern is not specified with switch -p");
                    }
                } else {
                    for (int j = i; j < args.Length; j++) {
                        inputFileList.Add(args[j]);
                    }
                }
            }

            if (outputFile == null) {
                throw new Exception("No output file specified.");
            }

            if (inputFileList.Count == 0) {
                throw new Exception("No input file specified.");
            }

            EngineParameter param = new EngineParameter();
            param.IncludePath = includePath;
            param.OutputFile = outputFile;
            param.InputFiles = inputFileList;

            return param;
        }
Esempio n. 2
0
        public static string Execute(EngineParameter param)
        {
            Dictionary<string, FileEntry> _entryTable = new Dictionary<string, FileEntry>();
            List<string> allInputFiles = PathUtil.CheckAndConvertDirectoryToFiles(param.InputFiles,param.FilePattern);

            //Create Graph
            foreach (string inputFile in allInputFiles) {
                CreateReferenceGraph(inputFile, param, null, _entryTable);
            }

            //Loop Reference Check
            string foundLoopAt = null;
            Dictionary<string,int> traverseBag = new Dictionary<string,int>();
            foreach (string inputFile in allInputFiles) {
                foundLoopAt = CheckLoopReference(inputFile, _entryTable, null, traverseBag);
                if (foundLoopAt != null) {
                    break;
                }
                traverseBag.Clear();
            }
            if (foundLoopAt != null) {
                throw new Exception("Found Loop Reference at " + foundLoopAt);
            }

            //Analyze Link By Adding Weight
            foreach (string inputFile in allInputFiles) {
                CalculateWeight(inputFile, 1, _entryTable);
            }

            //Sort File Entry
            List<FileEntry> allEntry = new List<FileEntry>(_entryTable.Values);
            allEntry.Sort();

            //Generate Output
            StringBuilder outputBuilder = new StringBuilder();
            foreach (FileEntry entry in allEntry) {
                string content = File.ReadAllText(entry.Path);
                outputBuilder.AppendLine(content);
            }

            return outputBuilder.ToString();
        }
Esempio n. 3
0
        private static void CreateReferenceGraph(string file, EngineParameter param, FileEntry referer, Dictionary<string, FileEntry> entryTable)
        {
            if (entryTable.ContainsKey(file)) {
                if (referer != null) {
                    FileEntry referencedEntry = entryTable[file];
                    referer.ReferTo.Add(referencedEntry);
                }
            } else {
                FileEntry entry = new FileEntry();
                entry.Path = file;
                entryTable[file] = entry;

                if (referer != null) {
                    referer.ReferTo.Add(entry);
                }

                List<string> allReferenced = PathUtil.GrabAllReferenced(file, param.ReferencePrefix);
                foreach (string aRef in allReferenced) {
                    string aRefFullPath = PathUtil.GetFullPath(file, aRef, param.IncludePath);
                    CreateReferenceGraph(aRefFullPath, param, entry, entryTable);
                }
            }
        }