public void Execute (XPathNavigator input, XmlResolver resolver, XmlArgumentList args, XmlWriter writer) { if (staticContext == null) throw new XmlQueryException ("Query string is not compiled."); // Initialize event handler method info. xqueryCommandOnMessageEventMethod = null; XQueryContext ctx = new XQueryContext (new XQueryContextManager (staticContext, input, writer, resolver, args)); XPathSequence iter = new SingleItemIterator (input, ctx); foreach (ExprSingle expr in staticContext.QueryBody) expr.Serialize (iter); }
public static object FnTrace (XQueryContext ctx, object value, string label) { if (value == null) return new XPathEmptySequence (ctx); XPathSequence seq = value as XPathSequence; if (seq == null) { XPathAtomicValue av = value as XPathAtomicValue; if (av == null) av = new XPathAtomicValue (value, InternalPool.GetBuiltInType ( InternalPool.XmlTypeCodeFromRuntimeType ( value.GetType (), true))); seq = new SingleItemIterator (av, ctx); } return new TracingIterator (seq, label); }
private SingleItemIterator (SingleItemIterator other) : base (other) { this.item = other.item; this.current = other.current; }
public override object Invoke (XPathSequence current, object [] args) { MethodInfo mi = methods [args.Length] as MethodInfo; if (mi == null) throw new ArgumentException ("The number of custom function parameter does not match with the registered method's signature."); ParameterInfo [] prms = mi.GetParameters (); // Use Evidence and PermissionSet.Demand() here // before invoking external function. Evidence e = current.Context.StaticContext.Evidence; if (e != null) SecurityManager.ResolvePolicy (e).Demand (); Type t = prms.Length > 0 ? prms [0].ParameterType : null; bool ctxSeq = mi.GetCustomAttributes ( typeof (XQueryFunctionContextAttribute), false).Length > 0; if (t == typeof (XQueryContext)) { ArrayList pl = new ArrayList (args); pl.Insert (0, current.Context); args = pl.ToArray (); } else if (ctxSeq) { ArrayList pl = new ArrayList (args); pl.Insert (0, current); args = pl.ToArray (); } if (args.Length != prms.Length) throw new XmlQueryException (String.Format ("Argument numbers were different for function {0}. Signature requires {1} while actual call was {2}.", mi.Name, prms.Length, args.Length)); // If native parameter type is XPathSequence and the actual values are not, adjust them for (int i = 0; i < args.Length; i++) { if (prms [i].ParameterType == typeof (XPathSequence) && !(args [i] is XPathSequence)) { XPathItem item = args [i] as XPathItem; if (item == null) item = args [i] == null ? null : new XPathAtomicValue (args [i], InternalPool.GetBuiltInType (InternalPool.XmlTypeCodeFromRuntimeType (prms [i].ParameterType, true))); if (item == null) args [i] = new XPathEmptySequence (current.Context); else args [i] = new SingleItemIterator (item, current.Context); } } return mi.Invoke (null, args); }