Exemple #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));
        }
Exemple #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));
        }
        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);
                }
            }
        }
Exemple #4
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);
        }
Exemple #5
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);
        }