Example #1
0
        protected override void RenderView(ViewContext viewContext, TextWriter writer, object instance)
        {
            if (viewContext == null)
            {
                throw new ArgumentNullException("viewContext");
            }

            XQueryPage page = instance as XQueryPage;

            if (page == null)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Compiled view '{0}' must inherit from {1}.", this.ViewPath, typeof(XQueryPage).AssemblyQualifiedName));
            }

            page.SetIntrinsics(HttpContext.Current);
            page.AddFileDependencies();

            var options = new XQueryRuntimeOptions();

            options.ContextItem = viewContext.ViewData.Model;

            foreach (var item in viewContext.ViewData)
            {
                options.ExternalVariables[new XmlQualifiedName(item.Key)] = item.Value;
            }

            page.Render(viewContext.Writer, options);
        }
Example #2
0
 public void Render(TextWriter writer, XQueryRuntimeOptions options)
 {
     try {
         this.Executable.Run(writer, options);
     } catch (ProcessorException ex) {
         throw CreateRenderException(ex);
     }
 }
Example #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());
        }
Example #4
0
      public override void Run(TextWriter output, XQueryRuntimeOptions options) {

         if (options == null) throw new ArgumentNullException("options");

         Serializer serializer = this.Processor.ItemFactory.CreateSerializer(options.Serialization);
         serializer.SetOutputWriter(output);

         Run(serializer, options);
      }
Example #5
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());
        }
Example #6
0
        void Run(XmlDestination destination, XQueryRuntimeOptions options)
        {
            XQueryEvaluator eval = GetEvaluator(options);

            try {
                eval.Run(destination);
            } catch (DynamicError ex) {
                throw new SaxonException(ex);
            } catch (Exception ex) {
                throw new SaxonException(ex.Message, ex);
            }
        }
Example #7
0
        public override void Run(TextWriter output, XQueryRuntimeOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            Serializer serializer = this.Processor.ItemFactory.CreateSerializer(options.Serialization);

            serializer.SetOutputWriter(output);

            Run(serializer, options);
        }
Example #8
0
        public override IEnumerable <XPathItem> Run(XQueryRuntimeOptions options)
        {
            XQueryEvaluator eval = GetEvaluator(options);

            XdmValue val;

            try {
                val = eval.Evaluate();
            } catch (DynamicError ex) {
                throw new SaxonException(ex);
            } catch (Exception ex) {
                throw new SaxonException(ex.Message, ex);
            }

            return(val.ToXPathItems());
        }
Example #9
0
      public override IEnumerable<XPathItem> Run(XQueryRuntimeOptions options) {

         XQueryEvaluator eval = GetEvaluator(options);

         XdmValue val;

         try {
            val = eval.Evaluate();

         } catch (DynamicError ex) {
            throw new SaxonException(ex);

         } catch (Exception ex) {
            throw new SaxonException(ex.Message, ex);
         }

         return val.ToXPathItems();
      }
Example #10
0
        XQueryRuntimeOptions GetRuntimeOptions(XPathItem input, IEnumerable <XPathNavigator> parameters)
        {
            var options = new XQueryRuntimeOptions();

            if (input != null)
            {
                options.ContextItem = input;
            }

            if (parameters != null)
            {
                foreach (XPathNavigator n in parameters)
                {
                    options.ExternalVariables.Add(new XmlQualifiedName(n.Name, n.NamespaceURI), n.TypedValue);
                }
            }

            return(options);
        }
Example #11
0
        public XQueryResultHandler Query(object input, object parameters)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            var options = new XQueryRuntimeOptions {
                ContextItem      = input,
                InputXmlResolver = new XmlDynamicResolver(this.withCallingAssembly)
            };

            if (parameters != null)
            {
                foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(parameters))
                {
                    options.ExternalVariables.Add(new XmlQualifiedName(property.Name), property.GetValue(parameters));
                }
            }

            return(Query(options));
        }
Example #12
0
        XQueryEvaluator GetEvaluator(XQueryRuntimeOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            XQueryEvaluator eval = this.executable.Load();

            if (options.InputXmlResolver != null)
            {
                eval.InputXmlResolver = options.InputXmlResolver;

                XmlDynamicResolver dynamicResolver = options.InputXmlResolver as XmlDynamicResolver;

                if (dynamicResolver != null &&
                    dynamicResolver.DefaultBaseUri == null)
                {
                    dynamicResolver.DefaultBaseUri = this.StaticBaseUri;
                }
            }

            if (options.ContextItem != null)
            {
                eval.ContextItem = options.ContextItem.ToXdmItem(this.Processor.ItemFactory);
            }

            foreach (var pair in options.ExternalVariables)
            {
                var      qname    = new QName(pair.Key);
                XdmValue xdmValue = pair.Value.ToXdmValue(this.Processor.ItemFactory);

                eval.SetExternalVariable(qname, xdmValue);
            }

            return(eval);
        }
Example #13
0
      void Run(XmlDestination destination, XQueryRuntimeOptions options) {

         XQueryEvaluator eval = GetEvaluator(options);

         try {
            eval.Run(destination);

         } catch (DynamicError ex) {
            throw new SaxonException(ex);

         } catch (Exception ex) {
            throw new SaxonException(ex.Message, ex);
         }
      }
Example #14
0
 internal XQueryResultHandler(XQueryExecutable executable, XQueryRuntimeOptions options)
 {
     this.executable           = executable;
     this.options              = options;
     this.defaultSerialization = options.Serialization;
 }
Example #15
0
        public override void Run(XmlWriter output, XQueryRuntimeOptions options)
        {
            XmlDestination builder = new TextWriterDestination(output);

            Run(builder, options);
        }
Example #16
0
      XQueryEvaluator GetEvaluator(XQueryRuntimeOptions options) {
         
         if (options == null) throw new ArgumentNullException("options");
         
         XQueryEvaluator eval = this.executable.Load();

         if (options.InputXmlResolver != null)
            eval.InputXmlResolver = options.InputXmlResolver;

         if (options.ContextItem != null) 
            eval.ContextItem = options.ContextItem.ToXdmItem(this.Processor.ItemFactory);

         foreach (var pair in options.ExternalVariables) {

            QName qname = new QName(pair.Key);
            XdmValue xdmValue = pair.Value.ToXdmValue(this.Processor.ItemFactory);

            eval.SetExternalVariable(qname, xdmValue);
         }

         return eval;
      }
Example #17
0
      public override void Run(XmlWriter output, XQueryRuntimeOptions options) {

         XmlDestination builder = new TextWriterDestination(output);

         Run(builder, options);
      }
Example #18
0
 public XQueryResultHandler Query(XQueryRuntimeOptions options)
 {
     return(new XQueryResultHandler(this.executable, options));
 }