Example #1
0
        internal async Task <IAsyncReactiveQubscription> SubscribeAsync <T>(IAsyncReactiveQbservable <T> observable, IAsyncReactiveQbserver <T> observer, Uri subscriptionUri, object state, CancellationToken token)
        {
            var subscribe = Expression.Parameter(typeof(Func <IAsyncReactiveQbservable <T>, IAsyncReactiveQbserver <T>, Task <IAsyncReactiveQubscription> >), Constants.SubscribeUri);

            var observableExpression = observable.Expression;

            if (observableExpression.Type != typeof(IAsyncReactiveQbservable <T>) && observableExpression.NodeType == ExpressionType.Parameter)
            {
                observableExpression = Expression.Parameter(typeof(IAsyncReactiveQbservable <T>), ((ParameterExpression)observableExpression).Name);
            }

            var observerExpression = observer.Expression;

            if (observerExpression.Type != typeof(IAsyncReactiveQbserver <T>) && observerExpression.NodeType == ExpressionType.Parameter)
            {
                observerExpression = Expression.Parameter(typeof(IAsyncReactiveQbserver <T>), ((ParameterExpression)observerExpression).Name);
            }

            var expression = Expression.Invoke(subscribe, observableExpression, observerExpression);

            var normalized = ExpressionServices.Normalize(expression);

            var subscription = new KnownQubscription(normalized, subscriptionUri, this);

            await CreateSubscriptionAsync(subscription, state, token).ConfigureAwait(false);

            return(subscription);
        }
Example #2
0
        internal IReactiveQubscription Subscribe <T>(IReactiveQbservable <T> observable, IReactiveQbserver <T> observer, Uri subscriptionUri, object state)
        {
            var subscribe = Expression.Parameter(typeof(Func <IReactiveQbservable <T>, IReactiveQbserver <T>, IReactiveQubscription>), Constants.SubscribeUri);

            var observableExpression = observable.Expression;

            if (observableExpression.Type != typeof(IReactiveQbservable <T>) && observableExpression.NodeType == ExpressionType.Parameter)
            {
                observableExpression = Expression.Parameter(typeof(IReactiveQbservable <T>), ((ParameterExpression)observableExpression).Name);
            }

            var observerExpression = observer.Expression;

            if (observerExpression.Type != typeof(IReactiveQbserver <T>) && observerExpression.NodeType == ExpressionType.Parameter)
            {
                observerExpression = Expression.Parameter(typeof(IReactiveQbserver <T>), ((ParameterExpression)observerExpression).Name);
            }

            var expression = Expression.Invoke(subscribe, observableExpression, observerExpression);

            var normalized = ExpressionServices.Normalize(expression);

            var subscription = new KnownQubscription(normalized, subscriptionUri, this);

            CreateSubscription(subscription, state);

            return(subscription);
        }
Example #3
0
        internal async Task <IAsyncReactiveQubscription> CreateSubscriptionAsync(IAsyncReactiveExpressible factory, Expression[] arguments, Uri subscriptionUri, object state, CancellationToken token)
        {
            var expression = Expression.Invoke(factory.Expression, arguments);

            var normalized = ExpressionServices.Normalize(expression);

#pragma warning disable IDE0079 // Remove unnecessary suppression.
#pragma warning disable CA2000  // Dispose objects before losing scope. (IDisposable semantics are used for deletion behavior here.)

            var qubscription = new KnownQubscription(normalized, subscriptionUri, this);
            await CreateSubscriptionAsyncCore(qubscription, state, token).ConfigureAwait(false);

#pragma warning restore CA2000
#pragma warning restore IDE0079

            var parameterExpression   = Expression.Parameter(typeof(IAsyncReactiveQubscription), subscriptionUri.ToCanonicalString());
            var parameterQubscription = new KnownQubscription(parameterExpression, subscriptionUri, this);
            return(parameterQubscription);
        }