public static void LoadByTxtFile(string folderPath) { string txtFilePath = IOFile.CompleteFileNameInput("AllSource.txt"); Logger.Log("Load from txt file: " + txtFilePath); string content = ""; try { using (StreamReader sr = new StreamReader(txtFilePath)) { content = sr.ReadToEnd(); } } catch (Exception e) { Logger.Log("Txt file may not exist."); Logger.Log(e); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } var tree = CSharpSyntaxTree.ParseText(content); var model = GetSemanticInfo(tree); var treeAndModelDic = new Dictionary <SyntaxTree, SemanticModel>(); treeAndModelDic.Add(tree, model); var compilation = BuildCompilation(new List <SyntaxTree> { tree }); CodeAnalyzer.AnalyzeAllTrees(treeAndModelDic, compilation); }
public static void LoadByFolder(string folderPath) { Logger.Log("Loading from folder: " + folderPath); IEnumerable <string> FileNames = Directory.EnumerateFiles(folderPath, "*.cs", SearchOption.AllDirectories).Where(file => !file.Contains("Test")); int numFiles = FileNames.Count(); Logger.Log("Loading " + numFiles + " *.cs files."); // parallelization var treeAndModelList = FileNames.AsParallel() .Select(fileName => LoadSourceFile(fileName)) .ToList(); var treeAndModelDic = new Dictionary <SyntaxTree, SemanticModel>(); foreach (var treeAndModel in treeAndModelList) { treeAndModelDic.Add(treeAndModel.Item1, treeAndModel.Item2); } var compilation = BuildCompilation(treeAndModelDic.Keys.ToList()); Logger.Log("Compilation built."); CodeAnalyzer.AnalyzeAllTrees(treeAndModelDic, compilation); }