當前位置: 首頁>>代碼示例>>C#>>正文


C# BehaviorSubject.Skip方法代碼示例

本文整理匯總了C#中BehaviorSubject.Skip方法的典型用法代碼示例。如果您正苦於以下問題:C# BehaviorSubject.Skip方法的具體用法?C# BehaviorSubject.Skip怎麽用?C# BehaviorSubject.Skip使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BehaviorSubject的用法示例。


在下文中一共展示了BehaviorSubject.Skip方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

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

示例2: ReactiveCommand

        /// <summary>
        /// Initializes a new instance of the <see cref="ReactiveCommand"/> class.
        /// </summary>
        /// <param name="canExecute">if set to <c>true</c> [can execute].</param>
        public ReactiveCommand(bool canExecute = false)
		{
			_canExecuteSource = new BehaviorSubject<bool>(canExecute);
			_canExecuteSource
				.Zip(_canExecuteSource.Skip(1),
					(x, y) =>
						x != y)
				.Where(x =>
					x && CanExecuteChanged != null)
				.Subscribe(_ =>
					CanExecuteChanged(this, EventArgs.Empty));


			_executeSource = new Subject<EventPattern<EventCommandEventArgs>>();
		}
開發者ID:waynebaby,項目名稱:MVVM-Sidekick,代碼行數:19,代碼來源:ReactiveCommand.cs


注:本文中的BehaviorSubject.Skip方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。