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


C# BehaviorSubject.OnNext方法代码示例

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


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

示例1: Should_Produce_Correct_Values

        public void Should_Produce_Correct_Values()
        {
            var activator = new BehaviorSubject<bool>(false);
            var source = new BehaviorSubject<object>(1);
            var target = new ActivatedObservable(activator, source, string.Empty);
            var result = new List<object>();

            target.Subscribe(x => result.Add(x));

            activator.OnNext(true);
            source.OnNext(2);
            activator.OnNext(false);
            source.OnNext(3);
            activator.OnNext(true);

            Assert.Equal(
                new[] 
                {
                    AvaloniaProperty.UnsetValue,
                    1,
                    2,
                    AvaloniaProperty.UnsetValue,
                    3,
                }, 
                result);
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:26,代码来源:ActivatedObservableTests.cs

示例2: BehaviorSubjectExample3

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

示例3: Example4

 static void Example4()
 {
     var subject = new BehaviorSubject<string>("a");
       subject.OnNext("b");
       subject.OnNext("c");
       subject.OnNext("d");
       subject.OnCompleted();
       subject.Subscribe(Console.WriteLine);
 }
开发者ID:pudae,项目名称:lplpl,代码行数:9,代码来源:TestBehaviorSubject.cs

示例4: BehaviourSubject

 ///<summary>
 ///With BehaviourSubject<T> ,the subscriber will only get all the last publication made
 ///Simply, BehaviourSubject has a one value buffer. Hence, it requires a default value.
 ///</summary>
 private static void BehaviourSubject()
 {
     var subject = new BehaviorSubject<string>("Rx");
         subject.OnNext("a");
         var d = subject.Subscribe(x => Console.WriteLine("Subscritipon 1 : " + x));
         subject.OnNext("b");
        // var d = subject.Subscribe(x => Console.WriteLine("Subscritipon 1 : " + x));
         d.Dispose();
         subject.OnNext("c");
         subject.Subscribe(x => Console.WriteLine("Subscritipon 2 : " + x));
 }
开发者ID:cypherwars,项目名称:ReactiveExtensions,代码行数:15,代码来源:Program.cs

示例5: Should_Change_Value_On_Activator_Change

        public void Should_Change_Value_On_Activator_Change()
        {
            var activator = new BehaviorSubject<bool>(false);
            var target = new StyleBinding(activator, 1, string.Empty);
            var result = new List<object>();

            target.Subscribe(x => result.Add(x));

            activator.OnNext(true);
            activator.OnNext(false);

            Assert.Equal(new[] { PerspexProperty.UnsetValue, 1, PerspexProperty.UnsetValue }, result);
        }
开发者ID:Arlorean,项目名称:Perspex,代码行数:13,代码来源:StyleBindingTests.cs

示例6: Should_Produce_Correct_Values

        public void Should_Produce_Correct_Values()
        {
            var activator = new BehaviorSubject<bool>(false);
            var target = new ActivatedValue(activator, 1, string.Empty);
            var result = new List<object>();

            target.Subscribe(x => result.Add(x));

            activator.OnNext(true);
            activator.OnNext(false);

            Assert.Equal(new[] { PerspexProperty.UnsetValue, 1, PerspexProperty.UnsetValue }, result);
        }
开发者ID:KvanTTT,项目名称:Perspex,代码行数:13,代码来源:ActivatedValueTests.cs

示例7: Observable_Current_returns_latest_element

        public async Task Observable_Current_returns_latest_element()
        {
            var subject = new BehaviorSubject<int>(1);
            var asyncEnumerable = subject.Current();

            using (var asyncEnumerator = asyncEnumerable.GetEnumerator())
            {
                subject.OnNext(2);
                subject.OnNext(3);
                subject.OnNext(4);

                Assert.True(await asyncEnumerator.MoveNext(CancellationToken.None));
                Assert.Equal(4, asyncEnumerator.Current);
            }
        }
开发者ID:ExRam,项目名称:ExRam.Extensions,代码行数:15,代码来源:ObservableExtensionsTests.cs

示例8: OneTime_Binding_Should_Be_Set_Up

        public void OneTime_Binding_Should_Be_Set_Up()
        {
            var dataContext = new BehaviorSubject<object>(null);
            var expression = new BehaviorSubject<object>(null);
            var target = CreateTarget(dataContext: dataContext);
            var binding = new Binding
            {
                Path = "Foo",
                Mode = BindingMode.OneTime,
            };

            binding.Bind(target.Object, TextBox.TextProperty, expression);

            target.Verify(x => x.SetValue(
                (PerspexProperty)TextBox.TextProperty, 
                null, 
                BindingPriority.LocalValue));
            target.ResetCalls();

            expression.OnNext("foo");
            dataContext.OnNext(1);

            target.Verify(x => x.SetValue(
                (PerspexProperty)TextBox.TextProperty,
                "foo",
                BindingPriority.LocalValue));
        }
开发者ID:furesoft,项目名称:Perspex,代码行数:27,代码来源:BindingTests.cs

示例9: RedisLogger

        internal RedisLogger(string key, ILog log, IRedisConnectionFactory redisConnectionFactory)
        {
            this.key = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", log.Logger.Name, key);
            this.log = log;
            this.messagesSubject = new ReplaySubject<Tuple<string, string>>(100, TimeSpan.FromSeconds(5));
            this.retry = new BehaviorSubject<bool>(false);

            var redisOnConnectionAction = new Action<Task<RedisConnection>>(task =>
            {
                if (task.IsCompleted && !task.IsFaulted)
                {
                    Interlocked.CompareExchange<RedisConnection>(ref this.redisConnection, task.Result, null);
                    subscription = messagesSubject.TakeUntil(retry.Skip(1)).Subscribe((item) => 
                        {
                            redisConnection.Publish(item.Item1, item.Item2).ContinueWith(taskWithException =>
                                {
                                    taskWithException.Exception.Handle(ex => true);
                                }, TaskContinuationOptions.OnlyOnFaulted);
                        });
                }
            });

            var redisOnErrorAction = new Action<ErrorEventArgs>(ex =>
                {
                    if (ex.IsFatal)
                    {
                        retry.OnNext(true);
                        Interlocked.Exchange<RedisConnection>(ref this.redisConnection, null);
                    }
                });

            Action subscribeAction = () =>
            {
                var connectionTask = redisConnectionFactory.CreateRedisConnection();
                connectionTask.ContinueWith(taskConnection =>
                    {
                        if (!taskConnection.IsFaulted)
                        {
                            taskConnection.ContinueWith(redisOnConnectionAction);
                            taskConnection.Result.Error += (_, err) => redisOnErrorAction(err);
                        }
                        else
                        {
                            taskConnection.Exception.Handle(_ => true);
                            this.retry.OnNext(true);
                        }
                    });
            };

            retry.Subscribe(val =>
                {
                    if (val)
                        Observable.Timer(TimeSpan.FromSeconds(10)).Subscribe(_ => subscribeAction()); 
                    else
                        subscribeAction();
                });
        }
开发者ID:g-un--,项目名称:log4net.redis,代码行数:57,代码来源:RedisLogger.cs

示例10: Main

    protected override void Main()
    {
      if (Environment.OSVersion.Version < new Version(6, 2))
      {
        TraceError(Text.LabRequiresWindows8OrHigher);
        return;
      }

      const int port = 5494;
      string subProtocol = GetType().Name;

      var userMessages = new BehaviorSubject<string>(null);

      var client = new ClientWebSocket();

      client.Options.AddSubProtocol(subProtocol);

      using (client)
      using (var cancel = new CancellationDisposable())
      using (ObservableHttpListener
        .StartWebSockets(new IPEndPoint(IPAddress.Loopback, port), subProtocol)
        .Subscribe(
          async request =>
          {
            using (var socket = request.WebSocket)
            {
              try
              {
                var message = await ReceiveMessageAsync(socket, cancel.Token);
                await SendMessageAsync("You sent \"" + message + "\"", socket, cancel.Token);
                await ReceiveCloseMessageAsync(socket, cancel.Token);
              }
              catch (OperationCanceledException)
              {
              }
            }
          },
          TraceError))
      using ((from _ in client.ConnectAsync(new Uri("ws://localhost:" + port), cancel.Token).ToObservable()
                .Do(_ => TraceLine(Environment.NewLine + "(Connected to host on sub-protocol \"{0}\")", client.SubProtocol))
              from message in userMessages.Where(m => m != null).Take(1)
              from __ in SendMessageAsync(message, client, cancel.Token).ToObservable()
              from response in ReceiveMessageAsync(client, cancel.Token).ToObservable()
                .Do(___ => client.CloseAsync(WebSocketCloseStatus.NormalClosure, "Done", cancel.Token))
              select response)
              .Subscribe(
                response => TraceLine("Response: {0}", response),
                TraceError,
                () => TraceLine("{0}: {1}", Text.Client, Text.Done)))
      {
        userMessages.OnNext(UserInput("{0}> ", Instructions.EnterAMessage));

        TraceStatus(Instructions.PressAnyKeyToCancel);

        WaitForKey();
      }
    }
开发者ID:ibebbs,项目名称:Rxx,代码行数:57,代码来源:WebSocketLab.cs

示例11: Search

        /// <summary>
        /// Starts the search. Pushes whenever the solver finds a solution.
        /// Cannot expost IObservable because it conflicts with FSharp.Core which contains the same type, 
        /// this conflict is why FoundOPS.SLClient.Algorithm is a seperate project.
        /// </summary>
        /// <param name="locationsToRoute">The locations to route</param>
        public BehaviorSubject<SolutionMessage<IList<IGeoLocation>>> Search(IList<IGeoLocation> locationsToRoute)
        {
            var foundSolution = new BehaviorSubject<SolutionMessage<IList<IGeoLocation>>>(null);

            _solver.FoundSolution += (s, e) => foundSolution.OnNext(e);

            var generator = new Func<Random, IList<IGeoLocation>>(random => Tsp.Shuffle(random, locationsToRoute));
            var mutator = new Func<IList<IGeoLocation>, Random, IList<IGeoLocation>>((solution, random) => Tsp.Swap(random, solution));
            var evaluator = new Func<IList<IGeoLocation>, double>(circuit => -Tsp.Length(circuit));
            var problem = new Problem<IList<IGeoLocation>>(generator, mutator, evaluator);
            _solver.Search(problem);

            return foundSolution;
        }
开发者ID:FoundOPS,项目名称:server,代码行数:20,代码来源:HiveRouteCalculator.cs

示例12: StickyItemShouldBeAddedWhenSelectionChangesFromNull

    public void StickyItemShouldBeAddedWhenSelectionChangesFromNull()
    {
        var source = CreateSource();
        var selection = new BehaviorSubject<Thing>(null);
        var stickie = new Thing();
        var target = source.CreateListenerCollection(stickie, selection);

        CollectionAssert.AreEqual(source, target);

        selection.OnNext(source[0]);

        var expected = new[] { stickie }.Concat(source);
        CollectionAssert.AreEqual(expected, target);
    }
开发者ID:github,项目名称:VisualStudio,代码行数:14,代码来源:ListenerCollectionTests.cs

示例13: Start

        private void Start()
        {
            //BehaviorSubjectは初期値を設定できる
            behaviorSubject = new BehaviorSubject<int>(0);

            /*
            OnNext → Subscribe と実行し、Subscribeした瞬間に直前の値が発行されることを確認しよう
            */

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

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

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

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

示例14: InitializesCanExecuteValueSourceAndSyncExecuteAction

        public void InitializesCanExecuteValueSourceAndSyncExecuteAction(
            object parameter)
        {
            var canExecuteSource = new BehaviorSubject<bool>(true);
            var functor = Mock.Of<IFunctor>();

            var command = ReactiveCommand.Create(
                canExecuteSource, p => functor.Action(p));
            command?.Execute(parameter);
            canExecuteSource.OnNext(false);

            command.Should().NotBeNull();
            command.CanExecute(parameter).Should().BeFalse();
            Mock.Get(functor).Verify(f => f.Action(parameter), Times.Once());
        }
开发者ID:helloimkaylee,项目名称:ReactiveMvvm,代码行数:15,代码来源:ReactiveCommandTest.cs

示例15: Produces_a_value_each_time_the_aggregate_availability_of_dependencies_changes

        public void Produces_a_value_each_time_the_aggregate_availability_of_dependencies_changes()
        {
            var dependency = new BehaviorSubject<bool>(false);
            var activator = new FeatureActivator(() => { }, dependsOn: dependency);

            var notifications = new List<bool>();

            disposables.Add(activator.Subscribe(notifications.Add));

            dependency.OnNext(false);
            dependency.OnNext(false);
            dependency.OnNext(true);
            dependency.OnNext(true);
            dependency.OnNext(true);
            dependency.OnNext(true);
            dependency.OnNext(false);
            dependency.OnNext(false);
            dependency.OnNext(false);

            Assert.That(notifications.IsSameSequenceAs(false, true, false));
        }
开发者ID:JayBazuzi,项目名称:Its.Configuration,代码行数:21,代码来源:FeatureActivatorTests.cs


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