当前位置: 首页>>代码示例>>C#>>正文


C# ReplaySubject.Subscribe方法代码示例

本文整理汇总了C#中ReplaySubject.Subscribe方法的典型用法代码示例。如果您正苦于以下问题:C# ReplaySubject.Subscribe方法的具体用法?C# ReplaySubject.Subscribe怎么用?C# ReplaySubject.Subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReplaySubject的用法示例。


在下文中一共展示了ReplaySubject.Subscribe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateDownloadObservable

 private static IObservable<byte[]> CreateDownloadObservable(Uri uri)
 {
     return Observable.Create<byte[]>(o => {
         var result = new ReplaySubject<byte[]>();
         var inner = Observable.Using(() => new WebClient(), wc => {
             var obs = Observable
                 .FromEventPattern<
                     DownloadDataCompletedEventHandler,
                     DownloadDataCompletedEventArgs>(
                         h => wc.DownloadDataCompleted += h,
                         h => wc.DownloadDataCompleted -= h)
                 .Take(1);
             wc.DownloadDataAsync(uri);
             return obs;
         }).Subscribe(ep => {
             if (ep.EventArgs.Cancelled) {
                 result.OnCompleted();
             } else {
                 if (ep.EventArgs.Error != null) {
                     result.OnError(ep.EventArgs.Error);
                 } else {
                     result.OnNext(ep.EventArgs.Result);
                     result.OnCompleted();
                 }
             }
         }, ex => {
             result.OnError(ex);
         });
         return new CompositeDisposable(inner, result.Subscribe(o));
     }).Retry(5);
 }
开发者ID:huoxudong125,项目名称:il-repack,代码行数:31,代码来源:NuGetHelpers.cs

示例2: CommandVersioningTests

 public CommandVersioningTests()
 {
     var events = new ReplaySubject<object>();
     events.Subscribe(_publishedEvents.Add);
     _host = new CedarHost(new Bootstrapper(new ObservableMessagePublisher(events)));
     _client = _host.CreateClient();
 }
开发者ID:modulexcite,项目名称:Obsolete-Cedar,代码行数:7,代码来源:CommandVersioningTests.cs

示例3: ReplaySubject

 ///<summary>
 ///ReplaySubject<T> will listen to all publications once subscribed. 
 ///The subscriber will also get all publications made before subscription.
 ///Simply, ReplaySubject has a buffer in whihc it will keep all the publications made for future subscriptions.
 ///</summary>
 private static void ReplaySubject()
 {
     var subject = new ReplaySubject<string>();
         subject.OnNext("a");
         subject.Subscribe(Console.WriteLine);
         subject.OnNext("b");
         subject.OnNext("c");
 }
开发者ID:cypherwars,项目名称:ReactiveExtensions,代码行数:13,代码来源:Program.cs

示例4: BlockingMethod

 ///<summary>
 ///The Method simulates a blocking call by assigning the Immediate Thread as the Thread of execution
 /// The execution will move into asyncmode when we call the Nonblocking Method
 /// </summary>
 private static IObservable<string> BlockingMethod()
 {
     var subject = new ReplaySubject<string>(Scheduler.Immediate);
       subject.Subscribe(Console.WriteLine);
       subject.OnNext("a");
       subject.OnNext("b");
       subject.OnCompleted();
       Thread.Sleep(2000);
       return subject;
 }
开发者ID:cypherwars,项目名称:ReactiveExtensions,代码行数:14,代码来源:Program.cs

示例5: ReplaySubjectBufferExample

 public static void ReplaySubjectBufferExample()
 {
     var bufferSize = 2;
     var subject = new ReplaySubject<string>(bufferSize);
     subject.OnNext("a");
     subject.OnNext("b");
     subject.OnNext("c");
     subject.Subscribe(Console.WriteLine);
     subject.OnNext("d");
 }
开发者ID:JonDouglas,项目名称:ReactivePlayground,代码行数:10,代码来源:Program.cs

示例6: ReplaySubjectWindowExample

 public static void ReplaySubjectWindowExample()
 {
     var window = TimeSpan.FromMilliseconds(150);
     var subject = new ReplaySubject<string>(window);
     subject.OnNext("w");
     Thread.Sleep(TimeSpan.FromMilliseconds(100));
     subject.OnNext("x");
     Thread.Sleep(TimeSpan.FromMilliseconds(100));
     subject.OnNext("y");
     subject.Subscribe(Console.WriteLine);
     subject.OnNext("z");
 }
开发者ID:JonDouglas,项目名称:ReactivePlayground,代码行数:12,代码来源:Program.cs

示例7: Start

        private void Start()
        {
            //ReplaySubjectも初期を設定することができる(今回は設定しない)
            replaySubject = new ReplaySubject<int>();

            /*
            OnNextを何回か繰り返す → Subscribe と実行し、Subscribeした瞬間に過去の値がまとめて値が発行されることを確認しよう
            */

            // Subscribeボタンが押されたらSubjectをSubscribeしてresultTextに表示する
            subscribeButton.OnClickAsObservable().Subscribe(_ =>
            {
                if (replaySubject != null)
                {
                    replaySubject.Subscribe(
                        time => resultText.text += time.ToString() + " ", //OnNext
                        () => resultText.text += "OnCompleted "); //OnCompleted
                }
            });

            // OnNextボタンが押されたら今が何度目のOnNextであるかを発行する
            onNextButton.OnClickAsObservable().Subscribe(_ =>
            {
                if (replaySubject != null)
                {
                    replaySubject.OnNext(++onNextCount);
                }
            });

            // OnCompletedボタンが押されたらOnCompletedを発行する
            onCompletedButton.OnClickAsObservable().Subscribe(_ =>
            {
                if (replaySubject != null)
                {
                    replaySubject.OnCompleted();
                }
            });

            // Resetボタンが押されたら全体を初期化する
            resetButton.OnClickAsObservable().Subscribe(_ =>
            {
                if (replaySubject != null)
                {
                    replaySubject.OnCompleted();
                }
                replaySubject = new ReplaySubject<int>();
                resultText.text = "";
                onNextCount = 0;
            });
        }
开发者ID:TORISOUP,项目名称:UniRxWorkBook,代码行数:50,代码来源:Lesson_3_ReplaySubject.cs

示例8: honours_buffer_size_for_replays_with_priority_to_most_recent

        public void honours_buffer_size_for_replays_with_priority_to_most_recent()
        {
            ReplaySubject<int> subject = new ReplaySubject<int>(2);

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);

            subject.Subscribe(stats);

            Assert.AreEqual(2, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 2, 3 }));
            Assert.IsFalse(stats.CompletedCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:16,代码来源:ReplaySubjectFixture.cs

示例9: errors_are_sent_through_scheduler

        public void errors_are_sent_through_scheduler()
        {
            ManualScheduler scheduler = new ManualScheduler();

            ReplaySubject<int> subject = new ReplaySubject<int>(scheduler);

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.OnError(new Exception());

            subject.Subscribe(stats);

            Assert.IsFalse(stats.ErrorCalled);

            scheduler.RunNext();
            Assert.IsTrue(stats.ErrorCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:17,代码来源:ReplaySubjectFixture.cs

示例10: buffer_size_includes_onerror

        public void buffer_size_includes_onerror()
        {
            ReplaySubject<int> subject = new ReplaySubject<int>(2);

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);
            subject.OnError(new Exception());

            subject.Subscribe(stats);

            Assert.AreEqual(1, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 3 }));
            Assert.IsTrue(stats.ErrorCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:17,代码来源:ReplaySubjectFixture.cs

示例11: Example2

        private static void Example2()
        {
            Console.WriteLine("Starting on threadId:{0}", Util.GetTid());

              var subject = new ReplaySubject<int>();

              subject.OnNext(0);
              subject.OnNext(1);
              subject.OnNext(2);

              subject
            // .SubscribeOn(NewThreadScheduler.Default)
            .Subscribe(
              i => Console.WriteLine("Received {1} on threadId:{0}", Util.GetTid(), i),
              () => Console.WriteLine("OnCompleted on threadId:{0}", Util.GetTid()));
              Console.WriteLine("Subscribed on threadId:{0}", Util.GetTid());

              Task.Delay(TimeSpan.FromMilliseconds(500)).Wait();
        }
开发者ID:pudae,项目名称:lplpl,代码行数:19,代码来源:TestSubject.cs

示例12: StartsTrueBecomesFalseWhenCompleted

        public async Task StartsTrueBecomesFalseWhenCompleted()
        {
            var repoSubject = new Subject<IRemoteRepositoryModel>();
            var col = TrackingCollection.Create(repoSubject);
            var repositoryHost = Substitute.For<IRepositoryHost>();
            repositoryHost.ModelService.GetRepositories(Arg.Any<ITrackingCollection<IRemoteRepositoryModel>>()).Returns(_ => col);

            var cloneService = Substitute.For<IRepositoryCloneService>();
            var vm = GetVM(
                repositoryHost,
                cloneService,
                Substitute.For<IOperatingSystem>(),
                Substitute.For<INotificationService>(),
                Substitute.For<IUsageTracker>());

            Assert.True(vm.IsLoading);

            var done = new ReplaySubject<Unit>();
            done.OnNext(Unit.Default);
            done.Subscribe();
            col.Subscribe(t => done?.OnCompleted(), () => { });

            repoSubject.OnNext(Substitute.For<IRemoteRepositoryModel>());
            repoSubject.OnNext(Substitute.For<IRemoteRepositoryModel>());

            await done;
            done = null;

            Assert.True(vm.IsLoading);

            repoSubject.OnCompleted();

            await col.OriginalCompleted;

            Assert.False(vm.IsLoading);
        }
开发者ID:github,项目名称:VisualStudio,代码行数:36,代码来源:RepositoryCloneViewModelTests.cs

示例13: Completed_to_late_subscriber_ReplayMany

        public void Completed_to_late_subscriber_ReplayMany()
        {
            var s = new ReplaySubject<int>(2);
            s.OnNext(1);
            s.OnNext(2);
            s.OnNext(3);
            s.OnCompleted();

            var scheduler = new TestScheduler();
            var observer = scheduler.CreateObserver<int>();
            s.Subscribe(observer);

            Assert.Equal(3, observer.Messages.Count);

            Assert.Equal(2, observer.Messages[0].Value.Value);
            Assert.Equal(3, observer.Messages[1].Value.Value);
            Assert.Equal(NotificationKind.OnCompleted, observer.Messages[2].Value.Kind);
        }
开发者ID:RolandPheasant,项目名称:Rx.NET,代码行数:18,代码来源:ReplaySubjectTest.cs

示例14: HasObservers_OnCompleted

        private static void HasObservers_OnCompleted(ReplaySubject<int> s)
        {
            Assert.False(s.HasObservers);

            var d = s.Subscribe(_ => { });
            Assert.True(s.HasObservers);

            s.OnNext(42);
            Assert.True(s.HasObservers);

            s.OnCompleted();
            Assert.False(s.HasObservers);
        }
开发者ID:RolandPheasant,项目名称:Rx.NET,代码行数:13,代码来源:ReplaySubjectTest.cs

示例15: HasObservers_OnError

        private static void HasObservers_OnError(ReplaySubject<int> s)
        {
            Assert.False(s.HasObservers);

            var d = s.Subscribe(_ => { }, ex => { });
            Assert.True(s.HasObservers);

            s.OnNext(42);
            Assert.True(s.HasObservers);

            s.OnError(new Exception());
            Assert.False(s.HasObservers);
        }
开发者ID:RolandPheasant,项目名称:Rx.NET,代码行数:13,代码来源:ReplaySubjectTest.cs


注:本文中的ReplaySubject.Subscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。