Observable.Remoting.cs 5.7 KB

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