public FindResult FindNext(BookmarkEnumerator bookmarkEnumerator) { var customMatches = new Dictionary <Bookmark, FindMatch>(); foreach (var finder in FindOptions.CustomFinders) { var customEnumerator = new BookmarkEnumerator(bookmarkEnumerator); var nextMatch = finder.NextMatch(customEnumerator); if (nextMatch == null || customMatches.ContainsKey(customEnumerator.Current)) { continue; } customMatches.Add(customEnumerator.Current, nextMatch); } do { bookmarkEnumerator.MoveNext(); FindMatch findMatch; if (customMatches.TryGetValue(bookmarkEnumerator.Current, out findMatch)) { return(new FindResult(this, bookmarkEnumerator, findMatch)); } findMatch = MatchInternal(bookmarkEnumerator); if (findMatch != null) { return(new FindResult(this, bookmarkEnumerator, findMatch)); } } while (!bookmarkEnumerator.AtStart); return(null); }
public virtual FindMatch NextMatch(BookmarkEnumerator bookmarkEnumerator) { do { bookmarkEnumerator.MoveNext(); var findMatch = Match(bookmarkEnumerator); if (findMatch != null) { return(findMatch); } } while (!bookmarkEnumerator.AtStart); return(null); }
public IEnumerable <FindResult> FindAll(ILongWaitBroker longWaitBroker, SrmDocument document) { longWaitBroker.Message = Resources.FindPredicate_FindAll_Found_0_matches; var customMatches = new HashSet <Bookmark> [FindOptions.CustomFinders.Count]; for (int iFinder = 0; iFinder < FindOptions.CustomFinders.Count; iFinder++) { var customFinder = FindOptions.CustomFinders[iFinder]; var bookmarkSet = new HashSet <Bookmark>(); longWaitBroker.Message = string.Format(Resources.FindPredicate_FindAll_Searching_for__0__, customFinder.DisplayName); foreach (var bookmark in customFinder.FindAll(document)) { if (longWaitBroker.IsCanceled) { yield break; } bookmarkSet.Add(bookmark); } customMatches[iFinder] = bookmarkSet; } var bookmarkEnumerator = new BookmarkEnumerator(document); int matchCount = 0; do { bookmarkEnumerator.MoveNext(); if (longWaitBroker.IsCanceled) { yield break; } FindMatch findMatch = null; for (int iFinder = 0; iFinder < FindOptions.CustomFinders.Count; iFinder++) { if (customMatches[iFinder].Contains(bookmarkEnumerator.Current)) { findMatch = FindOptions.CustomFinders[iFinder].Match(bookmarkEnumerator); } } findMatch = findMatch ?? MatchInternal(bookmarkEnumerator); if (findMatch != null) { matchCount++; longWaitBroker.Message = matchCount == 1 ? Resources.FindPredicate_FindAll_Found_1_match : string.Format(Resources.FindPredicate_FindAll_Found__0__matches, matchCount); yield return(new FindResult(this, bookmarkEnumerator, findMatch)); } } while (!bookmarkEnumerator.AtStart); }
public IEnumerator <Bookmark> GetEnumerator() { var enumerator = new BookmarkEnumerator(this); while (true) { enumerator.MoveNext(); yield return(enumerator.Current); if (enumerator.AtStart) { break; } } }
public virtual IEnumerable <Bookmark> FindAll(SrmDocument document) { var bookmarkEnumerator = new BookmarkEnumerator(document); while (true) { bookmarkEnumerator.MoveNext(); if (Match(bookmarkEnumerator) != null) { yield return(bookmarkEnumerator.Current); } if (bookmarkEnumerator.AtStart) { yield break; } } }
public FindMatch NextMatch(BookmarkEnumerator bookmarkEnumerator) { var allBookmarks = new HashSet <Bookmark>(FindAll(bookmarkEnumerator.Document)); if (allBookmarks.Count == 0) { return(null); } do { bookmarkEnumerator.MoveNext(); if (allBookmarks.Contains(bookmarkEnumerator.Current)) { var findMatch = Match(bookmarkEnumerator); if (findMatch != null) { return(findMatch); } } } while (!bookmarkEnumerator.AtStart); return(null); }