Debian Codegraph @

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

raw
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2
3 using System.Reactive.Concurrency;
4 using System.Reactive.Subjects;
5
6 namespace System.Reactive.Linq
7 {
8 public static partial class Observable
9 {
10 #region + Multicast +
11
12 /// <summary>
13 /// Multicasts the source sequence notifications through the specified subject to the resulting connectable observable. Upon connection of the
14 /// connectable observable, the subject is subscribed to the source exactly one, and messages are forwarded to the observers registered with
15 /// the connectable observable. For specializations with fixed subject types, see Publish, PublishLast, and Replay.
16 /// </summary>
17 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
18 /// <typeparam name="TResult">The type of the elements in the result sequence.</typeparam>
19 /// <param name="source">Source sequence whose elements will be pushed into the specified subject.</param>
20 /// <param name="subject">Subject to push source elements into.</param>
21 /// <returns>A connectable observable sequence that upon connection causes the source sequence to push results into the specified subject.</returns>
22 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="subject"/> is null.</exception>
23 public static IConnectableObservable<TResult> Multicast<TSource, TResult>(this IObservable<TSource> source, ISubject<TSource, TResult> subject)
24 {
25 if (source == null)
26 throw new ArgumentNullException("source");
27 if (subject == null)
28 throw new ArgumentNullException("subject");
29
30 return s_impl.Multicast<TSource, TResult>(source, subject);
31 }
32
33 /// <summary>
34 /// Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each
35 /// subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's
36 /// invocation. For specializations with fixed subject types, see Publish, PublishLast, and Replay.
37 /// </summary>
38 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
39 /// <typeparam name="TIntermediate">The type of the elements produced by the intermediate subject.</typeparam>
40 /// <typeparam name="TResult">The type of the elements in the result sequence.</typeparam>
41 /// <param name="source">Source sequence which will be multicasted in the specified selector function.</param>
42 /// <param name="subjectSelector">Factory function to create an intermediate subject through which the source sequence's elements will be multicast to the selector function.</param>
43 /// <param name="selector">Selector function which can use the multicasted source sequence subject to the policies enforced by the created subject.</param>
44 /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
45 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="subjectSelector"/> or <paramref name="selector"/> is null.</exception>
46 public static IObservable<TResult> Multicast<TSource, TIntermediate, TResult>(this IObservable<TSource> source, Func<ISubject<TSource, TIntermediate>> subjectSelector, Func<IObservable<TIntermediate>, IObservable<TResult>> selector)
47 {
48 if (source == null)
49 throw new ArgumentNullException("source");
50 if (subjectSelector == null)
51 throw new ArgumentNullException("subjectSelector");
52 if (selector == null)
53 throw new ArgumentNullException("selector");
54
55 return s_impl.Multicast<TSource, TIntermediate, TResult>(source, subjectSelector, selector);
56 }
57
58 #endregion
59
60 #region + Publish +
61
62 /// <summary>
63 /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence.
64 /// This operator is a specialization of Multicast using a regular <see cref="System.Reactive.Subjects.Subject&lt;T&gt;"/>.
65 /// </summary>
66 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
67 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
68 /// <returns>A connectable observable sequence that shares a single subscription to the underlying sequence.</returns>
69 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
70 /// <remarks>Subscribers will receive all notifications of the source from the time of the subscription on.</remarks>
71 /// <seealso cref="System.Reactive.Subjects.Subject&lt;T&gt;"/>
72 public static IConnectableObservable<TSource> Publish<TSource>(this IObservable<TSource> source)
73 {
74 if (source == null)
75 throw new ArgumentNullException("source");
76
77 return s_impl.Publish<TSource>(source);
78 }
79
80 /// <summary>
81 /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence.
82 /// This operator is a specialization of Multicast using a regular <see cref="System.Reactive.Subjects.Subject&lt;T&gt;"/>.
83 /// </summary>
84 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
85 /// <typeparam name="TResult">The type of the elements in the result sequence.</typeparam>
86 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
87 /// <param name="selector">Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all notifications of the source from the time of the subscription on.</param>
88 /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
89 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
90 /// <seealso cref="System.Reactive.Subjects.Subject&lt;T&gt;"/>
91 public static IObservable<TResult> Publish<TSource, TResult>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TResult>> selector)
92 {
93 if (source == null)
94 throw new ArgumentNullException("source");
95 if (selector == null)
96 throw new ArgumentNullException("selector");
97
98 return s_impl.Publish<TSource, TResult>(source, selector);
99 }
100
101 /// <summary>
102 /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initialValue.
103 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.BehaviorSubject&lt;T&gt;"/>.
104 /// </summary>
105 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
106 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
107 /// <param name="initialValue">Initial value received by observers upon subscription.</param>
108 /// <returns>A connectable observable sequence that shares a single subscription to the underlying sequence.</returns>
109 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
110 /// <remarks>Subscribers will receive immediately receive the initial value, followed by all notifications of the source from the time of the subscription on.</remarks>
111 /// <seealso cref="System.Reactive.Subjects.BehaviorSubject&lt;T&gt;"/>
112 public static IConnectableObservable<TSource> Publish<TSource>(this IObservable<TSource> source, TSource initialValue)
113 {
114 if (source == null)
115 throw new ArgumentNullException("source");
116
117 return s_impl.Publish<TSource>(source, initialValue);
118 }
119
120 /// <summary>
121 /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initialValue.
122 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.BehaviorSubject&lt;T&gt;"/>.
123 /// </summary>
124 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
125 /// <typeparam name="TResult">The type of the elements in the result sequence.</typeparam>
126 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
127 /// <param name="selector">Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive immediately receive the initial value, followed by all notifications of the source from the time of the subscription on.</param>
128 /// <param name="initialValue">Initial value received by observers upon subscription.</param>
129 /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
130 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
131 /// <seealso cref="System.Reactive.Subjects.BehaviorSubject&lt;T&gt;"/>
132 public static IObservable<TResult> Publish<TSource, TResult>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TResult>> selector, TSource initialValue)
133 {
134 if (source == null)
135 throw new ArgumentNullException("source");
136 if (selector == null)
137 throw new ArgumentNullException("selector");
138
139 return s_impl.Publish<TSource, TResult>(source, selector, initialValue);
140 }
141
142 #endregion
143
144 #region + PublishLast +
145
146 /// <summary>
147 /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence containing only the last notification.
148 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.AsyncSubject&lt;T&gt;"/>.
149 /// </summary>
150 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
151 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
152 /// <returns>A connectable observable sequence that shares a single subscription to the underlying sequence.</returns>
153 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
154 /// <remarks>Subscribers will only receive the last notification of the source.</remarks>
155 /// <seealso cref="System.Reactive.Subjects.AsyncSubject&lt;T&gt;"/>
156 public static IConnectableObservable<TSource> PublishLast<TSource>(this IObservable<TSource> source)
157 {
158 if (source == null)
159 throw new ArgumentNullException("source");
160
161 return s_impl.PublishLast<TSource>(source);
162 }
163
164 /// <summary>
165 /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence containing only the last notification.
166 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.AsyncSubject&lt;T&gt;"/>.
167 /// </summary>
168 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
169 /// <typeparam name="TResult">The type of the elements in the result sequence.</typeparam>
170 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
171 /// <param name="selector">Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will only receive the last notification of the source.</param>
172 /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
173 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
174 /// <seealso cref="System.Reactive.Subjects.AsyncSubject&lt;T&gt;"/>
175 public static IObservable<TResult> PublishLast<TSource, TResult>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TResult>> selector)
176 {
177 if (source == null)
178 throw new ArgumentNullException("source");
179 if (selector == null)
180 throw new ArgumentNullException("selector");
181
182 return s_impl.PublishLast<TSource, TResult>(source, selector);
183 }
184
185 #endregion
186
187 #region + RefCount +
188
189 /// <summary>
190 /// Returns an observable sequence that stays connected to the source as long as there is at least one subscription to the observable sequence.
191 /// </summary>
192 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
193 /// <param name="source">Connectable observable sequence.</param>
194 /// <returns>An observable sequence that stays connected to the source as long as there is at least one subscription to the observable sequence.</returns>
195 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
196 public static IObservable<TSource> RefCount<TSource>(this IConnectableObservable<TSource> source)
197 {
198 if (source == null)
199 throw new ArgumentNullException("source");
200
201 return s_impl.RefCount<TSource>(source);
202 }
203
204 #endregion
205
206 #region + Replay +
207
208 /// <summary>
209 /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence replaying all notifications.
210 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>.
211 /// </summary>
212 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
213 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
214 /// <returns>A connectable observable sequence that shares a single subscription to the underlying sequence.</returns>
215 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
216 /// <remarks>Subscribers will receive all the notifications of the source.</remarks>
217 /// <seealso cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>
218 public static IConnectableObservable<TSource> Replay<TSource>(this IObservable<TSource> source)
219 {
220 if (source == null)
221 throw new ArgumentNullException("source");
222
223 return s_impl.Replay<TSource>(source);
224 }
225
226 /// <summary>
227 /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence replaying all notifications.
228 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>.
229 /// </summary>
230 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
231 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
232 /// <param name="scheduler">Scheduler where connected observers will be invoked on.</param>
233 /// <returns>A connectable observable sequence that shares a single subscription to the underlying sequence.</returns>
234 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
235 /// <remarks>Subscribers will receive all the notifications of the source.</remarks>
236 /// <seealso cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>
237 public static IConnectableObservable<TSource> Replay<TSource>(this IObservable<TSource> source, IScheduler scheduler)
238 {
239 if (source == null)
240 throw new ArgumentNullException("source");
241 if (scheduler == null)
242 throw new ArgumentNullException("scheduler");
243
244 return s_impl.Replay<TSource>(source, scheduler);
245 }
246
247 /// <summary>
248 /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying all notifications.
249 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>.
250 /// </summary>
251 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
252 /// <typeparam name="TResult">The type of the elements in the result sequence.</typeparam>
253 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
254 /// <param name="selector">Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source.</param>
255 /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
256 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
257 /// <seealso cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>
258 public static IObservable<TResult> Replay<TSource, TResult>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TResult>> selector)
259 {
260 if (source == null)
261 throw new ArgumentNullException("source");
262 if (selector == null)
263 throw new ArgumentNullException("selector");
264
265 return s_impl.Replay<TSource, TResult>(source, selector);
266 }
267
268 /// <summary>
269 /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying all notifications.
270 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>.
271 /// </summary>
272 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
273 /// <typeparam name="TResult">The type of the elements in the result sequence.</typeparam>
274 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
275 /// <param name="selector">Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source.</param>
276 /// <param name="scheduler">Scheduler where connected observers within the selector function will be invoked on.</param>
277 /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
278 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> or <paramref name="scheduler"/> is null.</exception>
279 /// <seealso cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>
280 public static IObservable<TResult> Replay<TSource, TResult>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TResult>> selector, IScheduler scheduler)
281 {
282 if (source == null)
283 throw new ArgumentNullException("source");
284 if (selector == null)
285 throw new ArgumentNullException("selector");
286 if (scheduler == null)
287 throw new ArgumentNullException("scheduler");
288
289 return s_impl.Replay<TSource, TResult>(source, selector, scheduler);
290 }
291
292 /// <summary>
293 /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer.
294 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>.
295 /// </summary>
296 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
297 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
298 /// <param name="window">Maximum time length of the replay buffer.</param>
299 /// <returns>A connectable observable sequence that shares a single subscription to the underlying sequence.</returns>
300 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
301 /// <exception cref="ArgumentOutOfRangeException"><paramref name="window"/> is less than TimeSpan.Zero.</exception>
302 /// <remarks>Subscribers will receive all the notifications of the source subject to the specified replay buffer trimming policy.</remarks>
303 /// <seealso cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>
304 public static IConnectableObservable<TSource> Replay<TSource>(this IObservable<TSource> source, TimeSpan window)
305 {
306 if (source == null)
307 throw new ArgumentNullException("source");
308 if (window < TimeSpan.Zero)
309 throw new ArgumentOutOfRangeException("window");
310
311 return s_impl.Replay<TSource>(source, window);
312 }
313
314 /// <summary>
315 /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer.
316 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>.
317 /// </summary>
318 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
319 /// <typeparam name="TResult">The type of the elements in the result sequence.</typeparam>
320 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
321 /// <param name="selector">Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy.</param>
322 /// <param name="window">Maximum time length of the replay buffer.</param>
323 /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
324 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
325 /// <exception cref="ArgumentOutOfRangeException"><paramref name="window"/> is less than TimeSpan.Zero.</exception>
326 /// <seealso cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>
327 public static IObservable<TResult> Replay<TSource, TResult>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TResult>> selector, TimeSpan window)
328 {
329 if (source == null)
330 throw new ArgumentNullException("source");
331 if (selector == null)
332 throw new ArgumentNullException("selector");
333 if (window < TimeSpan.Zero)
334 throw new ArgumentOutOfRangeException("window");
335
336 return s_impl.Replay<TSource, TResult>(source, selector, window);
337 }
338
339 /// <summary>
340 /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer.
341 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>.
342 /// </summary>
343 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
344 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
345 /// <param name="window">Maximum time length of the replay buffer.</param>
346 /// <param name="scheduler">Scheduler where connected observers will be invoked on.</param>
347 /// <returns>A connectable observable sequence that shares a single subscription to the underlying sequence.</returns>
348 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
349 /// <exception cref="ArgumentOutOfRangeException"><paramref name="window"/> is less than TimeSpan.Zero.</exception>
350 /// <remarks>Subscribers will receive all the notifications of the source subject to the specified replay buffer trimming policy.</remarks>
351 /// <seealso cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>
352 public static IConnectableObservable<TSource> Replay<TSource>(this IObservable<TSource> source, TimeSpan window, IScheduler scheduler)
353 {
354 if (source == null)
355 throw new ArgumentNullException("source");
356 if (window < TimeSpan.Zero)
357 throw new ArgumentOutOfRangeException("window");
358 if (scheduler == null)
359 throw new ArgumentNullException("scheduler");
360
361 return s_impl.Replay<TSource>(source, window, scheduler);
362 }
363
364 /// <summary>
365 /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer.
366 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>.
367 /// </summary>
368 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
369 /// <typeparam name="TResult">The type of the elements in the result sequence.</typeparam>
370 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
371 /// <param name="selector">Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy.</param>
372 /// <param name="window">Maximum time length of the replay buffer.</param>
373 /// <param name="scheduler">Scheduler where connected observers within the selector function will be invoked on.</param>
374 /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
375 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> or <paramref name="scheduler"/> is null.</exception>
376 /// <exception cref="ArgumentOutOfRangeException"><paramref name="window"/> is less than TimeSpan.Zero.</exception>
377 /// <seealso cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>
378 public static IObservable<TResult> Replay<TSource, TResult>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TResult>> selector, TimeSpan window, IScheduler scheduler)
379 {
380 if (source == null)
381 throw new ArgumentNullException("source");
382 if (selector == null)
383 throw new ArgumentNullException("selector");
384 if (window < TimeSpan.Zero)
385 throw new ArgumentOutOfRangeException("window");
386 if (scheduler == null)
387 throw new ArgumentNullException("scheduler");
388
389 return s_impl.Replay<TSource, TResult>(source, selector, window, scheduler);
390 }
391
392 /// <summary>
393 /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence replaying bufferSize notifications.
394 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>.
395 /// </summary>
396 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
397 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
398 /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
399 /// <param name="scheduler">Scheduler where connected observers will be invoked on.</param>
400 /// <returns>A connectable observable sequence that shares a single subscription to the underlying sequence.</returns>
401 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
402 /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero.</exception>
403 /// <remarks>Subscribers will receive all the notifications of the source subject to the specified replay buffer trimming policy.</remarks>
404 /// <seealso cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>
405 public static IConnectableObservable<TSource> Replay<TSource>(this IObservable<TSource> source, int bufferSize, IScheduler scheduler)
406 {
407 if (source == null)
408 throw new ArgumentNullException("source");
409 if (bufferSize < 0)
410 throw new ArgumentOutOfRangeException("bufferSize");
411 if (scheduler == null)
412 throw new ArgumentNullException("scheduler");
413
414 return s_impl.Replay<TSource>(source, bufferSize, scheduler);
415 }
416
417 /// <summary>
418 /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum element count for the replay buffer.
419 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>.
420 /// </summary>
421 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
422 /// <typeparam name="TResult">The type of the elements in the result sequence.</typeparam>
423 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
424 /// <param name="selector">Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy.</param>
425 /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
426 /// <param name="scheduler">Scheduler where connected observers within the selector function will be invoked on.</param>
427 /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
428 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> or <paramref name="scheduler"/> is null.</exception>
429 /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero.</exception>
430 /// <seealso cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>
431 public static IObservable<TResult> Replay<TSource, TResult>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TResult>> selector, int bufferSize, IScheduler scheduler)
432 {
433 if (source == null)
434 throw new ArgumentNullException("source");
435 if (selector == null)
436 throw new ArgumentNullException("selector");
437 if (bufferSize < 0)
438 throw new ArgumentOutOfRangeException("bufferSize");
439 if (scheduler == null)
440 throw new ArgumentNullException("scheduler");
441
442 return s_impl.Replay<TSource, TResult>(source, selector, bufferSize, scheduler);
443 }
444
445 /// <summary>
446 /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum element count for the replay buffer.
447 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>.
448 /// </summary>
449 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
450 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
451 /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
452 /// <returns>A connectable observable sequence that shares a single subscription to the underlying sequence.</returns>
453 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
454 /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero.</exception>
455 /// <remarks>Subscribers will receive all the notifications of the source subject to the specified replay buffer trimming policy.</remarks>
456 /// <seealso cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>
457 public static IConnectableObservable<TSource> Replay<TSource>(this IObservable<TSource> source, int bufferSize)
458 {
459 if (source == null)
460 throw new ArgumentNullException("source");
461 if (bufferSize < 0)
462 throw new ArgumentOutOfRangeException("bufferSize");
463
464 return s_impl.Replay<TSource>(source, bufferSize);
465 }
466
467 /// <summary>
468 /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum element count for the replay buffer.
469 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>.
470 /// </summary>
471 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
472 /// <typeparam name="TResult">The type of the elements in the result sequence.</typeparam>
473 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
474 /// <param name="selector">Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy.</param>
475 /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
476 /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
477 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
478 /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero.</exception>
479 /// <seealso cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>
480 public static IObservable<TResult> Replay<TSource, TResult>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TResult>> selector, int bufferSize)
481 {
482 if (source == null)
483 throw new ArgumentNullException("source");
484 if (selector == null)
485 throw new ArgumentNullException("selector");
486 if (bufferSize < 0)
487 throw new ArgumentOutOfRangeException("bufferSize");
488
489 return s_impl.Replay<TSource, TResult>(source, selector, bufferSize);
490 }
491
492 /// <summary>
493 /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length and element count for the replay buffer.
494 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>.
495 /// </summary>
496 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
497 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
498 /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
499 /// <param name="window">Maximum time length of the replay buffer.</param>
500 /// <returns>A connectable observable sequence that shares a single subscription to the underlying sequence.</returns>
501 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
502 /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero.</exception>
503 /// <exception cref="ArgumentOutOfRangeException"><paramref name="window"/> is less than TimeSpan.Zero.</exception>
504 /// <remarks>Subscribers will receive all the notifications of the source subject to the specified replay buffer trimming policy.</remarks>
505 /// <seealso cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>
506 public static IConnectableObservable<TSource> Replay<TSource>(this IObservable<TSource> source, int bufferSize, TimeSpan window)
507 {
508 if (source == null)
509 throw new ArgumentNullException("source");
510 if (bufferSize < 0)
511 throw new ArgumentOutOfRangeException("bufferSize");
512 if (window < TimeSpan.Zero)
513 throw new ArgumentOutOfRangeException("window");
514
515 return s_impl.Replay<TSource>(source, bufferSize, window);
516 }
517
518 /// <summary>
519 /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length and element count for the replay buffer.
520 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>.
521 /// </summary>
522 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
523 /// <typeparam name="TResult">The type of the elements in the result sequence.</typeparam>
524 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
525 /// <param name="selector">Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy.</param>
526 /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
527 /// <param name="window">Maximum time length of the replay buffer.</param>
528 /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
529 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
530 /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero.</exception>
531 /// <exception cref="ArgumentOutOfRangeException"><paramref name="window"/> is less than TimeSpan.Zero.</exception>
532 /// <seealso cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>
533 public static IObservable<TResult> Replay<TSource, TResult>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TResult>> selector, int bufferSize, TimeSpan window)
534 {
535 if (source == null)
536 throw new ArgumentNullException("source");
537 if (selector == null)
538 throw new ArgumentNullException("selector");
539 if (bufferSize < 0)
540 throw new ArgumentOutOfRangeException("bufferSize");
541 if (window < TimeSpan.Zero)
542 throw new ArgumentOutOfRangeException("window");
543
544 return s_impl.Replay<TSource, TResult>(source, selector, bufferSize, window);
545 }
546
547 /// <summary>
548 /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length and element count for the replay buffer.
549 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>.
550 /// </summary>
551 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
552 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
553 /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
554 /// <param name="window">Maximum time length of the replay buffer.</param>
555 /// <param name="scheduler">Scheduler where connected observers will be invoked on.</param>
556 /// <returns>A connectable observable sequence that shares a single subscription to the underlying sequence.</returns>
557 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
558 /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero.</exception>
559 /// <exception cref="ArgumentOutOfRangeException"><paramref name="window"/> is less than TimeSpan.Zero.</exception>
560 /// <remarks>Subscribers will receive all the notifications of the source subject to the specified replay buffer trimming policy.</remarks>
561 /// <seealso cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>
562 public static IConnectableObservable<TSource> Replay<TSource>(this IObservable<TSource> source, int bufferSize, TimeSpan window, IScheduler scheduler)
563 {
564 if (source == null)
565 throw new ArgumentNullException("source");
566 if (bufferSize < 0)
567 throw new ArgumentOutOfRangeException("bufferSize");
568 if (window < TimeSpan.Zero)
569 throw new ArgumentOutOfRangeException("window");
570 if (scheduler == null)
571 throw new ArgumentNullException("scheduler");
572
573 return s_impl.Replay<TSource>(source, bufferSize, window, scheduler);
574 }
575
576 /// <summary>
577 /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length and element count for the replay buffer.
578 /// This operator is a specialization of Multicast using a <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>.
579 /// </summary>
580 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
581 /// <typeparam name="TResult">The type of the elements in the result sequence.</typeparam>
582 /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
583 /// <param name="selector">Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy.</param>
584 /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
585 /// <param name="window">Maximum time length of the replay buffer.</param>
586 /// <param name="scheduler">Scheduler where connected observers within the selector function will be invoked on.</param>
587 /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
588 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> or <paramref name="scheduler"/> is null.</exception>
589 /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero.</exception>
590 /// <exception cref="ArgumentOutOfRangeException"><paramref name="window"/> is less than TimeSpan.Zero.</exception>
591 /// <seealso cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/>
592 public static IObservable<TResult> Replay<TSource, TResult>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TResult>> selector, int bufferSize, TimeSpan window, IScheduler scheduler)
593 {
594 if (source == null)
595 throw new ArgumentNullException("source");
596 if (selector == null)
597 throw new ArgumentNullException("selector");
598 if (bufferSize < 0)
599 throw new ArgumentOutOfRangeException("bufferSize");
600 if (window < TimeSpan.Zero)
601 throw new ArgumentOutOfRangeException("window");
602 if (scheduler == null)
603 throw new ArgumentNullException("scheduler");
604
605 return s_impl.Replay<TSource, TResult>(source, selector, bufferSize, window, scheduler);
606 }
607
608 #endregion
609 }
610 }