public ExpressionBuilderParameters(ParameterExpression[] parameters, IQueryProvider queryProvider, Type elementType, IXmlNamespaceResolver namespaceResolver, bool mayRootPathBeImplied, IOperatorImplementationProvider operatorImplementationProvider, Func<Type, IXmlNamespaceResolver, XPathTypeNavigator> navigatorCreator=null) { Debug.Assert(parameters!=null); if (parameters==null) throw new ArgumentNullException("parameters"); Debug.Assert(parameters.Length>0); if (parameters.Length==0) throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, SR.ArrayShouldHaveElementsException, 1, parameters.Length ), "parameters" ); Debug.Assert(queryProvider!=null); if (queryProvider==null) throw new ArgumentNullException("queryProvider"); Debug.Assert(elementType!=null); if (elementType==null) throw new ArgumentNullException("elementType"); Parameters=new ReadOnlyCollection<ParameterExpression>(parameters); ElementType=elementType; QueryProvider=queryProvider; NamespaceResolver=namespaceResolver; MayRootPathBeImplied=mayRootPathBeImplied; OperatorImplementationProvider=operatorImplementationProvider; NavigatorCreator=navigatorCreator; }
internal LambdaExpression CreateLambda(IQueryable source, XmlNamespaceManager namespaceManager, bool mayRootPathBeImplied, IOperatorImplementationProvider operatorImplementationProvider, Func<Type, IXmlNamespaceResolver, XPathTypeNavigator> navigatorCreator=null) { Expression body=null; ParameterExpression[] parameters=new ParameterExpression[] { Expression.Parameter(source.ElementType) }; if (Untyped.Elements().Any()) { var ebp=new ExpressionBuilderParameters(parameters, source.Provider, source.ElementType, namespaceManager, mayRootPathBeImplied, operatorImplementationProvider, navigatorCreator); Type st=typeof(bool); if (logicOps!=null) body=logicOps.CreateExpression(ebp, st, null); else if (comparisonOps!=null) body=comparisonOps.CreateExpression(ebp, st, null); else if (spatialOps!=null) body=spatialOps.CreateExpression(ebp, st, null); } else if (string.IsNullOrWhiteSpace(Untyped.Value)) body=Expression.Constant(true, typeof(bool)); if (body==null) throw new ArgumentException( string.Format( CultureInfo.InvariantCulture, SR.InvalidFilterDefinitionException, Untyped.Value ) ); return Expression.Lambda(body, parameters); }
public ExpressionBuilderParameters(ParameterExpression[] parameters, IQueryProvider queryProvider, Type elementType, IXmlNamespaceResolver namespaceResolver, bool mayRootPathBeImplied, IOperatorImplementationProvider operatorImplementationProvider, Func <Type, IXmlNamespaceResolver, XPathTypeNavigator> navigatorCreator = null) { Debug.Assert(parameters != null); if (parameters == null) { throw new ArgumentNullException("parameters"); } Debug.Assert(parameters.Length > 0); if (parameters.Length == 0) { throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, SR.ArrayShouldHaveElementsException, 1, parameters.Length ), "parameters" ); } Debug.Assert(queryProvider != null); if (queryProvider == null) { throw new ArgumentNullException("queryProvider"); } Debug.Assert(elementType != null); if (elementType == null) { throw new ArgumentNullException("elementType"); } Parameters = new ReadOnlyCollection <ParameterExpression>(parameters); ElementType = elementType; QueryProvider = queryProvider; NamespaceResolver = namespaceResolver; MayRootPathBeImplied = mayRootPathBeImplied; OperatorImplementationProvider = operatorImplementationProvider; NavigatorCreator = navigatorCreator; }
public static IQueryable Where(this IQueryable source, string constraint, XmlNamespaceManager namespaceManager = null, bool mayRootPathBeImplied = false, IOperatorImplementationProvider operatorImplementationProvider = null) { Debug.Assert(source != null); if (source == null) { throw new ArgumentNullException("source"); } Debug.Assert(!string.IsNullOrEmpty(constraint)); if (constraint == null) { throw new ArgumentNullException("constraint"); } var parser = new Parser(LanguageData); ParseTree tree = parser.Parse(constraint); if (tree.ParserMessages.Count > 0) { var logger = LogManager.GetCurrentClassLogger(); var exl = new List <Exception>(); foreach (LogMessage lm in tree.ParserMessages) { switch (lm.Level) { case ErrorLevel.Error: logger.Error(CultureInfo.InvariantCulture, m => m("({0},{1}): {2}", lm.Location.Line, lm.Location.Column, lm.Message)); exl.Add( new ArgumentException( string.Format( parser.Context.Culture, SR.CqlSyntaxErrorException, constraint, lm.Location.Line, lm.Location.Column, lm.Level, lm.Message ), "constraint" ) ); break; case ErrorLevel.Info: logger.Info(CultureInfo.InvariantCulture, m => m("({0},{1}): {2}", lm.Location.Line, lm.Location.Column, lm.Message)); break; default: logger.Warn(CultureInfo.InvariantCulture, m => m("({0},{1}): {2}", lm.Location.Line, lm.Location.Column, lm.Message)); break; } } if (exl.Count > 0) { throw new AggregateException(exl); } } var parameters = new ParameterExpression[] { Expression.Parameter(source.ElementType) }; var ebp = new ExpressionBuilderParameters(parameters, source.Provider, source.ElementType, namespaceManager, mayRootPathBeImplied, operatorImplementationProvider); LambdaExpression lambda = Expression.Lambda(((Ast.IExpressionBuilder)tree.Root.AstNode).CreateExpression(ebp, typeof(bool), null), parameters); return(source.Provider.CreateQuery( Expression.Call( typeof(Queryable), "Where", new Type[] { source.ElementType }, source.Expression, Expression.Quote(lambda) ) )); }
public static IQueryable <T> Where <T>(this IQueryable <T> source, string constraint, XmlNamespaceManager namespaceManager = null, bool mayRootPathBeImplied = false, IOperatorImplementationProvider operatorImplementationProvider = null) { return((IQueryable <T>)Where((IQueryable)source, constraint, namespaceManager, mayRootPathBeImplied, operatorImplementationProvider)); }
//TODO: compile LINQ expression? internal IQueryable Where(IQueryable source, IEnumerable <Uri> ids, XmlNamespaceManager namespaceManager = null, IOperatorImplementationProvider operatorImplementationProvider = null) { var parameters = new ParameterExpression[] { Expression.Parameter(source.ElementType) }; var xpqn = new XPathQueryableNavigator(source.ElementType, namespaceManager); XPathNodeIterator xpni = xpqn.Select(CoreQueryable.Identifier.Name, namespaceManager); if (xpni.MoveNext()) { var idn = (XPathQueryableNavigator)xpni.Current; Type idType = idn.Type; TypeConverter converter = GetIdentifierUriConverter(idType); // Convert ids from Uris to identifier type // urip => (idType)converter.ConvertTo(urip, idType) var urip = Expression.Parameter(typeof(Uri)); var conex = Expression.Lambda( typeof(Func <,>).MakeGenericType(typeof(Uri), idType), Expression.Convert( Expression.Call( Expression.Constant(converter), "ConvertTo", null, urip, Expression.Constant(idType) ), idType ), urip ); // var convertedIds=ids.Select<Uri, idType>(uri => (idType)converter.ConvertTo(uri, idType)) var urilistp = Expression.Parameter(typeof(IEnumerable <Uri>)); var convertids = Expression.Lambda( Expression.Call( typeof(Enumerable), "Select", new Type[] { typeof(Uri), idType }, Expression.Constant(ids), conex ), urilistp ).Compile(); var convertedIds = convertids.DynamicInvoke(ids); // Creates the Where clause LambdaExpression lambda = Expression.Lambda( Expression.Call( typeof(Enumerable), "Contains", new Type[] { idType }, Expression.Constant(convertedIds), idn.CreateExpression(parameters[0]) ), parameters ); return(source.Provider.CreateQuery( Expression.Call( typeof(Queryable), "Where", new Type[] { source.ElementType }, source.Expression, Expression.Quote(lambda) ) )); } throw new InvalidOperationException(); }
public static IQueryable Where(this IQueryable source, Filter filter, XmlNamespaceManager namespaceManager = null, bool mayRootPathBeImplied = false, IOperatorImplementationProvider operatorImplementationProvider = null, Func <Type, IXmlNamespaceResolver, XPathTypeNavigator> navigatorCreator = null) { Debug.Assert(source != null); if (source == null) { throw new ArgumentNullException("source"); } Debug.Assert(filter != null); if (filter == null) { throw new ArgumentNullException("filter"); } LambdaExpression lambda = filter.CreateLambda(source, namespaceManager, mayRootPathBeImplied, operatorImplementationProvider, navigatorCreator); return(source.Provider.CreateQuery( Expression.Call( typeof(Queryable), "Where", new Type[] { source.ElementType }, source.Expression, Expression.Quote(lambda) ) )); }
public static IQueryable <T> Where <T>(this IQueryable <T> source, Filter filter, XmlNamespaceManager namespaceManager = null, bool mayRootPathBeImplied = false, IOperatorImplementationProvider operatorImplementationProvider = null, Func <Type, IXmlNamespaceResolver, XPathTypeNavigator> navigatorCreator = null) { return((IQueryable <T>)Where((IQueryable)source, filter, namespaceManager, mayRootPathBeImplied, operatorImplementationProvider)); }
internal static IQueryable Where(this IQueryable source, Types.Constraint constraint, XmlNamespaceManager namespaceManager = null, bool mayRootPathBeImplied = false, IOperatorImplementationProvider operatorImplementationProvider = null) { Debug.Assert(source != null); if (source == null) { throw new ArgumentNullException("source"); } Debug.Assert(constraint != null); if (constraint == null) { throw new ArgumentNullException("constraint"); } IQueryable ret = source; //if (constraint.Filter!=null) if (constraint.Untyped.Descendants("{http://www.opengis.net/ogc}Filter").Any <XElement>()) { ret = Filter110.FilterQueryable.Where(ret, constraint.Filter, namespaceManager, mayRootPathBeImplied, operatorImplementationProvider, (t, r) => new XPathQueryableNavigator(t, r)); } if (!string.IsNullOrWhiteSpace(constraint.CqlText)) { ret = Cql.CqlQueryable.Where(ret, constraint.CqlText, namespaceManager, mayRootPathBeImplied, operatorImplementationProvider); } return(ret); }
internal LambdaExpression CreateLambda(IQueryable source, XmlNamespaceManager namespaceManager, bool mayRootPathBeImplied, IOperatorImplementationProvider operatorImplementationProvider, Func <Type, IXmlNamespaceResolver, XPathTypeNavigator> navigatorCreator = null) { Expression body = null; ParameterExpression[] parameters = new ParameterExpression[] { Expression.Parameter(source.ElementType) }; if (Untyped.Elements().Any()) { var ebp = new ExpressionBuilderParameters(parameters, source.Provider, source.ElementType, namespaceManager, mayRootPathBeImplied, operatorImplementationProvider, navigatorCreator); Type st = typeof(bool); if (logicOps != null) { body = logicOps.CreateExpression(ebp, st, null); } else if (comparisonOps != null) { body = comparisonOps.CreateExpression(ebp, st, null); } else if (spatialOps != null) { body = spatialOps.CreateExpression(ebp, st, null); } } else if (string.IsNullOrWhiteSpace(Untyped.Value)) { body = Expression.Constant(true, typeof(bool)); } if (body == null) { throw new ArgumentException( string.Format( CultureInfo.InvariantCulture, SR.InvalidFilterDefinitionException, Untyped.Value ) ); } return(Expression.Lambda(body, parameters)); }