public IEnumerable <FindResult> Find(string searchString, bool caseSensitive, bool wholeWords, bool regex, string[] fileMasks) { var shell = IoC.Get <IShell>(); var searchStrategy = SearchStrategyFactory.Create(searchString, !caseSensitive, wholeWords, regex ? SearchMode.RegEx : SearchMode.Normal); if (shell.CurrentSolution == null) { return(Enumerable.Empty <FindResult>()); } var files = shell.CurrentSolution.Projects.SelectMany(p => p.SourceFiles); if (fileMasks != null && fileMasks.Count() > 0) { // Construct corresponding regular expression. Note Regex.Escape! var options = RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase; var patterns = fileMasks .Select(f => new Regex("^" + Regex.Escape(f).Replace("\\*", ".*") + "$", options)) .ToArray(); files = files.Where(f => patterns.Any(p => p.IsMatch(f.FilePath))); } return(files.SelectMany(f => GetResults(searchStrategy, f))); }
public Dictionary <int, string> GetManualResult(string text, bool regexMode, bool ignoreCaseMode) { Dictionary <int, string> returnValue = new Dictionary <int, string>(); ISearchStrategy strategy = SearchStrategyFactory.Create(text, ignoreCaseMode, false, regexMode ? SearchMode.RegEx : SearchMode.Normal); GetSearchResult(ref returnValue, strategy); return(returnValue); }
public void SearchStrategyFactoryGetStrategy_GivenInputGoogle_ShouldReturnGoogleStrategy() { var sut = new SearchStrategyFactory(); var strategy = sut.GetStrategy(SearchEngines.GOOGLE); Assert.IsType <GoogleSearchStrategy>(strategy); }
public void UpdateSearch() { // only reset as long as there are results // if no results are found, the "no matches found" message should not flicker. // if results are found by the next run, the message will be hidden inside DoSearch ... strategy = SearchStrategyFactory.Create(SearchPattern ?? "", true, false, SearchMode.Normal); OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, true, false, false)); DoSearch(true); }
public ThreadBuilder(Graph g, SearchStrategyFactory strategyFactory, List <Tuple <long, long> > ODs, double radius, int threads, EmailSender emailSender = null) { this._graph = g; this.StrategyFactory = strategyFactory; this.ODs = ODs; this.Radius = radius; this.ThreadsQuantity = Math.Max(Math.Min(Math.Min(ODs.Count, threads), Environment.ProcessorCount), 1); this.emailSender = emailSender; // new Thread(new ThreadStart(ThreadManager)) }
void UpdateSearch() { // only reset as long as there are results // if no results are found, the "no matches found" message should not flicker. // if results are found by the next run, the message will be hidden inside DoSearch ... if (_renderer.CurrentResults.Any()) { _messageView.IsOpen = false; } _strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal); OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords)); DoSearch(true); }
void FindNextButtonClicked(object sender, EventArgs e) { try { WritebackOptions(); var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(true) : null); var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode); lastMatch = SearchManager.FindNext(strategy, location); SearchManager.SelectResult(lastMatch); Focus(); } catch (SearchPatternException ex) { MessageService.ShowError(ex.Message); } }
public override void Run() { if (SearchOptions.CurrentFindPattern.Length > 0) { var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(true) : null); var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode); var result = SearchManager.FindNext(strategy, location); SearchManager.SelectResult(result); } else { Find find = new Find(); find.Run(); } }
void BookmarkAllButtonClicked(object sender, EventArgs e) { WritebackOptions(); using (var monitor = WorkbenchSingleton.StatusBar.CreateProgressMonitor()) { monitor.TaskName = StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}"); try { var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(false) : null); var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode); var results = SearchManager.FindAllParallel(strategy, location, monitor); SearchManager.MarkAll(results); } catch (SearchPatternException ex) { MessageService.ShowError(ex.Message); } catch (OperationCanceledException) {} } }
public static List <User> performeTreesSearchForPeople(string coreId, int depth, Dictionary <string, string> criteria, ISearchSubscriber subscriber, bool checkFriends) { ISearchProfile sProfile = SearchProfileFactory.createSearchProfile(SearchType.People); strategy = SearchStrategyFactory.createTreeSearchStrategy(SearchStrategyType.BalancedTrees); strategy.CoreId = coreId; strategy.OnFirstStep = true; strategy.Depth = depth; sProfile.Criteria = criteria; sProfile.CheckFriends = checkFriends; List <IData> targets = strategy.search(sProfile, subscriber); return(targets.Cast <User>().ToList()); }
/// <summary> /// Causes the background renderer to draw. /// </summary> /// <param name="textView"></param> /// <param name="drawingContext"></param> public void Draw(TextView textView, DrawingContext drawingContext) { if (String.IsNullOrWhiteSpace(editor.SelectedText) || !editor.SelectedText.All(Char.IsLetterOrDigit)) { return; } ISearchStrategy strategy = SearchStrategyFactory.Create(editor.SelectedText, false, true, SearchMode.Normal); foreach (ISearchResult result in strategy.FindAll(textView.Document, 0, textView.Document.TextLength)) { BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder() { CornerRadius = 1 }; builder.AddSegment(textView, result); drawingContext.DrawGeometry(BrushStyle, PenStyle, builder.CreateGeometry()); } }
void FindAllButtonClicked(object sender, EventArgs e) { WritebackOptions(); var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(false) : null); ISearchStrategy strategy; try { strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode); } catch (SearchPatternException ex) { MessageService.ShowError(ex.Message); return; } // No using block for the monitor; it is disposed when the asynchronous search finishes var monitor = WorkbenchSingleton.StatusBar.CreateProgressMonitor(); monitor.TaskName = StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}"); var results = SearchManager.FindAllParallel(strategy, location, monitor); SearchManager.ShowSearchResults(SearchOptions.FindPattern, results); }
public override void FixtureSetUp() { base.FixtureSetUp(); SD.Services.AddService(typeof(IWorkbench), MockRepository.GenerateStub <IWorkbench>()); // Set up SearchOptions required by the BruteForceSearchStrategy. SearchOptions.CurrentFindPattern = "foo"; SearchOptions.MatchCase = false; SearchOptions.MatchWholeWord = false; // Create the document to be searched. var doc = new ReadOnlyDocument("foo"); var location = MockRepository.GenerateStub <SearchLocation>(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, null); location.Stub(l => l.GenerateFileList()).Return(new[] { new FileName(@"C:\Temp\test.txt") }); // Search the document. var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode); result = SearchManager.FindNext(strategy, location); }
void ReplaceAllButtonClicked(object sender, EventArgs e) { WritebackOptions(); int count = -1; try { AsynchronousWaitDialog.RunInCancellableWaitDialog( StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}"), null, monitor => { var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(true) : null); var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode); var results = SearchManager.FindAll(strategy, location, monitor); count = SearchManager.ReplaceAll(results, SearchOptions.ReplacePattern, monitor.CancellationToken); }); if (count != -1) { SearchManager.ShowReplaceDoneMessage(count); } } catch (SearchPatternException ex) { MessageService.ShowError(ex.Message); } }
static void Main(string[] args) { var defaultThreadNumber = Environment.ProcessorCount; var file_path = Constants.PATH_GRAPH; var ods_path = Constants.PATH_ODs; var logToFile = Constants.LOG_TO_FILE; EmailSender emailSender = null; IConfiguration config = GetConfig(); string helpMessage = "====================> Region search program <====================\n"; helpMessage += "\n==========> Description <==========\n"; helpMessage += "\tThis program it's for research purpose and search the best path between two informed regions (set of nodes)\n"; helpMessage += "\tusing the informed strategy and the graph also informed. It is also needed the radius to build the region and the number of\n"; helpMessage += "\tpairs of origin and destinations to make data to the research. May also be informed the number of threads of execution\n"; helpMessage += "\tto run the program (the default depends on the machine that is running this script)\n"; helpMessage += "\n==========> Legend <==========\n"; helpMessage += "\t1. None \"< or >\" must be used, they are just to delimiter parameters \n"; helpMessage += "\t2. Arguments\n"; helpMessage += "\t\t(*) <mandatory arguments>\n"; helpMessage += "\t\t(#) <default arguments> (also optional) #default value\n"; helpMessage += "\t\t( ) <optional arguments>\n"; helpMessage += "\t\t <any kind of argument> :type\n"; helpMessage += "\t\t <any kind of argument> (description)\n"; helpMessage += "\t3. The order of the parameters must be followed (you can \n\tuse 'i' to avoid change default values or to ignore optional arguments)\n"; helpMessage += "\n==========> Arguments <==========\n"; helpMessage += "\t(*) <Strategy> : string (<C> to Collapse, <BF> to BruteForce)\n"; helpMessage += "\t(*) <File name> : string #" + Constants.PATH_GRAPH + "<File name>\n"; helpMessage += "\t(*) <Distance> :double (radius to search) \n"; helpMessage += "\t(*) <OD size> :int (number of Origin and Destination to run) #" + Constants.PATH_ODs + "<OD size>\n"; helpMessage += "\t(#) <Number of threads to use> :int #" + defaultThreadNumber + " (The number of logical processors in this machine)\n"; helpMessage += "\t(#) <Log to file> :bool #" + logToFile + " (<!> to negate the default value) (Whether the log should be written only to the console or to a file as well)\n"; helpMessage += "\t( ) <don't use default paths> :bool(<t> to true) (to use just the path on the <File path> argument when searching for graphs)\n"; if (args.Length == 1 && (args[0] == "-h" || args[0] == "--help")) { Console.WriteLine(helpMessage); return; } else if (args.Length < 4 || args.Length > 7) { throw new ArgumentException("Must inform 4~7 argument must be passed\n" + helpMessage); } // Console.WriteLine(args); // args.ToList().ForEach(Console.WriteLine); var argument = 0; string strategy = args[argument++]; var path = args[argument++]; var radius = double.Parse(args[argument++]); var OD = Int32.Parse(args[argument++]); if (args.Length >= argument + 1) { defaultThreadNumber = args[argument++] == "i"? defaultThreadNumber : Int32.Parse(args[argument - 1]); } if (args.Length >= argument + 1) { logToFile = args[argument++] == "!"? !logToFile: logToFile; } if (args.Length >= argument + 1 && args[argument++] == "t") { file_path = ""; } Graph graph = Import.LoadCityFromText(file_path + path); var ods = Import.LoadODsFromTxt(ods_path, graph.Name, OD); //sudo dotnet run C /home/danielaragao/Documents/Git/Colapsar/caracterizacao-dados-reviews/graphs/giantscomponentes/Mumbai-network-osm-2018-1.txt 50 300 i i t SearchStrategyFactory strategyFactory = SearchStrategyFactory.GetFactory(strategy); LoggerFactory.Define(logToFile, "MultithreadSearch-" + strategyFactory.SearchName); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; if (bool.Parse(config["EmailConfiguration:useEmail"])) { emailSender = new EmailSender(config); } var threadBuilder = new ThreadBuilder(graph, strategyFactory, ods, radius, defaultThreadNumber, emailSender); threadBuilder.Begin(); }