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


C# BehaviorSubject类代码示例

本文整理汇总了C#中BehaviorSubject的典型用法代码示例。如果您正苦于以下问题:C# BehaviorSubject类的具体用法?C# BehaviorSubject怎么用?C# BehaviorSubject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: live_values_are_sent_through_scheduler

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

            BehaviorSubject<int> subject = new BehaviorSubject<int>(0, scheduler);

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

            subject.Subscribe(stats);

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

            Assert.IsFalse(stats.NextCalled);

            scheduler.RunNext();
            Assert.AreEqual(1, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0 }));
            Assert.IsFalse(stats.CompletedCalled);

            scheduler.RunNext();
            Assert.AreEqual(2, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0, 1 }));
            Assert.IsFalse(stats.CompletedCalled);

            scheduler.RunNext();
            Assert.AreEqual(3, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0, 1, 2 }));
            Assert.IsFalse(stats.CompletedCalled);

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

示例2: SharedThemeService

 public SharedThemeService(ResourceDictionary resourceDictionary)
 {
     _resourceDictionary = resourceDictionary;
     _themes = new BehaviorSubject<IEnumerable<ITheme>>(Enumerable.Empty<ITheme>());
     _activeTheme = new BehaviorSubject<ITheme>(null);
     _themesMap = new Dictionary<string, ITheme>();
 }
开发者ID:a-wall,项目名称:radar,代码行数:7,代码来源:SharedThemeService.cs

示例3: MainWindowViewModel

        public MainWindowViewModel()
        {
            var noneInFlight = new BehaviorSubject<bool>(false);
            var updateManager = default(UpdateManager);

            this.WhenAny(x => x.UpdatePath, x => x.Value)
                .Where(x => !String.IsNullOrWhiteSpace(x))
                .Throttle(TimeSpan.FromMilliseconds(700), RxApp.DeferredScheduler)
                .Subscribe(x => {
                    if (updateManager != null)  updateManager.Dispose();
                    updateManager = new UpdateManager(UpdatePath, "SampleUpdatingApp", FrameworkVersion.Net40);
                });

            CheckForUpdate = new ReactiveAsyncCommand(noneInFlight);
            CheckForUpdate.RegisterAsyncObservable(_ => updateManager.CheckForUpdate())
                .Subscribe(x => { UpdateInfo = x; DownloadedUpdateInfo = null; });

            DownloadReleases = new ReactiveAsyncCommand(noneInFlight.Where(_ => UpdateInfo != null));
            DownloadReleases.RegisterAsyncObservable(_ => updateManager.DownloadReleases(UpdateInfo.ReleasesToApply))
                .Subscribe(_ => DownloadedUpdateInfo = UpdateInfo);

            ApplyReleases = new ReactiveAsyncCommand(noneInFlight.Where(_ => DownloadedUpdateInfo != null));
            ApplyReleases.RegisterAsyncObservable(_ => updateManager.ApplyReleases(DownloadedUpdateInfo));

            Observable.CombineLatest(
                CheckForUpdate.ItemsInflight.StartWith(0),
                DownloadReleases.ItemsInflight.StartWith(0),
                ApplyReleases.ItemsInflight.StartWith(0),
                this.WhenAny(x => x.UpdatePath, _ => 0),
                (a, b, c, _) => a + b + c
            ).Select(x => x == 0 && UpdatePath != null).Multicast(noneInFlight).Connect();
        }
开发者ID:rzhw,项目名称:Squirrel.Windows,代码行数:32,代码来源:MainWindow.xaml.cs

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

示例5: MainMenu

        public MainMenu(Engine engine)
            : base(engine)
        {
            this.button1 = new MenuButton(this.Engine);
            this.button2 = new MenuButton(this.Engine);

            this.button1.Position = new Vector2(0, -40);
            this.button2.Position = new Vector2(0, 40);

            this.button1.Text = "new game";
            this.button2.Text = "high scores";

            this.button1.Color = new Color(0.3f, 0.3f, 0.3f);
            this.button2.Color = new Color(0.3f, 0.3f, 0.3f);

            button1.Action = () =>
                                 {
                                     this.Dispose();
                                     new NewGameMenu(this.Engine).Initialize().Attach();
                                 };

            button2.Action = () =>
                                 {
                                     this.Dispose();
                                     new HighScoreMenu(this.Engine).Initialize().Attach();
                                 };

            this.buttons.Add(button1);
            this.buttons.Add(button2);

            this.oldButton = new BehaviorSubject<MenuButton>(null);
            this.currentButton = new BehaviorSubject<MenuButton>(this.button1);
        }
开发者ID:HaKDMoDz,项目名称:shooter,代码行数:33,代码来源:MainMenu.cs

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

示例7: ExecutionContext

        public ExecutionContext(TimeSpan skipAhead = default(TimeSpan))
        {
            this.disposables = new CompositeDisposable();
            this.cancelRequested = new BehaviorSubject<bool>(false)
                .AddTo(this.disposables);
            this.progressDeltas = new Subject<TimeSpan>()
                .AddTo(this.disposables);

            this
                .cancelRequested
                .Where(x => x)
                .Subscribe(_ => this.IsCancelled = true)
                .AddTo(this.disposables);

            this
                .progressDeltas
                .Scan((running, next) => running + next)
                .Subscribe(x => this.Progress = x)
                .AddTo(this.disposables);

            this
                .WhenAnyValue(x => x.CurrentExercise)
                .Select(x => this.progressDeltas.StartWith(TimeSpan.Zero).Scan((running, next) => running + next))
                .Switch()
                .Subscribe(x => this.CurrentExerciseProgress = x)
                .AddTo(this.disposables);

            this
                .progressDeltas
                .StartWith(skipAhead)
                .Scan((running, next) => running - next)
                .Select(x => x < TimeSpan.Zero ? TimeSpan.Zero : x)
                .Subscribe(x => this.SkipAhead = x)
                .AddTo(this.disposables);
        }
开发者ID:gregjones60,项目名称:WorkoutWotch,代码行数:35,代码来源:ExecutionContext.cs

示例8: AudioPlayer

        internal AudioPlayer()
        {
            this.audioPlayerCallback = new DummyMediaPlayerCallback();
            this.videoPlayerCallback = new DummyMediaPlayerCallback();
            this.currentCallback = new DummyMediaPlayerCallback();

            this.finishSubscription = new SerialDisposable();
            this.gate = new SemaphoreSlim(1, 1);

            this.playbackState = new BehaviorSubject<AudioPlayerState>(AudioPlayerState.None);
            this.PlaybackState = this.playbackState.DistinctUntilChanged();

            this.loadedSong = new BehaviorSubject<Song>(null);
            this.TotalTime = this.loadedSong.Select(x => x == null ? TimeSpan.Zero : x.Duration);

            this.currentTimeChangedFromOuter = new Subject<TimeSpan>();

            var conn = Observable.Interval(TimeSpan.FromMilliseconds(300), RxApp.TaskpoolScheduler)
                .CombineLatest(this.PlaybackState, (l, state) => state)
                .Where(x => x == AudioPlayerState.Playing)
                .Select(_ => this.CurrentTime)
                .Merge(this.currentTimeChangedFromOuter)
                .DistinctUntilChanged(x => x.TotalSeconds)
                .Publish(TimeSpan.Zero);
            conn.Connect();
            this.CurrentTimeChanged = conn;
        }
开发者ID:hur1can3,项目名称:Espera,代码行数:27,代码来源:AudioPlayer.cs

示例9: AnalyticsEngine

        public AnalyticsEngine()
        {
            _currentPositionUpdatesDto = new PositionUpdatesDto();
            _updates = new BehaviorSubject<PositionUpdatesDto>(_currentPositionUpdatesDto);

            _eventLoopScheduler.SchedulePeriodic(TimeSpan.FromSeconds(10), PublishPositionReport);
        }
开发者ID:AdaptiveConsulting,项目名称:ReactiveTraderCloud,代码行数:7,代码来源:AnalyticsEngine.cs

示例10: Should_Produce_Value_On_Activator_True

        public async void Should_Produce_Value_On_Activator_True()
        {
            var activator = new BehaviorSubject<bool>(true);
            var target = new StyleBinding(activator, 1, string.Empty);
            var result = await target.Take(1);

            Assert.Equal(1, result);
        }
开发者ID:Arlorean,项目名称:Perspex,代码行数:8,代码来源:StyleBindingTests.cs

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

示例12: OnOffFeature

 protected OnOffFeature(bool @on)
 {
     availability = new BehaviorSubject<bool>(@on);
     activator = new FeatureActivator(
         Activate,
         Deactivate,
         availability);
 }
开发者ID:JayBazuzi,项目名称:Its.Configuration,代码行数:8,代码来源:OnOffFeature.cs

示例13: iCloudExerciseDocumentService

        public iCloudExerciseDocumentService(ILoggerService loggerService)
        {
            Ensure.ArgumentNotNull(loggerService, nameof(loggerService));

            this.logger = loggerService.GetLogger(this.GetType());
            this.exerciseDocument = new BehaviorSubject<string>(null);
            this.sync = new object();
        }
开发者ID:gregjones60,项目名称:WorkoutWotch,代码行数:8,代码来源:iCloudExerciseDocumentService.cs

示例14: Should_Produce_UnsetValue_On_Activator_False

        public async void Should_Produce_UnsetValue_On_Activator_False()
        {
            var activator = new BehaviorSubject<bool>(false);
            var target = new StyleBinding(activator, 1, string.Empty);
            var result = await target.Take(1);

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

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


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