Debian Codegraph @

external/rx/Rx/NET/Source/System.Reactive.Runtime.Remoting/Reactive/Linq/Observable.Remoting.cs

raw
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2
3 #if !NO_REMOTING
4 using System.Linq.Expressions;
5 using System.Reflection;
6 using System.Runtime.Remoting.Lifetime;
7
8 namespace System.Reactive.Linq
9 {
10 /// <summary>
11 /// Provides a set of static methods for exposing observable sequences through .NET Remoting.
12 /// </summary>
13 public static partial class RemotingObservable
14 {
15 #region Remotable
16
17 /// <summary>
18 /// Makes an observable sequence remotable, using an infinite lease for the <see cref="MarshalByRefObject"/> wrapping the source.
19 /// </summary>
20 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
21 /// <param name="source">Source sequence.</param>
22 /// <returns>The observable sequence that supports remote subscriptions.</returns>
23 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
24 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Remotable", Justification = "In honor of the .NET Remoting heroes.")]
25 public static IObservable<TSource> Remotable<TSource>(this IObservable<TSource> source)
26 {
27 if (source == null)
28 throw new ArgumentNullException("source");
29
30 return Remotable_<TSource>(source);
31 }
32
33 /// <summary>
34 /// Makes an observable sequence remotable, using a controllable lease for the <see cref="MarshalByRefObject"/> wrapping the source.
35 /// </summary>
36 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
37 /// <param name="source">Source sequence.</param>
38 /// <param name="lease">Lease object to control lifetime of the remotable sequence. Notice null is a supported value.</param>
39 /// <returns>The observable sequence that supports remote subscriptions.</returns>
40 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
41 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Remotable", Justification = "In honor of the .NET Remoting heroes.")]
42 public static IObservable<TSource> Remotable<TSource>(this IObservable<TSource> source, ILease lease)
43 {
44 if (source == null)
45 throw new ArgumentNullException("source");
46
47 return Remotable_<TSource>(source, lease);
48 }
49
50 /// <summary>
51 /// Makes an observable sequence remotable, using an infinite lease for the <see cref="MarshalByRefObject"/> wrapping the source.
52 /// </summary>
53 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
54 /// <param name="source">Source sequence.</param>
55 /// <returns>The observable sequence that supports remote subscriptions.</returns>
56 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
57 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Remotable", Justification = "In honor of the .NET Remoting heroes.")]
58 public static IQbservable<TSource> Remotable<TSource>(this IQbservable<TSource> source)
59 {
60 if (source == null)
61 throw new ArgumentNullException("source");
62
63 return source.Provider.CreateQuery<TSource>(
64 Expression.Call(
65 null,
66 #if CRIPPLED_REFLECTION
67 InfoOf(() => RemotingObservable.Remotable<TSource>(default(IQbservable<TSource>))),
68 #else
69 ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
70 #endif
71 source.Expression
72 )
73 );
74 }
75
76 /// <summary>
77 /// Makes an observable sequence remotable, using a controllable lease for the <see cref="MarshalByRefObject"/> wrapping the source.
78 /// </summary>
79 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
80 /// <param name="source">Source sequence.</param>
81 /// <param name="lease">Lease object to control lifetime of the remotable sequence. Notice null is a supported value.</param>
82 /// <returns>The observable sequence that supports remote subscriptions.</returns>
83 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
84 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Remotable", Justification = "In honor of the .NET Remoting heroes.")]
85 public static IQbservable<TSource> Remotable<TSource>(this IQbservable<TSource> source, ILease lease)
86 {
87 if (source == null)
88 throw new ArgumentNullException("source");
89
90 return source.Provider.CreateQuery<TSource>(
91 Expression.Call(
92 null,
93 #if CRIPPLED_REFLECTION
94 InfoOf(() => RemotingObservable.Remotable<TSource>(default(IQbservable<TSource>), default(ILease))),
95 #else
96 ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
97 #endif
98 source.Expression,
99 Expression.Constant(lease, typeof(ILease))
100 )
101 );
102 }
103
104 #if CRIPPLED_REFLECTION
105 internal static MethodInfo InfoOf<R>(Expression<Func<R>> f)
106 {
107 return ((MethodCallExpression)f.Body).Method;
108 }
109 #endif
110
111 #endregion
112 }
113 }
114 #endif