static void Main(string[] args) { string inputMode = args[0]; string filePath = args[1]; if (filePath.EndsWith("\\")) { filePath = filePath.Remove(filePath.LastIndexOf('\\')); } IOFile.InputFolderPath = Path.GetFullPath(filePath); IOFile.OutputFolderPath = Directory.GetCurrentDirectory(); Logger.Initialize(); DateTime StartTime = DateTime.Now; Logger.Log("Current directory is: " + IOFile.OutputFolderPath.ToString()); Config.Load(IOFile.CompleteFileNameInput("Config.txt")); // traverse all the code folder for pattern check CodeWalker walker = new CodeWalker(); walker.LoadByInputMode(inputMode, filePath); DateTime EndTime = DateTime.Now; Logger.Log("All done. Elapsed time: " + (EndTime - StartTime).ToString()); Logger.Log("Press any key to terminate!"); Logger.Close(); //Console.ReadKey(); }
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); }