Exemple #1
0
        /// <summary>
        /// Converts a Windows Runtime asynchronous operation to an observable sequence by retrieving the operation's results whenever progress is reported and when the operation completes.
        /// Each observer subscribed to the resulting observable sequence will be notified about the action's successful or exceptional completion.
        /// </summary>
        /// <typeparam name="TResult">The type of the asynchronous operation's result.</typeparam>
        /// <typeparam name="TProgress">The type of the reported progress objects, which are used internally in the conversion but aren't exposed.</typeparam>
        /// <param name="source">Asynchronous operation to convert.</param>
        /// <returns>An observable sequence that notifies observers about the asynchronous operation's (incremental) result value(s) and completion.</returns>
        /// <remarks>This conversion can be used with Windows Runtime APIs that support incremental retrieval of results during an asynchronous operation's execution.</remarks>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
        public static IObservable <TResult> ToObservableMultiple <TResult, TProgress>(this IAsyncOperationWithProgress <TResult, TProgress> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(source.ToObservable_(null, true));
        }
Exemple #2
0
        /// <summary>
        /// Converts a Windows Runtime asynchronous operation to an observable sequence reporting its result and reporting its progress through the supplied progress object.
        /// Each observer subscribed to the resulting observable sequence will be notified about the operations's single result and its successful or exceptional completion.
        /// </summary>
        /// <typeparam name="TResult">The type of the asynchronous operation's result.</typeparam>
        /// <typeparam name="TProgress">The type of the reported progress objects.</typeparam>
        /// <param name="source">Asynchronous action to convert.</param>
        /// <param name="progress">Progress object to receive progress notifications on.</param>
        /// <returns>An observable sequence that notifies observers about the asynchronous operation's result value and completion.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="progress"/> is null.</exception>
        public static IObservable <TResult> ToObservable <TResult, TProgress>(this IAsyncOperationWithProgress <TResult, TProgress> source, IProgress <TProgress> progress)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (progress == null)
            {
                throw new ArgumentNullException(nameof(progress));
            }

            return(source.ToObservable_(progress, false));
        }
Exemple #3
0
        /// <summary>
        /// Converts a Windows Runtime asynchronous operation to an observable sequence reporting its progress but ignoring its result value.
        /// Each observer subscribed to the resulting observable sequence will be notified about the action's successful or exceptional completion.
        /// </summary>
        /// <typeparam name="TResult">The type of the asynchronous operation's result, which gets ignored by this conversion.</typeparam>
        /// <typeparam name="TProgress">The type of the reported progress objects.</typeparam>
        /// <param name="source">Asynchronous action to convert.</param>
        /// <returns>An observable sequence that produces progress values from the asynchronous operation and notifies observers about the operations's completion.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
        public static IObservable <TProgress> ToObservableProgress <TResult, TProgress>(this IAsyncOperationWithProgress <TResult, TProgress> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(Observable.Create <TProgress>(observer =>
            {
                var progress = observer.ToProgress();
                var src = source.ToObservable_(progress, false);
                return src.Subscribe(_ => { }, observer.OnError, observer.OnCompleted);
            }));
        }