/// <summary> /// Execute matches over the given seekable navigator. If the navigator is not safe, wrap it with one that is /// </summary> internal FilterResult Match(SeekableXPathNavigator navigator, ICollection <MessageFilter> matches) { // If the matcher places restrictions on the # of nodes we will inspect, and the navigator passed does // not do any nodecounting itself, we must make that navigator safe by wrapping it if (this.maxNodes < int.MaxValue) { navigator = this.CreateSafeNavigator(navigator); } QueryProcessor processor = this.CreateProcessor(); processor.MatchSet = matches; processor.EnsureFilterCollection(); try { processor.Eval(this.query, navigator); } catch (XPathNavigatorException e) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(e.Process(this.query)); } catch (NavigatorInvalidBodyAccessException e) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(e.Process(this.query)); } return(new FilterResult(processor)); }
public IEnumerator <KeyValuePair <MessageQuery, TResult> > GetEnumerator() { IEnumerator <KeyValuePair <MessageQuery, TResult> > enumerator; QueryProcessor processor = this.matcher.CreateProcessor(); Collection <KeyValuePair <MessageQuery, XPathResult> > collection = new Collection <KeyValuePair <MessageQuery, XPathResult> >(); processor.ResultSet = collection; try { processor.Eval(this.matcher.RootOpcode, this.message, this.evalBody); if (typeof(TResult) == typeof(XPathResult)) { return((IEnumerator <KeyValuePair <MessageQuery, TResult> >)collection.GetEnumerator()); } if ((!(typeof(TResult) == typeof(string)) && !(typeof(TResult) == typeof(bool))) && !(typeof(TResult) == typeof(object))) { throw Fx.AssertAndThrowFatal("unsupported type"); } Collection <KeyValuePair <MessageQuery, TResult> > collection2 = new Collection <KeyValuePair <MessageQuery, TResult> >(); foreach (KeyValuePair <MessageQuery, XPathResult> pair in collection) { if (typeof(TResult) == typeof(string)) { collection2.Add(new KeyValuePair <MessageQuery, TResult>(pair.Key, (TResult)pair.Value.GetResultAsString())); } else if (typeof(TResult) == typeof(bool)) { collection2.Add(new KeyValuePair <MessageQuery, TResult>(pair.Key, (TResult)pair.Value.GetResultAsBoolean())); } else { collection2.Add(new KeyValuePair <MessageQuery, TResult>(pair.Key, (TResult)pair.Value)); } } enumerator = collection2.GetEnumerator(); } catch (XPathNavigatorException exception) { throw TraceUtility.ThrowHelperError(exception.Process(this.matcher.RootOpcode), this.message); } catch (NavigatorInvalidBodyAccessException exception2) { throw TraceUtility.ThrowHelperError(exception2.Process(this.matcher.RootOpcode), this.message); } finally { if (this.evalBody) { this.message.Close(); } this.matcher.ReleaseProcessor(processor); } return(enumerator); }
public TResult GetSingleResult() { QueryProcessor processor = this.matcher.CreateProcessor(); XPathResult result; try { processor.Eval(this.matcher.RootOpcode, this.message, this.evalBody); } catch (XPathNavigatorException e) { throw TraceUtility.ThrowHelperError(e.Process(this.matcher.RootOpcode), this.message); } catch (NavigatorInvalidBodyAccessException e) { throw TraceUtility.ThrowHelperError(e.Process(this.matcher.RootOpcode), this.message); } finally { if (this.evalBody) { this.message.Close(); } result = processor.QueryResult; this.matcher.ReleaseProcessor(processor); } if (typeof(TResult) == typeof(XPathResult) || typeof(TResult) == typeof(object)) { return((TResult)(object)result); } else if (typeof(TResult) == typeof(string)) { return((TResult)(object)result.GetResultAsString()); } else if (typeof(TResult) == typeof(bool)) { return((TResult)(object)result.GetResultAsBoolean()); } else { throw Fx.AssertAndThrowFatal("unsupported type"); } }
internal FilterResult Match(Message message, bool matchBody, ICollection <MessageFilter> matches) { QueryProcessor processor = this.CreateProcessor(); processor.MatchSet = matches; processor.EnsureFilterCollection(); try { processor.Eval(this.query, message, matchBody); } catch (XPathNavigatorException exception) { throw TraceUtility.ThrowHelperError(exception.Process(this.query), message); } catch (NavigatorInvalidBodyAccessException exception2) { throw TraceUtility.ThrowHelperError(exception2.Process(this.query), message); } return(new FilterResult(processor)); }
internal FilterResult Match(SeekableXPathNavigator navigator, ICollection <MessageFilter> matches) { if (this.maxNodes < 0x7fffffff) { navigator = this.CreateSafeNavigator(navigator); } QueryProcessor processor = this.CreateProcessor(); processor.MatchSet = matches; processor.EnsureFilterCollection(); try { processor.Eval(this.query, navigator); } catch (XPathNavigatorException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception.Process(this.query)); } catch (NavigatorInvalidBodyAccessException exception2) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception2.Process(this.query)); } return(new FilterResult(processor)); }
public IEnumerator <KeyValuePair <MessageQuery, TResult> > GetEnumerator() { QueryProcessor processor = this.matcher.CreateProcessor(); Collection <KeyValuePair <MessageQuery, XPathResult> > results = new Collection <KeyValuePair <MessageQuery, XPathResult> >(); processor.ResultSet = results; try { processor.Eval(this.matcher.RootOpcode, this.message, this.evalBody); if (typeof(TResult) == typeof(XPathResult)) { return((IEnumerator <KeyValuePair <MessageQuery, TResult> >)(object) results.GetEnumerator()); } else if (typeof(TResult) == typeof(string) || typeof(TResult) == typeof(bool) || typeof(TResult) == typeof(object)) { Collection <KeyValuePair <MessageQuery, TResult> > typedResults = new Collection <KeyValuePair <MessageQuery, TResult> >(); foreach (var result in results) { if (typeof(TResult) == typeof(string)) { typedResults.Add( new KeyValuePair <MessageQuery, TResult>( result.Key, (TResult)(object)result.Value.GetResultAsString())); } else if (typeof(TResult) == typeof(bool)) { typedResults.Add( new KeyValuePair <MessageQuery, TResult>( result.Key, (TResult)(object)result.Value.GetResultAsBoolean())); } else { typedResults.Add(new KeyValuePair <MessageQuery, TResult>( result.Key, (TResult)(object)result.Value)); } } return((IEnumerator <KeyValuePair <MessageQuery, TResult> >)typedResults.GetEnumerator()); } else { throw Fx.AssertAndThrowFatal("unsupported type"); } } catch (XPathNavigatorException e) { throw TraceUtility.ThrowHelperError(e.Process(this.matcher.RootOpcode), this.message); } catch (NavigatorInvalidBodyAccessException e) { throw TraceUtility.ThrowHelperError(e.Process(this.matcher.RootOpcode), this.message); } finally { if (this.evalBody) { this.message.Close(); } this.matcher.ReleaseProcessor(processor); } }