// <summary>This method is applicable only to objects represnting types and // checks if this type is the same or subtype of specified type</summary> /// <param name="superType">version history representing object type</param> /// <param name="kind">search kind</param> /// <param name="timestamp">timestamp used to locate version</param> /// <returns>true if this type is the same or is subtype of specified type</returns> public bool IsSubTypeOf(VersionHistory superType, SearchKind kind, DateTime timestamp) { if (vh == superType) { return true; } foreach (VersionHistory subtype in this[Symbols.Subtype]) { if (kind == SearchKind.AllVersions) { foreach (Thing type in subtype.versions) { if (type.IsSubTypeOf(superType, kind, timestamp)) { return true; } } } else { Thing type = subtype.GetVersion(kind, timestamp); if (type != null && type.IsSubTypeOf(superType, kind, timestamp)) { return true; } } } return false; }
public ContactSearchArguments(string filter, SearchKind searchKind, FilterKind filterKind, object state) { this.Filter = filter; this.FilterKind = filterKind; this.SearchKind = searchKind; this.State = state; }
private SearchQuery(string name, SearchKind kind) { if (name == null) { throw new ArgumentNullException(nameof(name)); } Name = name; Kind = kind; switch (kind) { case SearchKind.Exact: _predicate = s => StringComparer.Ordinal.Equals(name, s); break; case SearchKind.ExactIgnoreCase: _predicate = s => CaseInsensitiveComparison.Comparer.Equals(name, s); break; case SearchKind.Fuzzy: // Create a single WordSimilarityChecker and capture a delegate reference to // its 'AreSimilar' method. That way we only create the WordSimilarityChecker // once and it can cache all the information it needs while it does the AreSimilar // check against all the possible candidates. var editDistance = new WordSimilarityChecker(name); _predicate = editDistance.AreSimilar; break; } }
private FindOptions CreateFindOptions(string pattern, SearchKind kind, SearchOptions options) { var searchData = new SearchData(pattern, SearchOffsetData.None, kind, options); var serviceSearchData = _searchRaw.GetServiceSearchData(searchData, _wordNavigator); var findData = SearchService.ConvertToFindDataCore(serviceSearchData, _textBuffer.CurrentSnapshot); Assert.True(findData.IsResult); return findData.AsResult().FindOptions; }
/// <summary> /// Get version correponding to the specified search kind and timestamp /// </summary> /// <param name="kind">One of SearchKind.LAtestVersion, SearchKind.LatestBefore and SearchKind.OldestAfter</param> /// <param name="timestamp"></param> /// <returns>Version natching time criteria or null if not found</returns> public Thing GetVersion(SearchKind kind, DateTime timestamp) { switch (kind) { case SearchKind.LatestVersion: return Latest; case SearchKind.LatestBefore: return GetLatestBefore(timestamp); case SearchKind.OldestAfter: return GetOldestAfter(timestamp); default: throw new InvalidOperationException("Invalid search kind " + kind + " for VersionHistory.GetVersion"); } }
public SearchResult(DatabaseRoot root, VersionHistory type, string uri, NameVal[] patterns, SearchKind kind, DateTime timestamp, IEnumerator iterator) { this.root = root; this.type = type; this.uri = uri; this.patterns = patterns; this.kind = kind; this.timestamp = timestamp; this.iterator = iterator; }
/// <summary>Check if object belongs to the partiular type</summary> /// <param name="superType">version history representing object type</param> /// <param name="kind">search kind</param> /// <param name="timestamp">timestamp used to locate version</param> /// <returns>true if type of the object is the same or is subtype of specified type</returns> public bool IsInstanceOf(VersionHistory superType, SearchKind kind, DateTime timestamp) { return type.IsSubTypeOf(superType, kind, timestamp); }
public ReferenceIterator(DatabaseRoot root, PropDef[] defs, IEnumerator iterator, SearchKind kind, DateTime timestamp) { this.root = root; this.defs = defs; this.kind = kind; this.timestamp = timestamp; iterators = new IEnumerator[defs.Length + 1]; iterators[iterators.Length - 1] = iterator; Reset(); }
FindOptions GetFindOptions(SearchKind searchKind, bool? forward) { Debug.Assert(searchKind != SearchKind.None); var options = FindOptions.None; switch (searchKind) { case SearchKind.Find: case SearchKind.Replace: if (MatchCase) options |= FindOptions.MatchCase; if (UseRegularExpressions) options |= FindOptions.UseRegularExpressions; if (MatchWholeWords) options |= FindOptions.WholeWord; break; case SearchKind.IncrementalSearchBackward: case SearchKind.IncrementalSearchForward: if (SearchString.Any(c => char.IsUpper(c))) options |= FindOptions.MatchCase; if (forward == null) forward = searchKind == SearchKind.IncrementalSearchForward; break; default: throw new ArgumentOutOfRangeException(nameof(searchKind)); } if (forward == false) options |= FindOptions.SearchReverse; if ((options & FindOptions.UseRegularExpressions) != 0) { if (IsMultiLineRegexPattern(SearchString)) options |= FindOptions.Multiline; else options |= FindOptions.SingleLine; } options |= FindOptions.Wrap | FindOptions.OrdinalComparison; return options; }
void SetSearchKind(SearchKind value) { Debug.Assert(value != SearchKind.None); if (IsSearchControlVisible && searchKind == value) return; searchKind = value; if (searchKind == SearchKind.IncrementalSearchForward || searchKind == SearchKind.IncrementalSearchBackward) { wpfTextView.VisualElement.Focus(); if (!inIncrementalSearch) wpfTextView.Caret.PositionChanged += Caret_PositionChanged; inIncrementalSearch = true; } else CleanUpIncrementalSearch(); OnPropertyChanged(nameof(ShowReplaceRow)); OnPropertyChanged(nameof(ShowOptionsRow)); OnPropertyChanged(nameof(IsReplaceMode)); OnPropertyChanged(nameof(CanReplace)); }
private FindOptions CreateFindOptions(string pattern, SearchKind kind, SearchOptions options) { var searchData = new SearchData(pattern, kind, options); var findData = _searchRaw.ConvertToFindData(searchData, _textBuffer.CurrentSnapshot, _wordNavigator); Assert.True(findData.IsSome()); return findData.Value.FindOptions; }
private IEnumerable SearchReferenceProperty(VersionHistory type, string uri, NameVal[] patterns, SearchKind kind, DateTime timestamp, NameVal prop, bool compound, PropDef def, ArrayList refs) { refs.Add(def); NameVal[] restOfPatterns = compound ? patterns : SubArray(patterns); object val = prop.val; switch (prop.name) { case Symbols.Timestamp: if (val is Range) { Range range = (Range)val; if (range.from is DateTime) { Key fromKey = new Key((DateTime)range.from, range.fromInclusive); Key tillKey = new Key((DateTime)range.till, range.tillInclusive); return new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.timeIndex.GetEnumerator(fromKey, tillKey), kind, timestamp)); } } else if (val is DateTime) { Key key = new Key((DateTime)val); return new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.timeIndex.GetEnumerator(key, key), kind, timestamp)); } return new object[0]; // empty selection case Symbols.Rectangle: if (val is NameVal[]) { NameVal[] coord = (NameVal[])val; if (coord.Length == 4) { RectangleR2 r = new RectangleR2((double)coord[0].val, (double)coord[1].val, (double)coord[2].val, (double)coord[3].val); return new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.spatialIndex.Overlaps(r).GetEnumerator(), kind, timestamp)); } } break; case Symbols.Point: if (val is NameVal[]) { NameVal[] coord = (NameVal[])val; if (coord.Length == 2) { double x = (double)coord[0].val; double y = (double)coord[1].val; RectangleR2 r = new RectangleR2(x, y, x, y); return new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.spatialIndex.Overlaps(r).GetEnumerator(), kind, timestamp)); } } break; case Symbols.Keyword: if (val is string) { ArrayList keywords = new ArrayList(); foreach (string keyword in ((string)val).ToLower().Split(keywordSeparators)) { if (keyword.Length > 0 && !keywordStopList.ContainsKey(keyword)) { keywords.Add(keyword); } } IEnumerator[] occurences = new IEnumerator[keywords.Count]; for (int i = 0; i < occurences.Length; i++) { Key key = new Key((string)keywords[i]); occurences[i] = root.inverseIndex.GetEnumerator(key, key); } return new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), db.Merge(occurences), kind, timestamp)); } break; } def = (PropDef)root.propDefIndex[prop.name]; if (def == null) { return new object[0]; // empty selection } if (val is Range) { Range range = (Range)val; if (range.from is double) { Key fromKey = new Key(new object[]{def, range.from}, range.fromInclusive); Key tillKey = new Key(new object[]{def, range.till}, range.tillInclusive); return new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.numPropIndex.GetEnumerator(fromKey, tillKey), kind, timestamp)); } else if (range.from is DateTime) { Key fromKey = new Key(new object[]{def, range.from}, range.fromInclusive); Key tillKey = new Key(new object[]{def, range.till}, range.tillInclusive); return new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.timePropIndex.GetEnumerator(fromKey, tillKey), kind, timestamp)); } else { Key fromKey = new Key(new object[]{def, range.from}, range.fromInclusive); Key tillKey = new Key(new object[]{def, range.till}, range.tillInclusive); return new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.strPropIndex.GetEnumerator(fromKey, tillKey), kind, timestamp)); } } if (val is string) { string str = (string)prop.val; int wc = str.IndexOf('*'); if (wc < 0) { Key key = new Key(new object[]{def, str}); return new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.strPropIndex.GetEnumerator(key, key), kind, timestamp)); } else if (wc > 0) { string prefix = str.Substring(0, wc); Key fromKey = new Key(new object[]{def, prefix}); Key tillKey = new Key(new object[]{def, prefix + Char.MaxValue}, false); return new SearchResult(root, type, uri, wc == str.Length-1 ? restOfPatterns : patterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.strPropIndex.GetEnumerator(fromKey, tillKey), kind, timestamp)); } } else if (val is double) { Key key = new Key(new object[]{def, val}); return new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.numPropIndex.GetEnumerator(key, key), kind, timestamp)); } else if (val is DateTime) { Key key = new Key(new object[]{def, (DateTime)val}); return new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.timePropIndex.GetEnumerator(key, key), kind, timestamp)); } else if (val is NameVal) { return SearchReferenceProperty(type, uri, patterns, kind, timestamp, (NameVal)val, compound, def, refs); } else if (val is NameVal[]) { NameVal[] props = (NameVal[])val; if (props.Length > 0) { return SearchReferenceProperty(type, uri, patterns, kind, timestamp, props[0], true, def, refs); } } return null; }
public ReferenceIterator(DatabaseRoot root, PropDef[] defs, IEnumerator iterator, SearchKind kind, DateTime timestamp) { this.root = root; this.defs = defs; this.kind = kind; this.timestamp = timestamp; iterators = new IEnumerator[defs.Length+1]; iterators[iterators.Length-1] = iterator; Reset(); }
/// <summary>Get iterator through object matching specified search parameters</summary> /// <param name="type">String representing type of the object (direct or indirect - IsInstanceOf /// method will be used to check if object belongs to the specified type). It may be null, /// in this case type criteria is skipped.</param> /// <param name="uri">Object URI pattern. It may be null, in this case URI is not inspected.</param> /// <param name="patterns">array of name:value pairs specifying search condition for object properties</param> /// <param name="kind">search kind used to select inspected versions</param> /// <param name="timestamp">timestamp used to select versions, if kind is SearchKind.LatestVersion /// or SearchKind.AllVersions this parameter is ignored</param> /// <returns>Enumerator through object meet search criteria.</returns> public IEnumerable Search(string type, string uri, NameVal[] patterns, SearchKind kind, DateTime timestamp) { VersionHistory typeVh = null; root.SharedLock(); try { if (type != null) { typeVh = GetObject(type); if (typeVh == null) { return new object[0]; // empty selection } } if (uri != null) { int wc = uri.IndexOf('*'); if (wc < 0) { return new SearchResult(root, typeVh, null, patterns, kind, timestamp, root.prefixUriIndex.GetEnumerator(uri, uri)); } else if (wc > 0) { String prefix = uri.Substring(0, wc); return new SearchResult(root, typeVh, uri, patterns, kind, timestamp, root.prefixUriIndex.GetEnumerator(prefix)); } else if ((wc = uri.LastIndexOf('*')) < uri.Length-1) { String suffix = ReverseString(uri.Substring(wc+1, uri.Length-wc-1)); return new SearchResult(root, typeVh, uri, patterns, kind, timestamp, root.suffixUriIndex.GetEnumerator(suffix)); } } if (patterns.Length > 0) { NameVal prop = patterns[0]; object val = prop.val; NameVal[] restOfPatterns = SubArray(patterns); switch (prop.name) { case Symbols.Timestamp: if (val is Range) { Range range = (Range)val; if (range.from is DateTime) { Key fromKey = new Key((DateTime)range.from, range.fromInclusive); Key tillKey = new Key((DateTime)range.till, range.tillInclusive); return new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.timeIndex.GetEnumerator(fromKey, tillKey)); } } else if (val is DateTime) { Key key = new Key((DateTime)val); return new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.timeIndex.GetEnumerator(key, key)); } return new object[0]; // empty selection case Symbols.Rectangle: if (val is NameVal[]) { NameVal[] coord = (NameVal[])val; if (coord.Length == 4) { RectangleR2 r = new RectangleR2((double)coord[0].val, (double)coord[1].val, (double)coord[2].val, (double)coord[3].val); return new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.spatialIndex.Overlaps(r).GetEnumerator()); } } break; case Symbols.Point: if (val is NameVal[]) { NameVal[] coord = (NameVal[])val; if (coord.Length == 2) { double x = (double)coord[0].val; double y = (double)coord[1].val; RectangleR2 r = new RectangleR2(x, y, x, y); return new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.spatialIndex.Overlaps(r).GetEnumerator()); } } break; case Symbols.Keyword: if (val is string) { ArrayList keywords = new ArrayList(); foreach (string keyword in ((string)val).ToLower().Split(keywordSeparators)) { if (keyword.Length > 0 && !keywordStopList.ContainsKey(keyword)) { keywords.Add(keyword); } } IEnumerator[] occurences = new IEnumerator[keywords.Count]; for (int i = 0; i < occurences.Length; i++) { Key key = new Key((string)keywords[i]); occurences[i] = root.inverseIndex.GetEnumerator(key, key); } return new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, db.Merge(occurences)); } break; } PropDef def = (PropDef)root.propDefIndex[prop.name]; if (def == null) { return new object[0]; // empty selection } if (val is Range) { Range range = (Range)val; if (range.from is double) { Key fromKey = new Key(new object[]{def, range.from}, range.fromInclusive); Key tillKey = new Key(new object[]{def, range.till}, range.tillInclusive); return new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.numPropIndex.GetEnumerator(fromKey, tillKey)); } else if (range.from is DateTime) { Key fromKey = new Key(new object[]{def, range.from}, range.fromInclusive); Key tillKey = new Key(new object[]{def, range.till}, range.tillInclusive); return new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.timePropIndex.GetEnumerator(fromKey, tillKey)); } else { Key fromKey = new Key(new object[]{def, range.from}, range.fromInclusive); Key tillKey = new Key(new object[]{def, range.till}, range.tillInclusive); return new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.strPropIndex.GetEnumerator(fromKey, tillKey)); } } else if (val is string) { string str = (string)val; int wc = str.IndexOf('*'); if (wc < 0) { Key key = new Key(new object[]{def, str}); return new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.strPropIndex.GetEnumerator(key, key)); } else if (wc > 0) { string prefix = str.Substring(0, wc); Key fromKey = new Key(new object[]{def, prefix}); Key tillKey = new Key(new object[]{def, prefix + Char.MaxValue}, false); return new SearchResult(root, typeVh, uri, wc == str.Length-1 ? restOfPatterns : patterns, kind, timestamp, root.strPropIndex.GetEnumerator(fromKey, tillKey)); } } else if (val is double) { Key key = new Key(new object[]{def, val}); return new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.numPropIndex.GetEnumerator(key, key)); } else if (val is DateTime) { Key key = new Key(new object[]{def, val}); return new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.timePropIndex.GetEnumerator(key, key)); } else if (val is NameVal) { IEnumerable iterator = SearchReferenceProperty(typeVh, uri, patterns, kind, timestamp, (NameVal)val, false, def, new ArrayList()); if (iterator != null) { return iterator; } } else if (val is NameVal[]) { NameVal[] props = (NameVal[])val; if (props.Length > 0) { IEnumerable iterator = SearchReferenceProperty(typeVh, uri, patterns, kind, timestamp, props[0], props.Length > 1, def, new ArrayList()); if (iterator != null) { return iterator; } } } } if (kind == SearchKind.LatestVersion) { return new SearchResult(root, typeVh, uri, patterns, kind, timestamp, root.latest.GetEnumerator()); } return new SearchResult(root, typeVh, uri, patterns, kind, timestamp, root.timeIndex.GetEnumerator()); } finally { root.Unlock(); } }
/// <summary>Get verion history by URI and timestamp</summary> /// <param name="uri">object URI</param> /// <param name="kind">search kind, should be object SearchKind.LatestVersion, SearchKind.LatestBefore or /// SearchKind.OldestAfter</param> /// <param name="timestamp">timestamp used to locate version</param> /// <returns>version of the object or null if no such version is found</returns> public Thing GetVersion(string uri, SearchKind kind, DateTime timestamp) { VersionHistory vh = (VersionHistory)root.prefixUriIndex[uri]; if (vh != null) { return vh.GetVersion(kind, timestamp); } return null; }
private IEnumerable SearchReferenceProperty(VersionHistory type, string uri, NameVal[] patterns, SearchKind kind, DateTime timestamp, NameVal prop, bool compound, PropDef def, ArrayList refs) { refs.Add(def); NameVal[] restOfPatterns = compound ? patterns : SubArray(patterns); object val = prop.val; switch (prop.name) { case Symbols.Timestamp: if (val is Range) { Range range = (Range)val; if (range.from is DateTime) { Key fromKey = new Key((DateTime)range.from, range.fromInclusive); Key tillKey = new Key((DateTime)range.till, range.tillInclusive); return(new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.timeIndex.GetEnumerator(fromKey, tillKey), kind, timestamp))); } } else if (val is DateTime) { Key key = new Key((DateTime)val); return(new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.timeIndex.GetEnumerator(key, key), kind, timestamp))); } return(new object[0]); // empty selection case Symbols.Rectangle: if (val is NameVal[]) { NameVal[] coord = (NameVal[])val; if (coord.Length == 4) { RectangleR2 r = new RectangleR2((double)coord[0].val, (double)coord[1].val, (double)coord[2].val, (double)coord[3].val); return(new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.spatialIndex.Overlaps(r).GetEnumerator(), kind, timestamp))); } } break; case Symbols.Point: if (val is NameVal[]) { NameVal[] coord = (NameVal[])val; if (coord.Length == 2) { double x = (double)coord[0].val; double y = (double)coord[1].val; RectangleR2 r = new RectangleR2(x, y, x, y); return(new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.spatialIndex.Overlaps(r).GetEnumerator(), kind, timestamp))); } } break; case Symbols.Keyword: if (val is string) { ArrayList keywords = new ArrayList(); foreach (string keyword in ((string)val).ToLower().Split(keywordSeparators)) { if (keyword.Length > 0 && !keywordStopList.ContainsKey(keyword)) { keywords.Add(keyword); } } IEnumerator[] occurences = new IEnumerator[keywords.Count]; for (int i = 0; i < occurences.Length; i++) { Key key = new Key((string)keywords[i]); occurences[i] = root.inverseIndex.GetEnumerator(key, key); } return(new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), db.Merge(occurences), kind, timestamp))); } break; } def = (PropDef)root.propDefIndex[prop.name]; if (def == null) { return(new object[0]); // empty selection } if (val is Range) { Range range = (Range)val; if (range.from is double) { Key fromKey = new Key(new object[] { def, range.from }, range.fromInclusive); Key tillKey = new Key(new object[] { def, range.till }, range.tillInclusive); return(new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.numPropIndex.GetEnumerator(fromKey, tillKey), kind, timestamp))); } else if (range.from is DateTime) { Key fromKey = new Key(new object[] { def, range.from }, range.fromInclusive); Key tillKey = new Key(new object[] { def, range.till }, range.tillInclusive); return(new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.timePropIndex.GetEnumerator(fromKey, tillKey), kind, timestamp))); } else { Key fromKey = new Key(new object[] { def, range.from }, range.fromInclusive); Key tillKey = new Key(new object[] { def, range.till }, range.tillInclusive); return(new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.strPropIndex.GetEnumerator(fromKey, tillKey), kind, timestamp))); } } if (val is string) { string str = (string)prop.val; int wc = str.IndexOf('*'); if (wc < 0) { Key key = new Key(new object[] { def, str }); return(new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.strPropIndex.GetEnumerator(key, key), kind, timestamp))); } else if (wc > 0) { string prefix = str.Substring(0, wc); Key fromKey = new Key(new object[] { def, prefix }); Key tillKey = new Key(new object[] { def, prefix + Char.MaxValue }, false); return(new SearchResult(root, type, uri, wc == str.Length - 1 ? restOfPatterns : patterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.strPropIndex.GetEnumerator(fromKey, tillKey), kind, timestamp))); } } else if (val is double) { Key key = new Key(new object[] { def, val }); return(new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.numPropIndex.GetEnumerator(key, key), kind, timestamp))); } else if (val is DateTime) { Key key = new Key(new object[] { def, (DateTime)val }); return(new SearchResult(root, type, uri, restOfPatterns, kind, timestamp, new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)), root.timePropIndex.GetEnumerator(key, key), kind, timestamp))); } else if (val is NameVal) { return(SearchReferenceProperty(type, uri, patterns, kind, timestamp, (NameVal)val, compound, def, refs)); } else if (val is NameVal[]) { NameVal[] props = (NameVal[])val; if (props.Length > 0) { return(SearchReferenceProperty(type, uri, patterns, kind, timestamp, props[0], true, def, refs)); } } return(null); }
private SearchQuery(Func<string, bool> predicate) { Kind = SearchKind.Custom; _predicate = predicate ?? throw new ArgumentNullException(nameof(predicate)); }
internal static SearchData CreateSearchData( string pattern, SearchKind kind = SearchKind.Forward, SearchOptions options = SearchOptions.None) { return new SearchData(SearchText.NewPattern(pattern), kind, options); }
private void SimulateSearch(string pattern, SearchKind searchKind = null, SearchOptions searchOptions = SearchOptions.None) { searchKind = searchKind ?? SearchKind.Forward; var data = new SearchData(pattern, SearchOffsetData.None, searchKind, searchOptions); var text = (searchKind.IsAnyForward ? "/" : "?") + pattern; _search.SetupGet(x => x.InSearch).Returns(true).Verifiable(); _search.SetupGet(x => x.CurrentSearchData).Returns(data).Verifiable(); _search.SetupGet(x => x.CurrentSearchText).Returns(text).Verifiable(); }
internal static SearchData CreateSearchData( SearchText text, SearchKind kind = SearchKind.Forward, SearchOptions options = SearchOptions.None) { return new SearchData(text, kind, options); }
void ShowSearchControl(SearchKind searchKind, bool canOverwriteSearchString) { UseGlobalSettingsIfUiIsHidden(canOverwriteSearchString); bool wasShown = IsSearchControlVisible; if (searchControl == null) { searchControl = new SearchControl { DataContext = this }; searchControl.InputBindings.Add(new KeyBinding(new RelayCommand(a => CloseSearchControl()), new KeyGesture(Key.Escape, ModifierKeys.None))); searchControl.InputBindings.Add(new KeyBinding(new RelayCommand(a => ShowFind()), new KeyGesture(Key.F, ModifierKeys.Control))); searchControl.InputBindings.Add(new KeyBinding(new RelayCommand(a => ShowReplace()), new KeyGesture(Key.H, ModifierKeys.Control))); searchControl.InputBindings.Add(new KeyBinding(new RelayCommand(a => FindNext(true)), new KeyGesture(Key.F, ModifierKeys.Alt))); searchControl.InputBindings.Add(new KeyBinding(new RelayCommand(a => FindNext(true)), new KeyGesture(Key.Enter, ModifierKeys.None))); searchControl.InputBindings.Add(new KeyBinding(new RelayCommand(a => FindNext(false)), new KeyGesture(Key.Enter, ModifierKeys.Shift))); searchControl.InputBindings.Add(new KeyBinding(new RelayCommand(a => FindNext(true)), new KeyGesture(Key.F3, ModifierKeys.None))); searchControl.InputBindings.Add(new KeyBinding(new RelayCommand(a => FindNext(false)), new KeyGesture(Key.F3, ModifierKeys.Shift))); searchControl.InputBindings.Add(new KeyBinding(new RelayCommand(a => FindNextSelected(true)), new KeyGesture(Key.F3, ModifierKeys.Control))); searchControl.InputBindings.Add(new KeyBinding(new RelayCommand(a => FindNextSelected(false)), new KeyGesture(Key.F3, ModifierKeys.Control | ModifierKeys.Shift))); searchControl.InputBindings.Add(new KeyBinding(new RelayCommand(a => FocusSearchStringTextBox()), new KeyGesture(Key.N, ModifierKeys.Alt))); searchControl.InputBindings.Add(new KeyBinding(new RelayCommand(a => FocusReplaceStringTextBox(), a => IsReplaceMode), new KeyGesture(Key.P, ModifierKeys.Alt))); searchControl.InputBindings.Add(new KeyBinding(new RelayCommand(a => MatchCase = !MatchCase), new KeyGesture(Key.C, ModifierKeys.Alt))); searchControl.InputBindings.Add(new KeyBinding(new RelayCommand(a => MatchWholeWords = !MatchWholeWords), new KeyGesture(Key.W, ModifierKeys.Alt))); searchControl.InputBindings.Add(new KeyBinding(new RelayCommand(a => UseRegularExpressions = !UseRegularExpressions), new KeyGesture(Key.E, ModifierKeys.Alt))); searchControl.InputBindings.Add(new KeyBinding(ReplaceNextCommand, new KeyGesture(Key.R, ModifierKeys.Alt))); searchControl.InputBindings.Add(new KeyBinding(ReplaceAllCommand, new KeyGesture(Key.A, ModifierKeys.Alt))); searchControl.AddHandler(UIElement.GotKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(SearchControl_GotKeyboardFocus), true); searchControl.AddHandler(UIElement.LostKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(SearchControl_LostKeyboardFocus), true); searchControl.AddHandler(UIElement.MouseDownEvent, new MouseButtonEventHandler(SearchControl_MouseDown), true); SelectAllWhenFocused(searchControl.searchStringTextBox); SelectAllWhenFocused(searchControl.replaceStringTextBox); searchControl.SizeChanged += SearchControl_SizeChanged; searchControl.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); } if (layer == null) layer = wpfTextView.GetAdornmentLayer(PredefinedDsAdornmentLayers.Search); if (layer.IsEmpty) { layer.AddAdornment(AdornmentPositioningBehavior.OwnerControlled, null, null, searchControl, null); wpfTextView.LayoutChanged += WpfTextView_LayoutChanged; } SetSearchKind(searchKind); RepositionControl(); if (!wasShown) UpdateTextMarkerSearch(); }
void CloseSearchControl() { if (layer == null || layer.IsEmpty) { Debug.Assert(searchKind == SearchKind.None && searchControlPosition == SearchControlPosition.Default); return; } CancelAsyncSearch(); CleanUpIncrementalSearch(); layer.RemoveAllAdornments(); wpfHexView.LayoutChanged -= WpfHexView_LayoutChanged; wpfHexView.BufferLinesChanged -= WpfHexView_BufferLinesChanged; wpfHexView.Buffer.BufferSpanInvalidated -= Buffer_BufferSpanInvalidated; hexMarkerSearchService = null; RefreshAllTags(); wpfHexView.VisualElement.Focus(); searchKind = SearchKind.None; searchControlPosition = SearchControlPosition.Default; SaveSettings(); }
void CloseSearchControl() { if (layer == null || layer.IsEmpty) { Debug.Assert(searchKind == SearchKind.None && searchControlPosition == SearchControlPosition.Default); return; } CleanUpIncrementalSearch(); layer.RemoveAllAdornments(); wpfTextView.LayoutChanged -= WpfTextView_LayoutChanged; findResultCollection = null; RefreshAllTags(); wpfTextView.VisualElement.Focus(); searchKind = SearchKind.None; searchControlPosition = SearchControlPosition.Default; SaveSettings(); }
OurFindOptions GetFindOptions(SearchKind searchKind, bool? forward) { Debug.Assert(searchKind != SearchKind.None); var options = OurFindOptions.None; switch (searchKind) { case SearchKind.Find: case SearchKind.Replace: if (MatchCase) options |= OurFindOptions.MatchCase; break; case SearchKind.IncrementalSearchBackward: case SearchKind.IncrementalSearchForward: if (SearchString.Any(c => char.IsUpper(c))) options |= OurFindOptions.MatchCase; if (forward == null) forward = searchKind == SearchKind.IncrementalSearchForward; break; default: throw new ArgumentOutOfRangeException(nameof(searchKind)); } if (forward == false) options |= OurFindOptions.SearchReverse; options |= OurFindOptions.Wrap; return options; }
SnapshotPoint? GetStartingPosition(SearchKind searchKind, FindOptions options, bool restart) { Debug.Assert(searchKind != SearchKind.None); switch (searchKind) { case SearchKind.Find: case SearchKind.Replace: return GetStartingPosition(options, restart); case SearchKind.IncrementalSearchBackward: case SearchKind.IncrementalSearchForward: return incrementalStartPosition; default: throw new ArgumentOutOfRangeException(nameof(searchKind)); } }
static void DumpObject(Thing thing, TextWriter writer, int indent, SearchKind kind, DateTime timestamp, int depth) { WriteTab(writer, indent); string typeName = GetQualifiedName(thing.type.vh.uri, writer); writer.WriteLine(" rdf:about=\"" + thing.vh.uri + "\" vr:timestamp=\"" + thing.timestamp + "\">"); foreach (PropVal pv in thing.props) { object val = pv.val; if (val is VersionHistory) { VersionHistory ptr = (VersionHistory)val; if (kind != SearchKind.AllVersions) { if (depth > 0 || ptr.uri.StartsWith(thing.vh.uri)) { Thing t = ptr.GetVersion(kind, timestamp); if (t != null) { DumpObject(t, writer, indent+1, kind, timestamp, depth-1); continue; } } } WriteTab(writer, indent+1); GetQualifiedName(pv.def.name, writer); writer.WriteLine(" rdf:resource=\"" + ptr.uri + "\"/>"); } else { WriteTab(writer, indent+1); string propName = GetQualifiedName(pv.def.name, writer); writer.WriteLine(">" + val + "</" + propName + ">"); } } WriteTab(writer, indent); writer.WriteLine("</" + typeName + ">"); }
private void SimulateSearch(string pattern, SearchKind searchKind = null, SearchOptions searchOptions = SearchOptions.None) { searchKind = searchKind ?? SearchKind.Forward; var data = new SearchData(pattern, searchKind, searchOptions); _search.SetupGet(x => x.InSearch).Returns(true).Verifiable(); _search.SetupGet(x => x.CurrentSearchData).Returns(FSharpOption.Create(data)).Verifiable(); }
/// <summary>Get iterator through object matching specified search parameters</summary> /// <param name="type">String representing type of the object (direct or indirect - IsInstanceOf /// method will be used to check if object belongs to the specified type). It may be null, /// in this case type criteria is skipped.</param> /// <param name="uri">Object URI pattern. It may be null, in this case URI is not inspected.</param> /// <param name="patterns">array of name:value pairs specifying search condition for object properties</param> /// <param name="kind">search kind used to select inspected versions</param> /// <param name="timestamp">timestamp used to select versions, if kind is SearchKind.LatestVersion /// or SearchKind.AllVersions this parameter is ignored</param> /// <returns>Enumerator through object meet search criteria.</returns> public IEnumerable Search(string type, string uri, NameVal[] patterns, SearchKind kind, DateTime timestamp) { VersionHistory typeVh = null; root.SharedLock(); try { if (type != null) { typeVh = GetObject(type); if (typeVh == null) { return(new object[0]); // empty selection } } if (uri != null) { int wc = uri.IndexOf('*'); if (wc < 0) { return(new SearchResult(root, typeVh, null, patterns, kind, timestamp, root.prefixUriIndex.GetEnumerator(uri, uri))); } else if (wc > 0) { String prefix = uri.Substring(0, wc); return(new SearchResult(root, typeVh, uri, patterns, kind, timestamp, root.prefixUriIndex.GetEnumerator(prefix))); } else if ((wc = uri.LastIndexOf('*')) < uri.Length - 1) { String suffix = ReverseString(uri.Substring(wc + 1, uri.Length - wc - 1)); return(new SearchResult(root, typeVh, uri, patterns, kind, timestamp, root.suffixUriIndex.GetEnumerator(suffix))); } } if (patterns.Length > 0) { NameVal prop = patterns[0]; object val = prop.val; NameVal[] restOfPatterns = SubArray(patterns); switch (prop.name) { case Symbols.Timestamp: if (val is Range) { Range range = (Range)val; if (range.from is DateTime) { Key fromKey = new Key((DateTime)range.from, range.fromInclusive); Key tillKey = new Key((DateTime)range.till, range.tillInclusive); return(new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.timeIndex.GetEnumerator(fromKey, tillKey))); } } else if (val is DateTime) { Key key = new Key((DateTime)val); return(new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.timeIndex.GetEnumerator(key, key))); } return(new object[0]); // empty selection case Symbols.Rectangle: if (val is NameVal[]) { NameVal[] coord = (NameVal[])val; if (coord.Length == 4) { RectangleR2 r = new RectangleR2((double)coord[0].val, (double)coord[1].val, (double)coord[2].val, (double)coord[3].val); return(new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.spatialIndex.Overlaps(r).GetEnumerator())); } } break; case Symbols.Point: if (val is NameVal[]) { NameVal[] coord = (NameVal[])val; if (coord.Length == 2) { double x = (double)coord[0].val; double y = (double)coord[1].val; RectangleR2 r = new RectangleR2(x, y, x, y); return(new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.spatialIndex.Overlaps(r).GetEnumerator())); } } break; case Symbols.Keyword: if (val is string) { ArrayList keywords = new ArrayList(); foreach (string keyword in ((string)val).ToLower().Split(keywordSeparators)) { if (keyword.Length > 0 && !keywordStopList.ContainsKey(keyword)) { keywords.Add(keyword); } } IEnumerator[] occurences = new IEnumerator[keywords.Count]; for (int i = 0; i < occurences.Length; i++) { Key key = new Key((string)keywords[i]); occurences[i] = root.inverseIndex.GetEnumerator(key, key); } return(new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, db.Merge(occurences))); } break; } PropDef def = (PropDef)root.propDefIndex[prop.name]; if (def == null) { return(new object[0]); // empty selection } if (val is Range) { Range range = (Range)val; if (range.from is double) { Key fromKey = new Key(new object[] { def, range.from }, range.fromInclusive); Key tillKey = new Key(new object[] { def, range.till }, range.tillInclusive); return(new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.numPropIndex.GetEnumerator(fromKey, tillKey))); } else if (range.from is DateTime) { Key fromKey = new Key(new object[] { def, range.from }, range.fromInclusive); Key tillKey = new Key(new object[] { def, range.till }, range.tillInclusive); return(new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.timePropIndex.GetEnumerator(fromKey, tillKey))); } else { Key fromKey = new Key(new object[] { def, range.from }, range.fromInclusive); Key tillKey = new Key(new object[] { def, range.till }, range.tillInclusive); return(new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.strPropIndex.GetEnumerator(fromKey, tillKey))); } } else if (val is string) { string str = (string)val; int wc = str.IndexOf('*'); if (wc < 0) { Key key = new Key(new object[] { def, str }); return(new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.strPropIndex.GetEnumerator(key, key))); } else if (wc > 0) { string prefix = str.Substring(0, wc); Key fromKey = new Key(new object[] { def, prefix }); Key tillKey = new Key(new object[] { def, prefix + Char.MaxValue }, false); return(new SearchResult(root, typeVh, uri, wc == str.Length - 1 ? restOfPatterns : patterns, kind, timestamp, root.strPropIndex.GetEnumerator(fromKey, tillKey))); } } else if (val is double) { Key key = new Key(new object[] { def, val }); return(new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.numPropIndex.GetEnumerator(key, key))); } else if (val is DateTime) { Key key = new Key(new object[] { def, val }); return(new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, root.timePropIndex.GetEnumerator(key, key))); } else if (val is NameVal) { IEnumerable iterator = SearchReferenceProperty(typeVh, uri, patterns, kind, timestamp, (NameVal)val, false, def, new ArrayList()); if (iterator != null) { return(iterator); } } else if (val is NameVal[]) { NameVal[] props = (NameVal[])val; if (props.Length > 0) { IEnumerable iterator = SearchReferenceProperty(typeVh, uri, patterns, kind, timestamp, props[0], props.Length > 1, def, new ArrayList()); if (iterator != null) { return(iterator); } } } } if (kind == SearchKind.LatestVersion) { return(new SearchResult(root, typeVh, uri, patterns, kind, timestamp, root.latest.GetEnumerator())); } return(new SearchResult(root, typeVh, uri, patterns, kind, timestamp, root.timeIndex.GetEnumerator())); } finally { root.Unlock(); } }