Observable.Remoting.cs 5.5 KB

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