Repository navigation
Expand file tree
/
Copy pathWhenAnyObservableExamples.cs
More file actions
729 lines (597 loc) · 28.5 KB
/
Copy pathWhenAnyObservableExamples.cs
File metadata and controls
729 lines (597 loc) · 28.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
// Copyright (c) ReactiveUI and Contributors. All rights reserved.
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
using ReactiveUI.Binding.Documentation.GitHub;
using ReactiveUI.Primitives;
namespace ReactiveUI.Binding.Documentation.Observing;
/// <summary>
/// Shows every <c>WhenAnyObservable</c> overload. The properties you name hold observables, and the feed swaps them at
/// run time. <c>WhenAnyObservable</c> follows whichever observable each property holds now and drops the one it held
/// before. With one to twelve properties and no selector it merges the streams into one. With two to twelve
/// properties and a selector it delivers the selector's result whenever any stream emits, once every stream has
/// emitted at least once.
/// </summary>
public static class WhenAnyObservableExamples
{
/// <summary>The name of the repository the examples follow first.</summary>
private const string WebshopName = "webshop";
/// <summary>The name of the repository the examples switch to.</summary>
private const string MobileAppName = "mobile-app";
/// <summary>The number of open issues the repository reports.</summary>
private const int OpenIssueCount = 12;
/// <summary>The announcement published on every stream before a selector has all its inputs.</summary>
private const string MaintenanceNotice = "Maintenance starts at 22:00 UTC";
/// <summary>An event that arrives on a stream the feed no longer follows.</summary>
private const string StaleEvent = "#55 opened: Reported before the switch";
/// <summary>An event that arrives on the repository the feed switched to.</summary>
private const string MobileAppEvent = "#7 opened: App crashes on start";
/// <summary>The event that arrives on the issue opened stream.</summary>
private const string IssueOpenedEvent = "#101 opened: Checkout button unresponsive";
/// <summary>The event that arrives on the issue closed stream.</summary>
private const string IssueClosedEvent = "#98 closed: Cart total rounds down";
/// <summary>The event that arrives on the issue reopened stream.</summary>
private const string IssueReopenedEvent = "#97 reopened: Login loops on Safari";
/// <summary>The event that arrives on the issue assigned stream.</summary>
private const string IssueAssignedEvent = "#101 assigned to priya-nair";
/// <summary>The event that arrives on the issue labelled stream.</summary>
private const string IssueLabelledEvent = "#101 labelled bug";
/// <summary>The event that arrives on the comment added stream.</summary>
private const string CommentAddedEvent = "#101 comment: Fixed in the next release.";
/// <summary>The event that arrives on the comment edited stream.</summary>
private const string CommentEditedEvent = "#101 comment edited";
/// <summary>The event that arrives on the milestone changed stream.</summary>
private const string MilestoneChangedEvent = "#101 milestone: 2.4";
/// <summary>The event that arrives on the pull request opened stream.</summary>
private const string PullRequestOpenedEvent = "PR #205 opened";
/// <summary>The event that arrives on the pull request merged stream.</summary>
private const string PullRequestMergedEvent = "PR #205 merged";
/// <summary>The event that arrives on the review requested stream.</summary>
private const string ReviewRequestedEvent = "PR #205 review requested from tomas-berg";
/// <summary>The event that arrives on the release published stream.</summary>
private const string ReleasePublishedEvent = "Release 2.4 published";
/// <summary>The repository the feed follows first.</summary>
private static readonly Repository _webshop = new("acme", WebshopName, "The online shop", OpenIssueCount);
/// <summary>The repository the feed switches to.</summary>
private static readonly Repository _mobileApp = new("acme", MobileAppName, "The mobile app", 1);
/// <summary>Follows one stream. A single stream delivers exactly what its property holds.</summary>
public static void FollowIssueOpened()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed.WhenAnyObservable(static x => x.IssueOpened).Subscribe(Console.WriteLine);
webshop.IssueOpened.OnNext(IssueOpenedEvent);
// Output:
// #101 opened: Checkout button unresponsive
}
/// <summary>Selects another repository: the stream of the first one is dropped and the new one is followed.</summary>
public static void SwitchStreamWhenRepositoryChanges()
{
using RepositoryChannels webshop = new(_webshop);
using RepositoryChannels mobileApp = new(_mobileApp);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed.WhenAnyObservable(static x => x.IssueOpened).Subscribe(Console.WriteLine);
Console.WriteLine(webshop.IssueOpened.HasObservers);
feed.Follow(mobileApp);
Console.WriteLine(webshop.IssueOpened.HasObservers);
Console.WriteLine(mobileApp.IssueOpened.HasObservers);
webshop.IssueOpened.OnNext(StaleEvent);
mobileApp.IssueOpened.OnNext(MobileAppEvent);
// Output:
// True
// False
// True
// #7 opened: App crashes on start
}
/// <summary>Stops following: a property that holds no observable delivers nothing and keeps no subscription.</summary>
public static void StopWhenNoRepositoryIsFollowed()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed.WhenAnyObservable(static x => x.IssueOpened).Subscribe(Console.WriteLine);
feed.Unfollow();
Console.WriteLine(webshop.IssueOpened.HasObservers);
webshop.IssueOpened.OnNext(StaleEvent);
feed.Follow(webshop);
webshop.IssueOpened.OnNext(IssueOpenedEvent);
// Output:
// False
// #101 opened: Checkout button unresponsive
}
/// <summary>Follows only the streams the call names: the other streams of the repository keep no subscriber.</summary>
public static void SubscribeOnlyToNamedStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed.WhenAnyObservable(static x => x.IssueOpened, static x => x.ReleasePublished).Subscribe(Console.WriteLine);
Console.WriteLine(webshop.SubscribedStreamCount);
// Output:
// 2
}
/// <summary>Merges the opened and closed issue streams of the followed repository into one feed.</summary>
public static void MergeTwoStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(static x => x.IssueOpened, static x => x.IssueClosed)
.Subscribe(Console.WriteLine);
webshop.IssueClosed.OnNext(IssueClosedEvent);
webshop.IssueOpened.OnNext(IssueOpenedEvent);
// Output:
// #98 closed: Cart total rounds down
// #101 opened: Checkout button unresponsive
}
/// <summary>Merges the issue lifecycle streams: opened, closed and reopened.</summary>
public static void MergeThreeStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(static x => x.IssueOpened, static x => x.IssueClosed, static x => x.IssueReopened)
.Subscribe(Console.WriteLine);
webshop.IssueReopened.OnNext(IssueReopenedEvent);
webshop.IssueOpened.OnNext(IssueOpenedEvent);
// Output:
// #97 reopened: Login loops on Safari
// #101 opened: Checkout button unresponsive
}
/// <summary>Merges four streams and adds the assignments a triage lead watches.</summary>
public static void MergeFourStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(
static x => x.IssueOpened,
static x => x.IssueClosed,
static x => x.IssueReopened,
static x => x.IssueAssigned)
.Subscribe(Console.WriteLine);
webshop.IssueAssigned.OnNext(IssueAssignedEvent);
webshop.IssueOpened.OnNext(IssueOpenedEvent);
// Output:
// #101 assigned to priya-nair
// #101 opened: Checkout button unresponsive
}
/// <summary>Merges five streams and adds the labels.</summary>
public static void MergeFiveStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(
static x => x.IssueOpened,
static x => x.IssueClosed,
static x => x.IssueReopened,
static x => x.IssueAssigned,
static x => x.IssueLabelled)
.Subscribe(Console.WriteLine);
webshop.IssueLabelled.OnNext(IssueLabelledEvent);
webshop.IssueOpened.OnNext(IssueOpenedEvent);
// Output:
// #101 labelled bug
// #101 opened: Checkout button unresponsive
}
/// <summary>Merges six streams and adds new comments.</summary>
public static void MergeSixStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(
static x => x.IssueOpened,
static x => x.IssueClosed,
static x => x.IssueReopened,
static x => x.IssueAssigned,
static x => x.IssueLabelled,
static x => x.CommentAdded)
.Subscribe(Console.WriteLine);
webshop.CommentAdded.OnNext(CommentAddedEvent);
webshop.IssueOpened.OnNext(IssueOpenedEvent);
// Output:
// #101 comment: Fixed in the next release.
// #101 opened: Checkout button unresponsive
}
/// <summary>Merges seven streams and adds edited comments.</summary>
public static void MergeSevenStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(
static x => x.IssueOpened,
static x => x.IssueClosed,
static x => x.IssueReopened,
static x => x.IssueAssigned,
static x => x.IssueLabelled,
static x => x.CommentAdded,
static x => x.CommentEdited)
.Subscribe(Console.WriteLine);
webshop.CommentEdited.OnNext(CommentEditedEvent);
webshop.IssueOpened.OnNext(IssueOpenedEvent);
// Output:
// #101 comment edited
// #101 opened: Checkout button unresponsive
}
/// <summary>Merges eight streams and adds milestone changes.</summary>
public static void MergeEightStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(
static x => x.IssueOpened,
static x => x.IssueClosed,
static x => x.IssueReopened,
static x => x.IssueAssigned,
static x => x.IssueLabelled,
static x => x.CommentAdded,
static x => x.CommentEdited,
static x => x.MilestoneChanged)
.Subscribe(Console.WriteLine);
webshop.MilestoneChanged.OnNext(MilestoneChangedEvent);
webshop.IssueOpened.OnNext(IssueOpenedEvent);
// Output:
// #101 milestone: 2.4
// #101 opened: Checkout button unresponsive
}
/// <summary>Merges nine streams and adds pull requests as they open.</summary>
public static void MergeNineStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(
static x => x.IssueOpened,
static x => x.IssueClosed,
static x => x.IssueReopened,
static x => x.IssueAssigned,
static x => x.IssueLabelled,
static x => x.CommentAdded,
static x => x.CommentEdited,
static x => x.MilestoneChanged,
static x => x.PullRequestOpened)
.Subscribe(Console.WriteLine);
webshop.PullRequestOpened.OnNext(PullRequestOpenedEvent);
webshop.IssueOpened.OnNext(IssueOpenedEvent);
// Output:
// PR #205 opened
// #101 opened: Checkout button unresponsive
}
/// <summary>Merges ten streams and adds merged pull requests.</summary>
public static void MergeTenStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(
static x => x.IssueOpened,
static x => x.IssueClosed,
static x => x.IssueReopened,
static x => x.IssueAssigned,
static x => x.IssueLabelled,
static x => x.CommentAdded,
static x => x.CommentEdited,
static x => x.MilestoneChanged,
static x => x.PullRequestOpened,
static x => x.PullRequestMerged)
.Subscribe(Console.WriteLine);
webshop.PullRequestMerged.OnNext(PullRequestMergedEvent);
webshop.IssueOpened.OnNext(IssueOpenedEvent);
// Output:
// PR #205 merged
// #101 opened: Checkout button unresponsive
}
/// <summary>Merges eleven streams and adds review requests.</summary>
public static void MergeElevenStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(
static x => x.IssueOpened,
static x => x.IssueClosed,
static x => x.IssueReopened,
static x => x.IssueAssigned,
static x => x.IssueLabelled,
static x => x.CommentAdded,
static x => x.CommentEdited,
static x => x.MilestoneChanged,
static x => x.PullRequestOpened,
static x => x.PullRequestMerged,
static x => x.ReviewRequested)
.Subscribe(Console.WriteLine);
webshop.ReviewRequested.OnNext(ReviewRequestedEvent);
webshop.IssueOpened.OnNext(IssueOpenedEvent);
// Output:
// PR #205 review requested from tomas-berg
// #101 opened: Checkout button unresponsive
}
/// <summary>Merges twelve streams, the most one call accepts, and adds releases.</summary>
public static void MergeTwelveStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(
static x => x.IssueOpened,
static x => x.IssueClosed,
static x => x.IssueReopened,
static x => x.IssueAssigned,
static x => x.IssueLabelled,
static x => x.CommentAdded,
static x => x.CommentEdited,
static x => x.MilestoneChanged,
static x => x.PullRequestOpened,
static x => x.PullRequestMerged,
static x => x.ReviewRequested,
static x => x.ReleasePublished)
.Subscribe(Console.WriteLine);
webshop.ReleasePublished.OnNext(ReleasePublishedEvent);
webshop.IssueOpened.OnNext(IssueOpenedEvent);
// Output:
// Release 2.4 published
// #101 opened: Checkout button unresponsive
}
/// <summary>Combines the first and last of two streams with a selector, once each stream has emitted.</summary>
public static void CombineTwoStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(static x => x.IssueOpened, static x => x.IssueClosed, static (first, last) => $"{first} / {last}")
.Subscribe(Console.WriteLine);
webshop.PublishNotice(MaintenanceNotice);
webshop.IssueClosed.OnNext(IssueClosedEvent);
// Output:
// Maintenance starts at 22:00 UTC / Maintenance starts at 22:00 UTC
// Maintenance starts at 22:00 UTC / #98 closed: Cart total rounds down
}
/// <summary>Combines the first and last of three streams with a selector, once each stream has emitted.</summary>
public static void CombineThreeStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(static x => x.IssueOpened, static x => x.IssueClosed, static x => x.IssueReopened, static (first, _, last) => $"{first} / {last}")
.Subscribe(Console.WriteLine);
webshop.PublishNotice(MaintenanceNotice);
webshop.IssueReopened.OnNext(IssueReopenedEvent);
// Output:
// Maintenance starts at 22:00 UTC / Maintenance starts at 22:00 UTC
// Maintenance starts at 22:00 UTC / #97 reopened: Login loops on Safari
}
/// <summary>Combines the first and last of four streams with a selector, once each stream has emitted.</summary>
public static void CombineFourStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(
static x => x.IssueOpened,
static x => x.IssueClosed,
static x => x.IssueReopened,
static x => x.IssueAssigned,
static (first, _, _, last) => $"{first} / {last}")
.Subscribe(Console.WriteLine);
webshop.PublishNotice(MaintenanceNotice);
webshop.IssueAssigned.OnNext(IssueAssignedEvent);
// Output:
// Maintenance starts at 22:00 UTC / Maintenance starts at 22:00 UTC
// Maintenance starts at 22:00 UTC / #101 assigned to priya-nair
}
/// <summary>Combines the first and last of five streams with a selector, once each stream has emitted.</summary>
public static void CombineFiveStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(
static x => x.IssueOpened,
static x => x.IssueClosed,
static x => x.IssueReopened,
static x => x.IssueAssigned,
static x => x.IssueLabelled,
static (first, _, _, _, last) => $"{first} / {last}")
.Subscribe(Console.WriteLine);
webshop.PublishNotice(MaintenanceNotice);
webshop.IssueLabelled.OnNext(IssueLabelledEvent);
// Output:
// Maintenance starts at 22:00 UTC / Maintenance starts at 22:00 UTC
// Maintenance starts at 22:00 UTC / #101 labelled bug
}
/// <summary>Combines the first and last of six streams with a selector, once each stream has emitted.</summary>
public static void CombineSixStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(
static x => x.IssueOpened,
static x => x.IssueClosed,
static x => x.IssueReopened,
static x => x.IssueAssigned,
static x => x.IssueLabelled,
static x => x.CommentAdded,
static (first, _, _, _, _, last) => $"{first} / {last}")
.Subscribe(Console.WriteLine);
webshop.PublishNotice(MaintenanceNotice);
webshop.CommentAdded.OnNext(CommentAddedEvent);
// Output:
// Maintenance starts at 22:00 UTC / Maintenance starts at 22:00 UTC
// Maintenance starts at 22:00 UTC / #101 comment: Fixed in the next release.
}
/// <summary>Combines the first and last of seven streams with a selector, once each stream has emitted.</summary>
public static void CombineSevenStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(
static x => x.IssueOpened,
static x => x.IssueClosed,
static x => x.IssueReopened,
static x => x.IssueAssigned,
static x => x.IssueLabelled,
static x => x.CommentAdded,
static x => x.CommentEdited,
static (first, _, _, _, _, _, last) => $"{first} / {last}")
.Subscribe(Console.WriteLine);
webshop.PublishNotice(MaintenanceNotice);
webshop.CommentEdited.OnNext(CommentEditedEvent);
// Output:
// Maintenance starts at 22:00 UTC / Maintenance starts at 22:00 UTC
// Maintenance starts at 22:00 UTC / #101 comment edited
}
/// <summary>Combines the first and last of eight streams with a selector, once each stream has emitted.</summary>
public static void CombineEightStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(
static x => x.IssueOpened,
static x => x.IssueClosed,
static x => x.IssueReopened,
static x => x.IssueAssigned,
static x => x.IssueLabelled,
static x => x.CommentAdded,
static x => x.CommentEdited,
static x => x.MilestoneChanged,
static (first, _, _, _, _, _, _, last) => $"{first} / {last}")
.Subscribe(Console.WriteLine);
webshop.PublishNotice(MaintenanceNotice);
webshop.MilestoneChanged.OnNext(MilestoneChangedEvent);
// Output:
// Maintenance starts at 22:00 UTC / Maintenance starts at 22:00 UTC
// Maintenance starts at 22:00 UTC / #101 milestone: 2.4
}
/// <summary>Combines the first and last of nine streams with a selector, once each stream has emitted.</summary>
public static void CombineNineStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(
static x => x.IssueOpened,
static x => x.IssueClosed,
static x => x.IssueReopened,
static x => x.IssueAssigned,
static x => x.IssueLabelled,
static x => x.CommentAdded,
static x => x.CommentEdited,
static x => x.MilestoneChanged,
static x => x.PullRequestOpened,
static (first, _, _, _, _, _, _, _, last) => $"{first} / {last}")
.Subscribe(Console.WriteLine);
webshop.PublishNotice(MaintenanceNotice);
webshop.PullRequestOpened.OnNext(PullRequestOpenedEvent);
// Output:
// Maintenance starts at 22:00 UTC / Maintenance starts at 22:00 UTC
// Maintenance starts at 22:00 UTC / PR #205 opened
}
/// <summary>Combines the first and last of ten streams with a selector, once each stream has emitted.</summary>
public static void CombineTenStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(
static x => x.IssueOpened,
static x => x.IssueClosed,
static x => x.IssueReopened,
static x => x.IssueAssigned,
static x => x.IssueLabelled,
static x => x.CommentAdded,
static x => x.CommentEdited,
static x => x.MilestoneChanged,
static x => x.PullRequestOpened,
static x => x.PullRequestMerged,
static (first, _, _, _, _, _, _, _, _, last) => $"{first} / {last}")
.Subscribe(Console.WriteLine);
webshop.PublishNotice(MaintenanceNotice);
webshop.PullRequestMerged.OnNext(PullRequestMergedEvent);
// Output:
// Maintenance starts at 22:00 UTC / Maintenance starts at 22:00 UTC
// Maintenance starts at 22:00 UTC / PR #205 merged
}
/// <summary>Combines the first and last of eleven streams with a selector, once each stream has emitted.</summary>
public static void CombineElevenStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(
static x => x.IssueOpened,
static x => x.IssueClosed,
static x => x.IssueReopened,
static x => x.IssueAssigned,
static x => x.IssueLabelled,
static x => x.CommentAdded,
static x => x.CommentEdited,
static x => x.MilestoneChanged,
static x => x.PullRequestOpened,
static x => x.PullRequestMerged,
static x => x.ReviewRequested,
static (first, _, _, _, _, _, _, _, _, _, last) => $"{first} / {last}")
.Subscribe(Console.WriteLine);
webshop.PublishNotice(MaintenanceNotice);
webshop.ReviewRequested.OnNext(ReviewRequestedEvent);
// Output:
// Maintenance starts at 22:00 UTC / Maintenance starts at 22:00 UTC
// Maintenance starts at 22:00 UTC / PR #205 review requested from tomas-berg
}
/// <summary>Combines the first and last of twelve streams with a selector, once each stream has emitted.</summary>
public static void CombineTwelveStreams()
{
using RepositoryChannels webshop = new(_webshop);
RepositoryFeedViewModel feed = new();
feed.Follow(webshop);
using IDisposable subscription = feed
.WhenAnyObservable(
static x => x.IssueOpened,
static x => x.IssueClosed,
static x => x.IssueReopened,
static x => x.IssueAssigned,
static x => x.IssueLabelled,
static x => x.CommentAdded,
static x => x.CommentEdited,
static x => x.MilestoneChanged,
static x => x.PullRequestOpened,
static x => x.PullRequestMerged,
static x => x.ReviewRequested,
static x => x.ReleasePublished,
static (first, _, _, _, _, _, _, _, _, _, _, last) => $"{first} / {last}")
.Subscribe(Console.WriteLine);
webshop.PublishNotice(MaintenanceNotice);
webshop.ReleasePublished.OnNext(ReleasePublishedEvent);
// Output:
// Maintenance starts at 22:00 UTC / Maintenance starts at 22:00 UTC
// Maintenance starts at 22:00 UTC / Release 2.4 published
}
}