コード例 #1
0
        /// <summary>
        /// Projects each update item to a new form using the specified transform function,
        /// providing an error handling action to safely handle transform errors without killing the stream.
        /// </summary>
        /// <typeparam name="TDestination">The type of the destination.</typeparam>
        /// <typeparam name="TSource">The type of the source.</typeparam>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <param name="source">The source.</param>
        /// <param name="transformFactory">The transform factory.</param>
        /// <param name="errorHandler">Provides the option to safely handle errors without killing the stream.
        ///  If not specified the stream will terminate as per rx convention.
        /// </param>
        /// <param name="parallelisationOptions">The parallelisation options to be used on the transforms</param>
        /// <returns>
        /// A transformed update collection
        /// </returns>
        /// <exception cref="System.ArgumentNullException">source
        /// or
        /// transformFactory</exception>
        public static IObservable <IChangeSet <TDestination, TKey> > TransformSafe <TDestination, TSource, TKey>(this IObservable <IChangeSet <TSource, TKey> > source,
                                                                                                                 Func <TSource, TKey, TDestination> transformFactory,
                                                                                                                 Action <Error <TSource, TKey> > errorHandler,
                                                                                                                 ParallelisationOptions parallelisationOptions)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (transformFactory == null)
            {
                throw new ArgumentNullException(nameof(transformFactory));
            }
            if (errorHandler == null)
            {
                throw new ArgumentNullException(nameof(errorHandler));
            }

            return(Observable.Create <IChangeSet <TDestination, TKey> >(
                       observer =>
            {
                var transformer = new PlinqTransformer <TDestination, TSource, TKey>(parallelisationOptions, errorHandler);
                return source
                .Select(updates => transformer.Transform(updates, transformFactory))
                .NotEmpty()
                .SubscribeSafe(observer);
            }));
        }
コード例 #2
0
        /// <summary>
        /// Projects each update item to a new form using the specified transform function
        /// </summary>
        /// <typeparam name="TDestination">The type of the destination.</typeparam>
        /// <typeparam name="TSource">The type of the source.</typeparam>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <param name="source">The source.</param>
        /// <param name="transformFactory">The transform factory.</param>
        /// <param name="parallelisationOptions">The parallelisation options to be used on the transforms</param>
        /// <returns>
        /// A transformed update collection
        /// </returns>
        /// <exception cref="System.ArgumentNullException">source
        /// or
        /// transformFactory</exception>
        public static IObservable <IChangeSet <TDestination, TKey> > Transform <TDestination, TSource, TKey>(this IObservable <IChangeSet <TSource, TKey> > source,
                                                                                                             Func <TSource, TKey, TDestination> transformFactory,
                                                                                                             ParallelisationOptions parallelisationOptions)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (transformFactory == null)
            {
                throw new ArgumentNullException("transformFactory");
            }
            if (parallelisationOptions == null)
            {
                throw new ArgumentNullException("parallelisationOptions");
            }

            return(Observable.Create <IChangeSet <TDestination, TKey> >(
                       observer =>
            {
                var transformer = new PlinqTransformer <TDestination, TSource, TKey>(parallelisationOptions, null);
                return source
                .Select(updates => transformer.Transform(updates, transformFactory))
                .NotEmpty()
                .Finally(observer.OnCompleted)
                .SubscribeSafe(observer);
            }));
        }