示例#1
0
        internal IReliableQubscription Subscribe <T>(IReliableQbservable <T> observable, IReliableQbserver <T> observer, Uri subscriptionUri, object state)
        {
            var subscribe  = Expression.Parameter(typeof(Func <IReliableQbservable <T>, IReliableQbserver <T>, IReliableQubscription>), Constants.SubscribeUri);
            var expression = Expression.Invoke(subscribe, observable.Expression, observer.Expression);

            var normalized = _expressionServices.Normalize(expression);

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

            CreateSubscription(subscription, state);

            return(subscription);
        }
        /// <summary>
        /// Converts an instance of <see cref="IAsyncReactiveResource"/>
        /// to its underlying representation for serialization.
        /// </summary>
        /// <param name="value">The original value.</param>
        /// <param name="sourceType">The source type.</param>
        /// <param name="targetType">The target type.</param>
        /// <returns>The converted instance.</returns>
        public override object ConvertTo(object value, Type sourceType, Type targetType)
        {
            // Base class knows how to write null values
            Debug.Assert(value != null);

            var resource = (IAsyncReactiveResource)value;

            var container = new ReactiveResourceContainer
            {
                Uri        = resource.Uri,
                Expression = _expressionServices != null
                    ? _expressionServices.Normalize(resource.Expression).ToExpressionSlim()
                    : resource.Expression.ToExpressionSlim(),
            };

            if (value is IAsyncReactiveDefinedResource definedResource)
            {
                container.State = (TState)definedResource.State;
            }
            else if (value is IAsyncReactiveProcessResource processResource)
            {
                container.State = (TState)processResource.State;
            }

            return(container);
        }
            protected Resource(ReactiveResourceContainer container, IReactiveExpressionServices expressionServices)
            {
                Debug.Assert(container != null);

                Uri         = container.Uri;
                _expression = new Lazy <Expression>(() => expressionServices != null
                    ? expressionServices.Normalize(container.Expression.ToExpression())
                    : container.Expression.ToExpression());
            }
示例#4
0
        /// <summary>
        /// Executes the specified expression.
        /// </summary>
        /// <typeparam name="TResult">Result type of the expression.</typeparam>
        /// <param name="expression">Expression to execute.</param>
        /// <returns>Result of executing the expression.</returns>
        protected override TResult Execute <TResult>(Expression expression)
        {
            var expr = _expressionServices.Normalize(expression);

            return(_provider.Provider.Execute <TResult>(expr));
        }
示例#5
0
        /// <summary>
        /// Defines a stream factory identified by the specified URI.
        /// </summary>
        /// <typeparam name="TInput">Type of the data received by the subjects created by the stream factory.</typeparam>
        /// <typeparam name="TOutput">Type of the data produced by the subjects created by the stream factory.</typeparam>
        /// <param name="uri">URI identifying the stream factory.</param>
        /// <param name="streamFactory">Stream factory 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 stream factory definition.</returns>
        protected override Task DefineStreamFactoryAsyncCore <TInput, TOutput>(Uri uri, IAsyncReactiveQubjectFactory <TInput, TOutput> streamFactory, object state = null, CancellationToken token = default)
        {
            var expression = _expressionServices.Normalize(streamFactory.Expression);

            return(_provider.DefineStreamFactoryAsync(uri, expression, state, token));
        }
示例#6
0
        /// <summary>
        /// Defines a stream factory identified by the specified URI.
        /// </summary>
        /// <typeparam name="TInput">Type of the data received by the subjects created by the stream factory.</typeparam>
        /// <typeparam name="TOutput">Type of the data produced by the subjects created by the stream factory.</typeparam>
        /// <param name="uri">URI identifying the stream factory.</param>
        /// <param name="streamFactory">Stream factory to be defined.</param>
        /// <param name="state">Additional metadata to associate with the artifact. Implementations can interpret this value, or ignore it.</param>
        protected override void DefineStreamFactoryCore <TInput, TOutput>(Uri uri, IReactiveQubjectFactory <TInput, TOutput> streamFactory, object state = null)
        {
            var expression = _expressionServices.Normalize(streamFactory.Expression);

            _provider.DefineStreamFactory(uri, expression, state);
        }