示例#1
0
        public IEnumerable <XPathItem> Eval(XPathItem module, XPathItem input, IEnumerable <XPathNavigator> parameters)
        {
            XQueryInvoker invoker;

            IXQueryProcessor currentOrDefaultProc = this.CurrentXQueryProcessor ?? Processors.XQuery.DefaultProcessor;

            if (module.IsNode)
            {
                XPathNavigator node = ((XPathNavigator)module).Clone();

                if (node.NodeType == XPathNodeType.Root)
                {
                    node.MoveToChild(XPathNodeType.Element);
                }

                if (node.NodeType == XPathNodeType.Element &&
                    node.NamespaceURI == Namespace)
                {
                    XmlSerializer serializer = XPathItemFactory.GetSerializer(typeof(CompiledQueryReference));

                    var reference = (CompiledQueryReference)serializer.Deserialize(node.ReadSubtree());

                    IXQueryProcessor specifiedProcessor = (reference.Processor != null) ?
                                                          Processors.XQuery[reference.Processor]
                  : null;

                    invoker = (reference.HashCode > 0) ?
                              XQueryInvoker.WithQuery(reference.HashCode, specifiedProcessor ?? currentOrDefaultProc)
                  : XQueryInvoker.With(reference.Uri, specifiedProcessor);
                }
                else
                {
                    invoker = XQueryInvoker.WithQuery(module.Value, currentOrDefaultProc);
                }
            }
            else
            {
                object value = module.TypedValue;

                if (value.GetType().IsPrimitive)
                {
                    int hashCode = Convert.ToInt32(value, CultureInfo.InvariantCulture);

                    invoker = XQueryInvoker.WithQuery(hashCode, currentOrDefaultProc);
                }
                else
                {
                    Uri moduleUri = ResolveUri(module);

                    invoker = XQueryInvoker.WithQuery(module.Value, currentOrDefaultProc);
                }
            }

            XQueryRuntimeOptions options = GetRuntimeOptions(input, parameters);

            return(invoker.Query(options).Result());
        }
示例#2
0
        public IEnumerable <XPathItem> Invoke(string moduleUri, XPathItem input, IEnumerable <XPathNavigator> parameters)
        {
            XQueryRuntimeOptions options = GetRuntimeOptions(input, parameters);

            Uri uri = ResolveUri(moduleUri);

            return(XQueryInvoker.With(uri)
                   .Query(options)
                   .Result());
        }
示例#3
0
        public XPathItem CompileFrom(string moduleUri, string processor)
        {
            IXQueryProcessor proc = (processor != null) ?
                                    Processors.XQuery[processor]
            : Processors.XQuery.DefaultProcessor;

            Uri uri = this.Resolver.ResolveUri(null, moduleUri);

            XQueryInvoker.With(uri, proc);

            var reference = new CompiledQueryReference {
                Uri       = uri.AbsoluteUri,
                Processor = processor
            };

            return(this.ItemFactory.CreateDocument(reference)
                   .CreateNavigator());
        }
示例#4
0
        public XPathItem CompileQuery(string query, string processor)
        {
            IXQueryProcessor proc = (processor != null) ?
                                    Processors.XQuery[processor]
            : this.CurrentXQueryProcessor ?? Processors.XQuery.DefaultProcessor;

            int hashCode;

            XQueryInvoker.WithQuery(query, proc, null, out hashCode);

            if (processor == null)
            {
                return(this.ItemFactory.CreateAtomicValue(hashCode, XmlTypeCode.Integer));
            }

            var reference = new CompiledQueryReference {
                HashCode  = hashCode,
                Processor = processor
            };

            return(this.ItemFactory.CreateDocument(reference)
                   .CreateNavigator());
        }