public Expression PrepareExpression(IQbservableProtocol protocol) { Contract.Requires(protocol != null); Contract.Ensures(Contract.Result <Expression>() != null); Log.ClientSendingExpression(clientId, Expression); if (!Expression.Type.GetIsGenericType() || (Expression.Type.GetGenericTypeDefinition() != typeof(IQbservable <>) && Expression.Type.GetGenericTypeDefinition() != typeof(ClientQuery <>))) { throw new InvalidOperationException("The query must end as an IQbservable<T>."); } var visitor = ReplaceConstantsVisitor.CreateForGenericTypeByDefinition( typeof(ClientQuery <>), #if REFLECTION (_, actualType) => Activator.CreateInstance(typeof(QbservableSourcePlaceholder <>).MakeGenericType(actualType.GetGenericArguments()[0]), true), #else (_, actualType) => Activator.CreateInstance(typeof(QbservableSourcePlaceholder <>).MakeGenericType(actualType.GetGenericArguments()[0])), #endif type => typeof(IQbservable <>).MakeGenericType(type.GetGenericArguments()[0])); var result = visitor.Visit(Expression); if (visitor.ReplacedConstants == 0) { throw new InvalidOperationException("A queryable observable service was not found in the query."); } var evaluator = Provider.ClientEvaluator; if (!evaluator.IsKnownType(Provider.SourceType)) { evaluator.AddKnownType(Provider.SourceType); } var evaluationVisitor = new LocalEvaluationVisitor(evaluator, protocol); var preparedExpression = evaluationVisitor.Visit(result); Contract.Assume(!evaluationVisitor.HasAnyExpectedTypes); Log.ClientRewrittenExpression(clientId, preparedExpression); return(preparedExpression); }
public Expression PrepareExpression(QbservableProtocol protocol) { QbservableProviderDiagnostics.DebugPrint(Expression, "TcpClientQuery Original Expression"); if (!Expression.Type.IsGenericType || (Expression.Type.GetGenericTypeDefinition() != typeof(IQbservable <>) && Expression.Type.GetGenericTypeDefinition() != typeof(TcpClientQuery <>))) { throw new InvalidOperationException("The query must end as an IQbservable<T>."); } var visitor = ReplaceConstantsVisitor.CreateForGenericTypeByDefinition( typeof(TcpClientQuery <>), (_, actualType) => Activator.CreateInstance(typeof(QbservableSourcePlaceholder <>).MakeGenericType(actualType.GetGenericArguments()[0]), true), type => typeof(IQbservable <>).MakeGenericType(type.GetGenericArguments()[0])); var result = visitor.Visit(Expression); if (visitor.ReplacedConstants == 0) { throw new InvalidOperationException("A queryable observable service was not found in the query."); } var evaluator = Provider.LocalEvaluator; if (!evaluator.IsKnownType(Provider.SourceType)) { evaluator.AddKnownType(Provider.SourceType); } var evaluationVisitor = new LocalEvaluationVisitor(evaluator, protocol); var preparedExpression = evaluationVisitor.Visit(result); QbservableProviderDiagnostics.DebugPrint(preparedExpression, "TcpClientQuery Rewritten Expression"); return(preparedExpression); }