AsyncInfoObservableExtensions
Provides conversions from Windows Runtime asynchronous actions and operations to observable sequences.
using System.Reactive.Linq;
using Windows.Foundation;
namespace System.Reactive.Windows.Foundation
{
[CLSCompliant(false)]
public static class AsyncInfoObservableExtensions
{
public unsafe static IObservable<Unit> ToObservable(this IAsyncAction source)
{
if (source == null)
throw new ArgumentNullException("source");
return new AsyncInfoToObservableBridge<Unit, Unit>(source, delegate(IAsyncInfo iai, Action<IAsyncInfo, AsyncStatus> a) {
? val = iai;
<>c__DisplayClass0_0 <>c__DisplayClass0_;
val.put_Completed(Delegate.Combine((Delegate)val.get_Completed(), (Delegate)new AsyncActionCompletedHandler((object)<>c__DisplayClass0_, (IntPtr)(void*))));
}, (IAsyncInfo iai) => Unit.Default, null, null, false);
}
public static IObservable<Unit> ToObservable<TProgress>(this IAsyncActionWithProgress<TProgress> source)
{
if (source == null)
throw new ArgumentNullException("source");
return source.ToObservable_<TProgress>(null);
}
public static IObservable<Unit> ToObservable<TProgress>(this IAsyncActionWithProgress<TProgress> source, IProgress<TProgress> progress)
{
if (source == null)
throw new ArgumentNullException("source");
if (progress == null)
throw new ArgumentNullException("progress");
return source.ToObservable_(progress);
}
public static IObservable<TProgress> ToObservableProgress<TProgress>(this IAsyncActionWithProgress<TProgress> source)
{
if (source == null)
throw new ArgumentNullException("source");
return Observable.Create(delegate(IObserver<TProgress> observer) {
IProgress<TProgress> progress = Observer.ToProgress<TProgress>(observer);
return ObservableExtensions.Subscribe<Unit>(AsyncInfoObservableExtensions.ToObservable_<TProgress>(source, progress), (Action<Unit>)delegate {
}, (Action<Exception>)observer.OnError, (Action)observer.OnCompleted);
});
}
private unsafe static IObservable<Unit> ToObservable_<TProgress>(this IAsyncActionWithProgress<TProgress> source, IProgress<TProgress> progress)
{
return new AsyncInfoToObservableBridge<Unit, TProgress>(source, (Action<IAsyncInfo, Action<IAsyncInfo, AsyncStatus>>)delegate(IAsyncInfo iai, Action<IAsyncInfo, AsyncStatus> a) {
IAsyncInfo obj2 = iai;
<>c__DisplayClass4_0<TProgress> <>c__DisplayClass4_2;
obj2.put_Completed(Delegate.Combine((Delegate)obj2.get_Completed(), (Delegate)new AsyncActionWithProgressCompletedHandler<TProgress>((object)<>c__DisplayClass4_2, (IntPtr)(void*))));
}, (Func<IAsyncInfo, Unit>)((IAsyncInfo iai) => Unit.Default), (Action<IAsyncInfo, Action<IAsyncInfo, TProgress>>)delegate(IAsyncInfo iai, Action<IAsyncInfo, TProgress> a) {
IAsyncInfo obj = iai;
<>c__DisplayClass4_1<TProgress> <>c__DisplayClass4_;
obj.put_Progress(Delegate.Combine((Delegate)obj.get_Progress(), (Delegate)new AsyncActionProgressHandler<TProgress>((object)<>c__DisplayClass4_, (IntPtr)(void*))));
}, progress, false);
}
public unsafe static IObservable<TResult> ToObservable<TResult>(this IAsyncOperation<TResult> source)
{
if (source == null)
throw new ArgumentNullException("source");
return new AsyncInfoToObservableBridge<TResult, Unit>(source, (Action<IAsyncInfo, Action<IAsyncInfo, AsyncStatus>>)delegate(IAsyncInfo iai, Action<IAsyncInfo, AsyncStatus> a) {
IAsyncInfo obj = iai;
<>c__DisplayClass5_0<TResult> <>c__DisplayClass5_;
obj.put_Completed(Delegate.Combine((Delegate)obj.get_Completed(), (Delegate)new AsyncOperationCompletedHandler<TResult>((object)<>c__DisplayClass5_, (IntPtr)(void*))));
}, (Func<IAsyncInfo, TResult>)((IAsyncInfo iai) => iai.GetResults()), (Action<IAsyncInfo, Action<IAsyncInfo, Unit>>)null, (IProgress<Unit>)null, false);
}
public static IObservable<TResult> ToObservable<TResult, TProgress>(this IAsyncOperationWithProgress<TResult, TProgress> source)
{
if (source == null)
throw new ArgumentNullException("source");
return source.ToObservable_<TResult, TProgress>(null, false);
}
public static IObservable<TResult> ToObservable<TResult, TProgress>(this IAsyncOperationWithProgress<TResult, TProgress> source, IProgress<TProgress> progress)
{
if (source == null)
throw new ArgumentNullException("source");
if (progress == null)
throw new ArgumentNullException("progress");
return source.ToObservable_<TResult, TProgress>(progress, false);
}
public static IObservable<TProgress> ToObservableProgress<TResult, TProgress>(this IAsyncOperationWithProgress<TResult, TProgress> source)
{
if (source == null)
throw new ArgumentNullException("source");
return Observable.Create(delegate(IObserver<TProgress> observer) {
IProgress<TProgress> progress = Observer.ToProgress<TProgress>(observer);
return ObservableExtensions.Subscribe<TResult>(AsyncInfoObservableExtensions.ToObservable_<TResult, TProgress>(source, progress, false), (Action<TResult>)delegate {
}, (Action<Exception>)observer.OnError, (Action)observer.OnCompleted);
});
}
public static IObservable<TResult> ToObservableMultiple<TResult, TProgress>(this IAsyncOperationWithProgress<TResult, TProgress> source)
{
if (source == null)
throw new ArgumentNullException("source");
return source.ToObservable_<TResult, TProgress>(null, true);
}
public static IObservable<TResult> ToObservableMultiple<TResult, TProgress>(this IAsyncOperationWithProgress<TResult, TProgress> source, IProgress<TProgress> progress)
{
if (source == null)
throw new ArgumentNullException("source");
if (progress == null)
throw new ArgumentNullException("progress");
return source.ToObservable_<TResult, TProgress>(progress, true);
}
private unsafe static IObservable<TResult> ToObservable_<TResult, TProgress>(this IAsyncOperationWithProgress<TResult, TProgress> source, IProgress<TProgress> progress, bool supportsMultiple)
{
return new AsyncInfoToObservableBridge<TResult, TProgress>(source, (Action<IAsyncInfo, Action<IAsyncInfo, AsyncStatus>>)delegate(IAsyncInfo iai, Action<IAsyncInfo, AsyncStatus> a) {
IAsyncInfo obj2 = iai;
<>c__DisplayClass11_0<TResult, TProgress> <>c__DisplayClass11_2;
obj2.put_Completed(Delegate.Combine((Delegate)obj2.get_Completed(), (Delegate)new AsyncOperationWithProgressCompletedHandler<TResult, TProgress>((object)<>c__DisplayClass11_2, (IntPtr)(void*))));
}, (Func<IAsyncInfo, TResult>)((IAsyncInfo iai) => iai.GetResults()), (Action<IAsyncInfo, Action<IAsyncInfo, TProgress>>)delegate(IAsyncInfo iai, Action<IAsyncInfo, TProgress> a) {
IAsyncInfo obj = iai;
<>c__DisplayClass11_1<TResult, TProgress> <>c__DisplayClass11_;
obj.put_Progress(Delegate.Combine((Delegate)obj.get_Progress(), (Delegate)new AsyncOperationProgressHandler<TResult, TProgress>((object)<>c__DisplayClass11_, (IntPtr)(void*))));
}, progress, supportsMultiple);
}
}
}