private static Uri GetObserverUriAsync <T>(IAsyncReactiveQbserver <T> observer) { if (!TryGetUriFromKnownResource(observer, out Uri uri)) { throw new InvalidOperationException("Cannot notify an observer without a known URI-based identity. Did you get the observer through GetObserver? Did you use DefineObserverAsync to define the observer prior to usage?"); } return(uri); }
protected override Task <IAsyncReactiveQubscription> SubscribeAsyncCore(IAsyncReactiveQbserver <TOutput> observer, Uri subscriptionUri, object state, CancellationToken token) { var expr = Expression.Invoke( Expression.Parameter(typeof(Func <IAsyncReactiveQbservable <TOutput>, IAsyncReactiveQbserver <TOutput>, Uri, object, IAsyncReactiveQubscription>), "$subscribe"), Expression, observer.Expression, Expression.Constant(subscriptionUri, typeof(Uri)), Expression.Constant(state, typeof(object)) ); return(Task.FromResult <IAsyncReactiveQubscription>(Provider.CreateQubscription(expr))); }
/// <summary> /// Defines an observer identified by the specified URI. /// </summary> /// <typeparam name="T">Type of the data received by the observer.</typeparam> /// <param name="uri">URI identifying the observer.</param> /// <param name="observer">Observer to be defined.</param> /// <param name="state">Additional metadata to associate with the artifact. Implementations can interpret this value, or ignore it.</param> /// <param name="token">Token to observe for cancellation of the request.</param> /// <returns>Task to await the completion of the observer definition.</returns> public Task DefineObserverAsync <T>(Uri uri, IAsyncReactiveQbserver <T> observer, object state = null, CancellationToken token = default) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } if (observer == null) { throw new ArgumentNullException(nameof(observer)); } return(DefineObserverAsyncCore <T>(uri, observer, state, token)); }
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); }
public static IAsyncReactiveQubscription Subscribe <T>(this IAsyncReactiveQbservable <T> observable, IAsyncReactiveQbserver <T> observer) { var method = ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(T)); return(observer.Provider.CreateQubscription(Expression.Call(method, observable.Expression, observer.Expression))); }
protected override Task <IAsyncReactiveQubscription> SubscribeAsyncCore(IAsyncReactiveQbserver <T> observer, Uri subscriptionUri, object state, CancellationToken token) { return(((AsyncReactiveQueryProviderBase)base.Provider).SubscribeAsync <T>(this, observer, subscriptionUri, state, token)); }
/// <summary> /// Defines an observer identified by the specified URI. /// </summary> /// <typeparam name="T">Type of the data received by the observer.</typeparam> /// <param name="uri">URI identifying the observer.</param> /// <param name="observer">Observer to be defined.</param> /// <param name="state">Additional metadata to associate with the artifact. Implementations can interpret this value, or ignore it.</param> /// <param name="token">Token to observe for cancellation of the request.</param> /// <returns>Task to await the completion of the observer definition.</returns> protected override Task DefineObserverAsyncCore <T>(Uri uri, IAsyncReactiveQbserver <T> observer, object state = null, CancellationToken token = default) { var expression = _expressionServices.Normalize(observer.Expression); return(_provider.DefineObserverAsync(uri, expression, state, token)); }
/// <summary> /// This method is not supported because an instance of this type is only created to hold an /// expression tree used to dispatch to the underlying method. /// </summary> /// <param name="observer">Observer used for the subscription.</param> /// <param name="subscriptionUri">URI representing the subscription.</param> /// <param name="state">State passed to the subscription creation operation.</param> /// <param name="token">Token to observe cancellation requests.</param> /// <returns>This method always throws an exception.</returns> protected override Task <IAsyncReactiveQubscription> SubscribeAsyncCore(IAsyncReactiveQbserver <T> observer, Uri subscriptionUri, object state, CancellationToken token) { throw new NotImplementedException(); }
public TestableQbserver(Uri observerId, IAsyncReactiveQbserver <T> inner, IReactivePlatform platform) { _observerId = observerId; _inner = inner; _platform = platform; }
public static IAsyncReactiveQbservable <T> Do <T>(this IAsyncReactiveQbservable <T> source, IAsyncReactiveQbserver <T> observer) { return(source.Provider.CreateQbservable <T>( Expression.Call( ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(T)), source.Expression, observer.Expression ) )); }
/// <summary> /// Defines an observer identified by the specified URI. /// </summary> /// <typeparam name="T">Type of the data received by the observer.</typeparam> /// <param name="uri">URI identifying the observer.</param> /// <param name="observer">Observer to be defined.</param> /// <param name="state">Additional metadata to associate with the artifact. Implementations can interpret this value, or ignore it.</param> /// <param name="token">Token to observe for cancellation of the request.</param> /// <returns>Task to await the completion of the observer definition.</returns> protected abstract Task DefineObserverAsyncCore <T>(Uri uri, IAsyncReactiveQbserver <T> observer, object state = null, CancellationToken token = default);
public Task <IAsyncReactiveQubscription> SubscribeAsync(IAsyncReactiveQbserver <T> observer, Uri subscriptionUri, object state, CancellationToken token) { _testClient.CleanupEntity(subscriptionUri, ReactiveEntityType.Subscription); return(_inner.SubscribeAsync(observer, subscriptionUri, state, token)); }
/// <summary> /// Gets an observer to send notifications to. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="observer">Expression tree representation of an observer to get a publication observer for.</param> /// <param name="token">Token used to observe cancellation requests.</param> /// <returns>Observer to send notifications to.</returns> protected override Task <IAsyncReactiveObserver <T> > GetObserverAsyncCore <T>(IAsyncReactiveQbserver <T> observer, CancellationToken token) { var observerUri = GetObserverUriAsync(observer); return(_provider.GetObserverAsync <T>(observerUri, token)); }
internal Task <IAsyncReactiveObserver <T> > GetObserverAsync <T>(IAsyncReactiveQbserver <T> observer, CancellationToken token) => GetObserverAsyncCore <T>(observer, token);
/// <summary> /// Defines an observer identified by the specified URI. /// </summary> /// <typeparam name="T">Type of the data received by the observer.</typeparam> /// <param name="uri">URI identifying the observer.</param> /// <param name="observer">Observer to be defined.</param> /// <param name="state">Additional metadata to associate with the artifact. Implementations can interpret this value, or ignore it.</param> /// <param name="token">Token to observe for cancellation of the request.</param> /// <returns>Task to await the completion of the observer definition.</returns> public Task DefineObserverAsync <T>(Uri uri, IAsyncReactiveQbserver <T> observer, object state = null, CancellationToken token = default) => Definition.DefineObserverAsync(uri, observer, state, token);
/// <summary> /// Gets an observer to send notifications to. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="observer">Expression tree representation of an observer to get a publication observer for.</param> /// <param name="token">Token used to observe cancellation requests.</param> /// <returns>Observer to send notifications to.</returns> protected abstract Task <IAsyncReactiveObserver <T> > GetObserverAsyncCore <T>(IAsyncReactiveQbserver <T> observer, CancellationToken token);
public Qubject(Expression expression, IAsyncReactiveQueryProvider provider) : base(provider) { Expression = expression; _observer = provider.CreateQbserver <TInput>(expression); }