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


C# ReplaySubject.OnNext方法代码示例

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


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

示例1: Last_FeedItem_Is_The_One_Published_Later

        public void Last_FeedItem_Is_The_One_Published_Later()
        {
            var testPodcastsSubj = new ReplaySubject<IPodcastItem>();
            IPodcastItemsLoader testPodcasts = new TestPodcastItemsLoader(testPodcastsSubj);

            var initialDate = DateTime.Now;
            testPodcastsSubj.OnNext(new TestPodcastItem(1, initialDate.AddDays(1)));
            testPodcastsSubj.OnNext(new TestPodcastItem(2, initialDate.AddDays(2)));

            _virtualScheduler.AdvanceBy(TimeSpan.FromSeconds(1));
            var model = new FeedViewModel("TestFeed", testPodcasts);
            _virtualScheduler.AdvanceBy(TimeSpan.FromSeconds(1));

            Assert.AreEqual(2, ((TestPodcastItem)model.LastFeedItem).Id);
            Assert.AreEqual(2, model.Items.Count);

            testPodcastsSubj.OnNext(new TestPodcastItem(3, initialDate.AddDays(3)));
            _virtualScheduler.AdvanceBy(TimeSpan.FromSeconds(1));

            Assert.AreEqual(3, ((TestPodcastItem)model.LastFeedItem).Id);

            testPodcastsSubj.OnNext(new TestPodcastItem(4, initialDate.AddDays(-1)));
            _virtualScheduler.AdvanceBy(TimeSpan.FromSeconds(1));
            
            Assert.AreEqual(3, ((TestPodcastItem)model.LastFeedItem).Id);
        }
开发者ID:journeyman,项目名称:PodcastReader,代码行数:26,代码来源:FeedViewModelTests.cs

示例2: LeakyLetterRepo

 public LeakyLetterRepo()
 {
     _letters = new ReplaySubject<string>();
     _letters.OnNext("A");
     _letters.OnNext("B");
     _letters.OnNext("C");
 }
开发者ID:pudae,项目名称:lplpl,代码行数:7,代码来源:Encapsulating.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: UsingSubject

 static IObservable<string> UsingSubject()
 {
     var subject = new ReplaySubject<string>();
       subject.OnNext("a");
       subject.OnNext("b");
       subject.OnCompleted();
       Task.Delay(TimeSpan.FromMilliseconds(3000)).Wait();
       return subject;
 }
开发者ID:pudae,项目名称:lplpl,代码行数:9,代码来源:TestCreate.cs

示例5: 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

示例6: 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

示例7: Returns_Correct_Movement

        public static async Task Returns_Correct_Movement(decimal price1, decimal price2, PriceMovement expected)
        {
            var subject = new ReplaySubject<IPrice>();

            var result = subject.ToPriceMovementStream();
            subject.OnNext(new Price { Mid = price1 });
            subject.OnNext(new Price { Mid = price2 });
            subject.OnCompleted();

            // Assert
            await result.SingleAsync(movement => movement == expected);
        }
开发者ID:tomgilder,项目名称:ReactiveTrader,代码行数:12,代码来源:PriceMovementExtentionsTests.cs

示例8: 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

示例9: 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

示例10: SynchronizationController

 public SynchronizationController(
     IScheduler scheduler, 
     IStartSynchronizing startSynchronizing,
     ITranscodingNotifications transcodingNotifications)
 {
     if (transcodingNotifications == null) throw new ArgumentNullException(nameof(transcodingNotifications), $"{nameof(transcodingNotifications)} is null.");
     if (startSynchronizing == null) throw new ArgumentNullException(nameof(startSynchronizing), $"{nameof(startSynchronizing)} is null.");
     if (scheduler == null) throw new ArgumentNullException(nameof(scheduler));
     _scheduler = scheduler;
     _startSynchronizing = startSynchronizing;
     _transcodingNotifications = transcodingNotifications;
     _enabledDisposable = new ReplaySubject<IDisposable>(1, _scheduler);
     _enabledDisposable.OnNext(null);
     _disposable = _enabledDisposable.Delta((d1, d2) =>
     {
         if (d1 != null)
         {                    
             d1.Dispose();
         }
         return d1 != null || d2 != null;
     })
         .TakeWhile(b => b)
         .SubscribeOn(_scheduler)
         .Subscribe(_ => { }, e => { });
 }
开发者ID:Galad,项目名称:musicmirror,代码行数:25,代码来源:SynchronizationController.cs

示例11: 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

示例12: 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

示例13: Run

        public static void Run()
        {
            // var subject = new ReplaySubject<string>();

              // var subject = new ReplaySubject<string>(2 /* bufferSize */);

              var window = TimeSpan.FromMilliseconds(150);
              var subject = new ReplaySubject<string>(window);

              subject.OnNext("a");
              Task.Delay(TimeSpan.FromMilliseconds(100)).Wait();
              subject.OnNext("b");
              Task.Delay(TimeSpan.FromMilliseconds(100)).Wait();
              subject.OnNext("c");
              WriteSequenceToConsole(subject);
              subject.OnNext("d");
              Console.ReadLine();
        }
开发者ID:pudae,项目名称:lplpl,代码行数:18,代码来源:TestReplaySubject.cs

示例14: 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

示例15: CallOperationOnService

        private static IObservable<ServiceState> CallOperationOnService(ServiceBase serviceBase, Operation operation)
        {
            ReplaySubject<ServiceState> result = new ReplaySubject<ServiceState>();
            result.OnNext(operation.InitialState);

            var methodObs = Observable.Start(() =>
                {
                    Type serviceBaseType = serviceBase.GetType();
                    object[] parameters = null;
                    if (operation == Operations.Start)
                    {
                        parameters = new object[] { null };
                    }

                    try
                    {
                        serviceBaseType.InvokeMember(operation.MethodCall, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, serviceBase, parameters);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(string.Format("An exception was thrown while trying to call the {0} of the {1} service.  Examine the inner exception for more information.", operation, serviceBase.ServiceName), ex.InnerException);
                    }
                });

            methodObs.Subscribe
                (
                    _ =>
                    {
                        result.OnNext(operation.FinishedState);
                        result.OnCompleted();
                    },

                    ex =>
                    {
                        result.OnNext(operation.ErrorState);
                        result.OnError(ex);
                    }
                );

            return result;
        }
开发者ID:Behzadkhosravifar,项目名称:SignalR,代码行数:41,代码来源:ServiceBaseHelpers.cs


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