static Index BuildIndex() { var path = //"..\\.."; //@"C:\Treserva\Dev\Prestanda1\S3\Arende\Source\Process"; //@"C:\Treserva\Dev\Prestanda1\S3\Arende\Source\"; @"C:\Treserva\Dev\Prestanda1\S3\"; var pattern = "*.cs"; var regex = new Regex( //@"(?:(?<=(?:class|namespace)\s+?)[^\s:{]+?(?=[\s:{]))|(?:())", //"class", @"(?:(?<=(?:class|namespace)\s+?)(?<identifier>[a-zA-Z_][\w_]*?)(?=[\s:{]))|(?:(?<=(?<before>[{};]\s*?)(?<type>(?:[a-zA-Z_][\w_]*?\.)*?(?:[a-zA-Z_][\w_]*?)(?:\<[^\>]+?\>)?)\s+?)(?<identifier>[a-zA-Z_][\w_]*?)(?=(?<after>\s*?[;=])))", RegexOptions.Compiled | RegexOptions.Singleline); var indexBuilder = new RegexIndexBuilder(path, pattern, regex); var index = indexBuilder.BuildIndex(null); return index; }
private void RebuildIndex() { rebuildIndexButton.IsEnabled = false; rebuildIndexProgressBar.Value = 0; rebuildIndexProgressBar.IsEnabled = true; var worker = new BackgroundWorker() { WorkerReportsProgress = true }; worker.DoWork += delegate(object s, DoWorkEventArgs args) { var indexBuilder = args.Argument as IndexBuilder; args.Result = indexBuilder.BuildIndex(progress => worker.ReportProgress(progress)); }; worker.RunWorkerCompleted += (s, args) => { this.index = args.Result as Index; //index.SetSearcher(new BinarySearcher()); index.SetSearcher(new RegexSearcher()); rebuildIndexProgressBar.IsIndeterminate = false; rebuildIndexProgressBar.IsEnabled = false; rebuildIndexButton.IsEnabled = true; }; worker.ProgressChanged += (s, args) => { rebuildIndexProgressBar.Value = args.ProgressPercentage; rebuildIndexProgressBar.IsIndeterminate = args.ProgressPercentage >= 100; }; try { var regex = new Regex(indexPatternTextBox.Text, RegexOptions.Compiled | RegexOptions.Singleline); var ib = new RegexIndexBuilder(folderPathTextBox.Text, filePatternTextBox.Text, regex); worker.RunWorkerAsync(ib); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); rebuildIndexButton.IsEnabled = true; } }