Exemplo n.º 1
0
        static XQueryInvoker With(Uri queryUri, IXQueryProcessor processor, Assembly callingAssembly)
        {
            if (queryUri == null)
            {
                throw new ArgumentNullException("queryUri");
            }

            var resolver = new XmlDynamicResolver(callingAssembly);

            if (!queryUri.IsAbsoluteUri)
            {
                queryUri = resolver.ResolveUri(null, queryUri.OriginalString);
            }

            if (processor == null)
            {
                processor = Processors.XQuery.DefaultProcessor;
            }

            ConcurrentDictionary <Uri, XQueryExecutable> cache =
                uriCache.GetOrAdd(processor, p => new ConcurrentDictionary <Uri, XQueryExecutable>());

            XQueryExecutable executable = cache.GetOrAdd(queryUri, u => {
                using (var stylesheetSource = (Stream)resolver.GetEntity(queryUri, null, typeof(Stream))) {
                    return(processor.Compile(stylesheetSource, new XQueryCompileOptions {
                        BaseUri = queryUri,
                        XmlResolver = resolver
                    }));
                }
            });

            return(new XQueryInvoker(executable, callingAssembly));
        }
Exemplo n.º 2
0
        internal static XQueryInvoker WithQuery(string query, IXQueryProcessor processor, Assembly callingAssembly, out int hashCode)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            if (processor == null)
            {
                processor = Processors.XQuery.DefaultProcessor;
            }

            hashCode = query.GetHashCode();

            ConcurrentDictionary <int, XQueryExecutable> cache =
                inlineCache.GetOrAdd(processor, p => new ConcurrentDictionary <int, XQueryExecutable>());

            XQueryExecutable exec = cache.GetOrAdd(hashCode, i => {
                var resolver = new XmlDynamicResolver(callingAssembly);

                return(processor.Compile(new StringReader(query), new XQueryCompileOptions {
                    XmlResolver = resolver
                }));
            });

            return(new XQueryInvoker(exec, callingAssembly));
        }
Exemplo n.º 3
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());
        }
Exemplo n.º 4
0
        internal static XQueryInvoker WithQuery(int stylesheetHashCode, IXQueryProcessor processor)
        {
            if (processor == null)
            {
                processor = Processors.XQuery.DefaultProcessor;
            }

            return(new XQueryInvoker(inlineCache[processor][stylesheetHashCode], null));
        }
Exemplo n.º 5
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());
        }
Exemplo n.º 6
0
        public override void GenerateCode(AssemblyBuilder assemblyBuilder)
        {
            base.GenerateCode(assemblyBuilder);

            // test compilation

            XQueryPageParser xqueryParser = (XQueryPageParser)Parser;

            IXQueryProcessor proc = Processors.XQuery[xqueryParser.ProcessorName];

            using (Stream source = this.OpenStream()) {
                try {
                    proc.Compile(source, new XQueryCompileOptions {
                        BaseUri = this.PhysicalPath
                    });
                } catch (ProcessorException ex) {
                    throw CreateCompileException(ex);
                }
            }
        }
Exemplo n.º 7
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());
        }
Exemplo n.º 8
0
        internal static XQueryInvoker WithQuery(string query, IXQueryProcessor processor, Assembly callingAssembly, out int hashCode)
        {
            if (query == null) throw new ArgumentNullException("query");

             if (processor == null) {
            processor = Processors.XQuery.DefaultProcessor;
             }

             hashCode = query.GetHashCode();

             ConcurrentDictionary<int, XQueryExecutable> cache =
            inlineCache.GetOrAdd(processor, p => new ConcurrentDictionary<int, XQueryExecutable>());

             XQueryExecutable exec = cache.GetOrAdd(hashCode, i => {

            var resolver = new XmlDynamicResolver(callingAssembly);

            return processor.Compile(new StringReader(query), new XQueryCompileOptions {
               XmlResolver = resolver
            });
             });

             return new XQueryInvoker(exec, callingAssembly);
        }
Exemplo n.º 9
0
 static XQueryInvoker With(string queryUri, IXQueryProcessor processor, Assembly callingAssembly)
 {
     return With(new Uri(queryUri, UriKind.RelativeOrAbsolute), processor, callingAssembly);
 }
Exemplo n.º 10
0
        static XQueryInvoker With(Uri queryUri, IXQueryProcessor processor, Assembly callingAssembly)
        {
            if (queryUri == null) throw new ArgumentNullException("queryUri");

             var resolver = new XmlDynamicResolver(callingAssembly);

             if (!queryUri.IsAbsoluteUri) {
            queryUri = resolver.ResolveUri(null, queryUri.OriginalString);
             }

             if (processor == null) {
            processor = Processors.XQuery.DefaultProcessor;
             }

             ConcurrentDictionary<Uri, XQueryExecutable> cache =
            uriCache.GetOrAdd(processor, p => new ConcurrentDictionary<Uri, XQueryExecutable>());

             XQueryExecutable executable = cache.GetOrAdd(queryUri, u => {

            using (var stylesheetSource = (Stream)resolver.GetEntity(queryUri, null, typeof(Stream))) {
               return processor.Compile(stylesheetSource, new XQueryCompileOptions {
                  BaseUri = queryUri,
                  XmlResolver = resolver
               });
            }
             });

             return new XQueryInvoker(executable, callingAssembly);
        }
Exemplo n.º 11
0
        static XQueryInvoker WithQuery(string query, IXQueryProcessor processor, Assembly callingAssembly)
        {
            int hashCode;

             return WithQuery(query, processor, callingAssembly, out hashCode);
        }
Exemplo n.º 12
0
 static XQueryInvoker With(string queryUri, IXQueryProcessor processor, Assembly callingAssembly)
 {
     return(With(new Uri(queryUri, UriKind.RelativeOrAbsolute), processor, callingAssembly));
 }
Exemplo n.º 13
0
 public static XQueryInvoker With(Uri queryUri, IXQueryProcessor processor)
 {
     return(With(queryUri, processor, Assembly.GetCallingAssembly()));
 }
Exemplo n.º 14
0
 public static XQueryInvoker With(Uri queryUri, IXQueryProcessor processor)
 {
     return With(queryUri, processor, Assembly.GetCallingAssembly());
 }
Exemplo n.º 15
0
        internal static XQueryInvoker WithQuery(int stylesheetHashCode, IXQueryProcessor processor)
        {
            if (processor == null) {
            processor = Processors.XQuery.DefaultProcessor;
             }

             return new XQueryInvoker(inlineCache[processor][stylesheetHashCode], null);
        }
Exemplo n.º 16
0
        static XQueryInvoker WithQuery(string query, IXQueryProcessor processor, Assembly callingAssembly)
        {
            int hashCode;

            return(WithQuery(query, processor, callingAssembly, out hashCode));
        }
Exemplo n.º 17
0
 public static XQueryInvoker WithQuery(string query, IXQueryProcessor processor)
 {
     return(WithQuery(query, processor, Assembly.GetCallingAssembly()));
 }
Exemplo n.º 18
0
 public static XQueryInvoker WithQuery(string query, IXQueryProcessor processor)
 {
     return WithQuery(query, processor, Assembly.GetCallingAssembly());
 }