private void DisplayHttpContextWalkerVB(wucCodeExplorerContext codeExplorerContext, string context) { StringBuilder sb = new StringBuilder(); Dictionary <string, Int32> matches = new Dictionary <string, Int32>(); var sourceCode = ""; // If a source file has been specified use it if (codeExplorerContext.teSourceFile.Text.Length > 0) { string fileNameAndPath = codeExplorerContext.teSourceFile.Text; if (!File.Exists(fileNameAndPath)) { sb.AppendLine(string.Format("File ({0}) does not exist. Check path and name.", fileNameAndPath)); goto PrematureExitBummer; } if ((Boolean)CodeExplorer.configurationOptions.ceListImpactedFilesOnly.IsChecked) { sb.AppendLine("Would Process these files ...."); sb.AppendLine(string.Format(" {0}", fileNameAndPath)); } else { sb.AppendLine(string.Format("Processing ({0}) ...", fileNameAndPath)); using (var sr = new StreamReader(fileNameAndPath)) { sourceCode = sr.ReadToEnd(); } var tree = VisualBasicSyntaxTree.ParseText(sourceCode); string pattern = string.Empty; VNCSW.VB.HttpContextCurrentInvocationExpression walker = null; walker = new VNCCA.SyntaxWalkers.VB.HttpContextCurrentInvocationExpression(context); walker.Messages = sb; walker.Matches = matches; walker.Visit(tree.GetRoot()); } } else { // Otherwise, go see if one or more files has been selected if (codeExplorerContext.cbeSourceFile.SelectedItems.Count > 0) { if ((Boolean)CodeExplorer.configurationOptions.ceListImpactedFilesOnly.IsChecked) { sb.AppendLine("Would Process these files ...."); } foreach (XElement file in codeExplorerContext.cbeSourceFile.SelectedItems) { string filePath = codeExplorerContext.teSourcePath.Text + wucCodeExplorerContext.GetFilePath(file); if (!File.Exists(filePath)) { sb.AppendLine(string.Format("ERROR File ({0}) does not exist. Check config file", filePath)); continue; } if ((Boolean)CodeExplorer.configurationOptions.ceListImpactedFilesOnly.IsChecked) { sb.AppendLine(string.Format(" {0}", filePath)); } else { sb.AppendLine(string.Format("Processing ({0}) ...", filePath)); using (var sr = new StreamReader(filePath)) { sourceCode = sr.ReadToEnd(); } var tree = VisualBasicSyntaxTree.ParseText(sourceCode); string pattern = string.Empty; VNCSW.VB.HttpContextCurrentInvocationExpression walker = null; walker = new VNCSW.VB.HttpContextCurrentInvocationExpression(context); walker.Messages = sb; walker.Matches = matches; walker.Visit(tree.GetRoot()); } } } } sb.AppendLine("Summary"); foreach (var item in matches.OrderBy(v => v.Key).Select(k => k.Key)) { sb.AppendLine(string.Format("Count: {0,3} {1} ", matches[item], item)); } PrematureExitBummer: CodeExplorer.teSourceCode.Text = sb.ToString(); }
public static void ProcessOperation(VNCCA.Types.SearchTreeCommand searchTreeCommand, User_Controls.wucCodeExplorer codeExplorer, User_Controls.wucCodeExplorerContext codeExplorerContext, User_Controls.wucConfigurationOptions configurationOptions) { long startTicks = Log.UTILITY("Enter", Common.LOG_APPNAME); StringBuilder sb = new StringBuilder(); codeExplorer.teSourceCode.Clear(); codeExplorer.teSourceCode.InvalidateVisual(); //CodeExplorer.teSourceCode.Text = ""; codeExplorer.teSyntaxNode.Clear(); codeExplorer.teSyntaxToken.Clear(); codeExplorer.teSyntaxTrivia.Clear(); codeExplorer.teSyntaxStructuredTrivia.Clear(); codeExplorer.teSummary.Clear(); codeExplorer.teSummaryCRCToString.Clear(); codeExplorer.teSummaryCRCToFullString.Clear(); string projectFullPath = codeExplorerContext.teProjectFile.Text; var filesToProcess = codeExplorerContext.GetFilesToProcess(); Dictionary <string, Int32> matches = new Dictionary <string, int>(); Dictionary <string, Int32> crcMatchesToString = new Dictionary <string, int>(); Dictionary <string, Int32> crcMatchesToFullString = new Dictionary <string, int>(); if (filesToProcess.Count > 0) { if ((Boolean)configurationOptions.ceListImpactedFilesOnly.IsChecked) { sb.AppendLine("Would Search these files ...."); } foreach (string filePath in filesToProcess) { if ((Boolean)configurationOptions.ceListImpactedFilesOnly.IsChecked) { sb.AppendLine(string.Format(" {0}", filePath)); } else { StringBuilder sbFileResults = new StringBuilder(); var sourceCode = ""; using (var sr = new System.IO.StreamReader(filePath)) { sourceCode = sr.ReadToEnd(); } // // This is where the action happens // SyntaxTree tree = VisualBasicSyntaxTree.ParseText(sourceCode); VNCCA.SearchTreeCommandConfiguration searchTreeCommandConfiguration = new VNCCA.SearchTreeCommandConfiguration(); searchTreeCommandConfiguration.Results = sbFileResults; searchTreeCommandConfiguration.SyntaxTree = tree; searchTreeCommandConfiguration.Matches = matches; searchTreeCommandConfiguration.CRCMatchesToString = crcMatchesToString; searchTreeCommandConfiguration.CRCMatchesToFullString = crcMatchesToFullString; sbFileResults = searchTreeCommand(searchTreeCommandConfiguration); if ((bool)configurationOptions.ceAlwaysDisplayFileName.IsChecked || (sbFileResults.Length > 0)) { sb.AppendLine("Searching " + filePath); } sb.Append(sbFileResults.ToString()); } } } else { sb.AppendLine("No files selected to process"); } if (!(Boolean)configurationOptions.ceDisplayResults.IsChecked) { // If only want to see the summary ... sb.Clear(); } codeExplorer.teSourceCode.Text = sb.ToString(); if ((Boolean)configurationOptions.ceDisplaySummary.IsChecked) { StringBuilder summary = new StringBuilder(); // Add information from the matches dictionary summary.AppendLine("\n*** Summary ***\n"); foreach (var item in matches.OrderBy(v => v.Key).Select(k => k.Key)) { if (matches[item] >= configurationOptions.sbDisplaySummaryMinimum.Value) { summary.AppendLine(string.Format("Count: {0,3} {1} ", matches[item], item)); } } codeExplorer.teSummary.Text = summary.ToString(); if ((Boolean)configurationOptions.ceDisplayCRC32.IsChecked) { summary.Clear(); summary.AppendLine("\n*** CRC ToString Summary *** \n"); foreach (var item in crcMatchesToString.OrderBy(v => v.Key).Select(k => k.Key)) { if (crcMatchesToString[item] >= configurationOptions.sbDisplaySummaryMinimum.Value) { summary.AppendLine(string.Format("Count: {0,3} {1} ", crcMatchesToString[item], item)); } } codeExplorer.teSummaryCRCToString.Text = summary.ToString(); summary.Clear(); summary.AppendLine("\n*** CRC ToFullString Summary ***\n"); foreach (var item in crcMatchesToFullString.OrderBy(v => v.Key).Select(k => k.Key)) { if (crcMatchesToFullString[item] >= configurationOptions.sbDisplaySummaryMinimum.Value) { summary.AppendLine(string.Format("Count: {0,3} {1} ", crcMatchesToFullString[item], item)); } } codeExplorer.teSummaryCRCToString.Text = summary.ToString(); } } Log.UTILITY("Exit", Common.LOG_APPNAME, startTicks); }