private Expression PrepareExpression(out IQbservableProvider realProvider) { Contract.Ensures(Contract.ValueAtReturn(out realProvider) != null); Contract.Ensures(Contract.Result <Expression>() != null); Log.ServerReceivingExpression(clientId, Expression); var source = Provider.GetSource(argument); realProvider = source.Provider; ExpressionVisitor visitor; Expression preparedExpression = null; if (!Provider.Options.AllowExpressionsUnrestricted) { visitor = new SecurityExpressionVisitor(Provider.Options); preparedExpression = visitor.Visit(Expression); } visitor = ReplaceConstantsVisitor.Create( typeof(QbservableSourcePlaceholder <TSource>), source, typeof(IQbservable <TSource>), (actualTypeInQuery, actualTypeInServer) => { throw new InvalidOperationException("The client specified the wrong data type for the query." + Environment.NewLine + "Client data type: " + actualTypeInQuery.FullName + Environment.NewLine + "Actual data type: " + actualTypeInServer.FullName); }); preparedExpression = visitor.Visit(preparedExpression ?? Expression); visitor = ReplaceConstantsVisitor.Create( typeof(DuplexCallback), (value, _) => { var callback = (DuplexCallback)value; callback.SetServerProtocol(Provider.Protocol); return(callback); }, type => type); preparedExpression = visitor.Visit(preparedExpression); foreach (var customVisitorFactory in Provider.Options.VisitorFactories) { var customVisitor = customVisitorFactory(); preparedExpression = customVisitor.Visit(preparedExpression); } Log.ServerRewrittenExpression(clientId, preparedExpression); return(preparedExpression); }
private Expression PrepareExpression(out IQbservableProvider realProvider) { QbservableProviderDiagnostics.DebugPrint(Expression, "TcpServerQuery Received Expression"); var source = Provider.GetSource(argument); realProvider = source.Provider; ExpressionVisitor visitor; Expression preparedExpression = null; if (!Provider.Options.AllowExpressionsUnrestricted) { visitor = new SecurityExpressionVisitor(Provider.Options); preparedExpression = visitor.Visit(Expression); } visitor = ReplaceConstantsVisitor.Create( typeof(QbservableSourcePlaceholder <TSource>), source, typeof(IQbservable <TSource>), (actualTypeInQuery, actualTypeInServer) => { throw new InvalidOperationException("The client specified the wrong data type for the query." + Environment.NewLine + "Client data type: " + actualTypeInQuery.FullName + Environment.NewLine + "Actual data type: " + actualTypeInServer.FullName); }); preparedExpression = visitor.Visit(preparedExpression ?? Expression); visitor = ReplaceConstantsVisitor.Create( typeof(DuplexCallback), (value, _) => { var callback = (DuplexCallback)value; callback.SetServerProtocol(Provider.Protocol); return(callback); }, type => type); preparedExpression = visitor.Visit(preparedExpression); QbservableProviderDiagnostics.DebugPrint(preparedExpression, "TcpServerQuery Rewritten Expression"); return(preparedExpression); }