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)); }
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)); }