public TestableQbservable(Uri observableId, IList <Recorded <INotification <T> > > messages, IAsyncReactiveQbservable <T> inner, ITestReactivePlatformClient testClient) { _observableId = observableId; ObserverMessages = messages; _inner = inner; _testClient = testClient; }
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 IAsyncReactiveQbservable <TResult> OfType <TResult>(this IAsyncReactiveQbservable <object> source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.Provider.CreateQbservable <TResult>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)), source.Expression))); }
public static IAsyncReactiveQbservable <TSource> Take <TSource>(this IAsyncReactiveQbservable <TSource> source, int count) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.Provider.CreateQbservable <TSource>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, Expression.Constant(count)))); }
public static IAsyncReactiveQbservable <double> Average(this IAsyncReactiveQbservable <double> source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.Provider.CreateQbservable <double>(Expression.Call((MethodInfo)MethodBase.GetCurrentMethod(), source.Expression))); }
public static IAsyncReactiveQbservable <T> Where <T>(this IAsyncReactiveQbservable <T> source, Expression <Func <T, bool> > predicate) { return(source.Provider.CreateQbservable <T>( Expression.Call( ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(T)), source.Expression, predicate ) )); }
public static IAsyncReactiveQbservable <R> SelectMany <T, R>(this IAsyncReactiveQbservable <T> source, Expression <Func <T, IAsyncReactiveQbservable <R> > > resultSelector) { return(source.Provider.CreateQbservable <R>( Expression.Call( ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(T), typeof(R)), source.Expression, resultSelector ) )); }
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 ) )); }
public static IAsyncReactiveQbservable <TSource> DoHttpPost <TSource>( this IAsyncReactiveQbservable <TSource> source, Expression <Func <TSource, Uri> > getUri, Expression <Func <TSource, string> > getBody, Expression <Func <TSource, Tuple <string, string>[]> > getHeaders = null) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (getUri == null) { throw new ArgumentNullException(nameof(getUri)); } if (getBody == null) { throw new ArgumentNullException(nameof(getBody)); } var item = Expression.Parameter(typeof(TSource)); var bindings = new List <MemberBinding> { Expression.Bind(typeof(HttpPost).GetProperty("Uri"), getUri.Apply(item)), Expression.Bind(typeof(HttpPost).GetProperty("Body"), getBody.Apply(item)) }; if (getHeaders != null) { bindings.Add(Expression.Bind(typeof(HttpPost).GetProperty("Headers"), getHeaders.Apply(item))); } var newHttpPost = Expression.MemberInit( Expression.New(typeof(HttpPost)), bindings); var poster = source.Provider.CreateQbserver <HttpPost>(Expression.Parameter( typeof(IAsyncReactiveQbserver <HttpPost>), Constants.Observer.Action.HttpPost.String)); #pragma warning disable IDE0034 // Simplify 'default' expression (documents the signature) var callOnNext = Expression.Call( poster.Expression, (MethodInfo)ReflectionHelpers.InfoOf((IAsyncReactiveQbserver <HttpPost> iv) => iv.OnNextAsync(default(HttpPost), default(CancellationToken))), newHttpPost, Expression.Default(typeof(CancellationToken))); #pragma warning restore IDE0034 // Simplify 'default' expression var onNext = Expression.Lambda <Action <TSource> >(callOnNext, item); return(source.Do(onNext)); }
/// <summary> /// Creates a local observable that, when subscribed to, sets up a /// remote subscription that pushes values back to the client through /// the messaging role. /// </summary> /// <typeparam name="T">The message type.</typeparam> /// <param name="source">The remote observable.</param> /// <param name="platform">The platform containing the messaging connection.</param> /// <returns>The local observable.</returns> public static IObservable <T> AsObservable <T>(this IAsyncReactiveQbservable <T> source, IReactivePlatform platform) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (platform == null) { throw new ArgumentNullException(nameof(platform)); } return(new Impl <T>(source, platform)); }
/// <summary> /// Defines an observable identified by the specified URI. /// </summary> /// <typeparam name="T">Type of the data produced by the observable.</typeparam> /// <param name="uri">URI identifying the observable.</param> /// <param name="observable">Observable 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 observable definition.</returns> public Task DefineObservableAsync <T>(Uri uri, IAsyncReactiveQbservable <T> observable, object state = null, CancellationToken token = default) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } if (observable == null) { throw new ArgumentNullException(nameof(observable)); } return(DefineObservableAsyncCore <T>(uri, observable, state, token)); }
public static IAsyncReactiveQbservable <double> Average <TSource>(this IAsyncReactiveQbservable <TSource> source, Expression <Func <TSource, double> > selector) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (selector == null) { throw new ArgumentNullException(nameof(selector)); } return(source.Provider.CreateQbservable <double>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, selector))); }
public static IAsyncReactiveQbservable <TSource> Where <TSource>(this IAsyncReactiveQbservable <TSource> source, Expression <Func <TSource, int, bool> > predicate) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (predicate == null) { throw new ArgumentNullException(nameof(predicate)); } return(source.Provider.CreateQbservable <TSource>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, predicate))); }
public static IAsyncReactiveQbservable <TSource> DelaySubscriptionV2 <TSource>( this IAsyncReactiveQbservable <TSource> source, DateTimeOffset dueTime) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.Provider.CreateQbservable <TSource>( Expression.Call( ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, Expression.Constant(dueTime)))); }
public static IAsyncReactiveQbservable <TResult> Scan <TSource, TResult>(this IAsyncReactiveQbservable <TSource> source, TResult seed, Expression <Func <TResult, TSource, TResult> > aggregate) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (aggregate == null) { throw new ArgumentNullException(nameof(aggregate)); } return(source.Provider.CreateQbservable <TResult>( Expression.Call( ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TResult)), source.Expression, Expression.Constant(seed, typeof(TResult)), aggregate))); }
private static Action CreateRemoteSubscription(IAsyncReactiveQbservable <T> source, Uri uri) { var observer = source.Provider.CreateQbserver <Uri, T>( Expression.Parameter(typeof(Uri)).Let(u => Expression.Lambda <Func <Uri, IAsyncReactiveQbserver <T> > >( Expression.Invoke( Expression.Parameter( typeof(Func <Uri, IAsyncReactiveQbserver <T> >), Platform.Constants.Identifiers.Observer.FireHose.String ), u ), u ) ) ); var sub = source.SubscribeAsync(observer(uri), uri, null, CancellationToken.None).Result; return(() => sub.DisposeAsync(CancellationToken.None).Wait()); }
public static IAsyncReactiveQbservable <R> Select <T, R>(IAsyncReactiveQbservable <T> source, Func <T, R> selector) { throw new NotImplementedException(); }
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))); }
public IAsyncReactiveQbservable <TrafficInfo> GetTrafficTimeToLeaveValidationNoFlowEventsQuery(IAsyncReactiveQbservable <TrafficInfo> source, long now) { string noTrafficSubscriptionId = "NoTrafficNotify"; int notificationThresholdInSecs = 900; int renotificationThresholdInSecs = notificationThresholdInSecs; TimeSpan extraBuffer = TimeSpan.FromMinutes(2); TimeSpan travelTimeWithoutTraffic = TimeSpan.FromSeconds(1800); TimeSpan overhead = extraBuffer; DateTimeOffset eventStartTime = new DateTimeOffset(now, TimeSpan.Zero) + travelTimeWithoutTraffic + overhead + TimeSpan.FromMinutes(1); DateTimeOffset noTrafficNotifyTime = eventStartTime - travelTimeWithoutTraffic - overhead; DateTimeOffset startMonitoring = new DateTimeOffset(now, TimeSpan.Zero); DateTimeOffset stopMonitoring = noTrafficNotifyTime + TimeSpan.FromMinutes(1); string startAddress = "Start"; string endAddress = "End"; return (source .DelaySubscription(startMonitoring) .TakeUntil(stopMonitoring) .Select(traffic => this.Timer( // the right time to fire is the different between UTC now and the right // time to leave for the event. The right time to leave is the UTC event // start time minus the travel duration without traffic, minus the traffic // delay minus the minimum threshold to trigger a traffic notification // minus a configurable extra buffer eventStartTime - TimeSpan.FromSeconds(traffic.FlowInfo.FreeFlowTravelDurationInSeconds) - TimeSpan.FromSeconds(traffic.FlowInfo.DelayInSeconds) - TimeSpan.FromSeconds(notificationThresholdInSecs) - extraBuffer) .Select(_ => traffic)) .StartWith(this.Timer(noTrafficNotifyTime).Select(_ => new TrafficInfo() { FlowInfo = new TrafficFlowInfo() { DelayInSeconds = 0, FreeFlowTravelDurationInSeconds = (int)travelTimeWithoutTraffic.TotalSeconds, HovDelayInSeconds = 0, }, NotificationType = NotificationTypeEnum.Flow, Subscription = new TrafficParameters() { StartAddress = startAddress, EndAddress = endAddress, StartTime = startMonitoring, EndTime = stopMonitoring, FlowParameters = new TrafficFlowParameters() { NotificationThresholdInSeconds = notificationThresholdInSecs, RenotificationThresholdInSeconds = renotificationThresholdInSecs } }, SubscriptionId = noTrafficSubscriptionId, TimestampUTC = DateTime.UtcNow })) .Switch() .Take(1)); }
public IAsyncReactiveQbservable <TrafficInfo> GetTrafficIncidentsBackwardsCompatibleQuery(IAsyncReactiveQbservable <TrafficInfo> source, long now) { DateTimeOffset startMonitoring = new DateTimeOffset(now, TimeSpan.Zero); DateTimeOffset stopMonitoring = new DateTimeOffset(now, TimeSpan.FromMinutes(7)); return(source .Where(travel => travel.NotificationType == NotificationTypeEnum.Incident && travel.IncidentInfo.Severity >= IncidentSeverityEnum.Moderate && travel.IncidentInfo.Status == IncidentStatusEnum.NewIncident) .DelaySubscription(startMonitoring) .TakeUntil(stopMonitoring)); }
#pragma warning disable CA1822 // Mark members as static (compat) public IAsyncReactiveQbservable <FlightsBvtProjection> GetFlightBackwardsCompatibleQuery(IAsyncReactiveQbservable <FlightStatus> source, long now) { DateTimeOffset takeUntil = new DateTimeOffset(now, TimeSpan.Zero).AddSeconds(30); DateTimeOffset skipUntil = new DateTimeOffset(now, TimeSpan.Zero).AddSeconds(5); DateTimeOffset flightDepartureDate = DateTime.UtcNow.Date; string originAirportCode = "OriginAirportCode"; string destinationAirportCode = "DestinationAirportCode"; int notificationThresholdInMinutes = 5; List <string> statusCodes = new List <string>() { "A", "S" }; return((from flight in source where flight.ScheduledDepartureDateTime.ToUniversalTime().Date == flightDepartureDate && flight.OriginAirport.Code == originAirportCode && flight.DestinationAirport.Code == destinationAirportCode && statusCodes.Contains(flight.StatusCode) && (flight.UpdatedDepartureDateTime.Subtract(flight.ScheduledDepartureDateTime).TotalMinutes > notificationThresholdInMinutes || flight.UpdatedArrivalDateTime.Subtract(flight.ScheduledArrivalDateTime).TotalMinutes > notificationThresholdInMinutes || statusCodes.Contains(flight.StatusCode)) select new FlightsBvtProjection() { AirlineCode = flight.AirlineCode, FlightNumber = flight.FlightNumber, ScheduledDepartureDateTime = flight.ScheduledDepartureDateTime, ScheduledArrivalDateTime = flight.ScheduledArrivalDateTime, OriginAirportCode = flight.OriginAirport.Code, DestinationAirportCode = flight.DestinationAirport.Code, StatusCode = flight.StatusCode, DepartureDelayInMinutes = flight.UpdatedDepartureDateTime.Subtract(flight.ScheduledDepartureDateTime).TotalMinutes, ArrivalDelayInMinutes = flight.UpdatedArrivalDateTime.Subtract(flight.ScheduledArrivalDateTime).TotalMinutes }) .DistinctUntilChanged(t => t) .SkipUntil(skipUntil) .TakeUntil(takeUntil)); }
/// <summary> /// Defines an observable identified by the specified URI. /// </summary> /// <typeparam name="T">Type of the data produced by the observable.</typeparam> /// <param name="uri">URI identifying the observable.</param> /// <param name="observable">Observable 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 observable definition.</returns> protected override Task DefineObservableAsyncCore <T>(Uri uri, IAsyncReactiveQbservable <T> observable, object state = null, CancellationToken token = default) { var expression = _expressionServices.Normalize(observable.Expression); return(_provider.DefineObservableAsync(uri, expression, state, token)); }
public static IAsyncReactiveQbservable <TSource> DoHttp <TSource>( this IAsyncReactiveQbservable <TSource> source, Expression <Func <TSource, string> > getMethod, Expression <Func <TSource, Uri> > getOnNext, Expression <Func <TSource, string> > getBody, Expression <Func <TSource, Tuple <string, string>[]> > getHeaders, Expression <Func <TSource, RetryData> > getRetryData, Expression <Func <TSource, TimeSpan> > getTimeout) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (getMethod == null) { throw new ArgumentNullException(nameof(getMethod)); } if (getOnNext == null) { throw new ArgumentNullException(nameof(getOnNext)); } if (getBody == null) { throw new ArgumentNullException(nameof(getBody)); } if (getHeaders == null) { throw new ArgumentNullException(nameof(getHeaders)); } if (getRetryData == null) { throw new ArgumentNullException(nameof(getRetryData)); } if (getTimeout == null) { throw new ArgumentNullException(nameof(getTimeout)); } Expression <Func <string, string, Tuple <string, string>[], Uri, RetryData, TimeSpan, HttpData> > newHttpDataTemplate = (body, method, headers, onNext, retryData, timeout) => new HttpData { Body = body, Method = method, Headers = headers, OnNext = onNext, RetryData = retryData, Timeout = timeout, }; var item = Expression.Parameter(typeof(TSource)); var newHttpData = BetaReducer.Reduce(Expression.Invoke(newHttpDataTemplate, getBody.Apply(item), getMethod.Apply(item), getHeaders.Apply(item), getOnNext.Apply(item), getRetryData.Apply(item), getTimeout.Apply(item)), BetaReductionNodeTypes.Unrestricted, BetaReductionRestrictions.ExactlyOnce); var getHttpData = Expression.Lambda <Func <TSource, HttpData> >(newHttpData, item); var poster = source.Provider.CreateQbserver <HttpData>(Expression.Parameter( typeof(IAsyncReactiveQbserver <HttpData>), Constants.Observer.Action.Http.String)); return(source.Do(getHttpData, poster)); }
/// <summary> /// Defines an observable identified by the specified URI. /// </summary> /// <typeparam name="T">Type of the data produced by the observable.</typeparam> /// <param name="uri">URI identifying the observable.</param> /// <param name="observable">Observable 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 observable definition.</returns> public Task DefineObservableAsync <T>(Uri uri, IAsyncReactiveQbservable <T> observable, object state = null, CancellationToken token = default) => Definition.DefineObservableAsync(uri, observable, state, token);
private static IAsyncReactiveQbservable <T> Augment <T>(IAsyncReactiveQbservable <T> source) { return(source.StatefulAugmentation()); }
public static IAsyncReactiveQbservable <T> Concat <T>(IAsyncReactiveQbservable <T> first, IAsyncReactiveQbservable <T> second) { throw new NotImplementedException(); }
public static IAsyncReactiveQbservable <TSource> DistinctUntilChanged <TSource>(this IAsyncReactiveQbservable <TSource> source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.Provider.CreateQbservable <TSource>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression))); }
public static ISubscribable <T> AsSubscribable <T>(this IAsyncReactiveQbservable <T> observable) => throw new NotImplementedException();
public Impl(IAsyncReactiveQbservable <T> source, IReactivePlatform platform) { _source = source; _platform = platform; }
/// <summary> /// Defines an observable identified by the specified URI. /// </summary> /// <typeparam name="T">Type of the data produced by the observable.</typeparam> /// <param name="uri">URI identifying the observable.</param> /// <param name="observable">Observable 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 observable definition.</returns> protected abstract Task DefineObservableAsyncCore <T>(Uri uri, IAsyncReactiveQbservable <T> observable, object state = null, CancellationToken token = default);