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


C# IObservable.Delay方法代码示例

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


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

示例1: ModificationViewModel

        public ModificationViewModel(IScreen screen, ICredentialStore store, IObservable<RepositoryModel> repository)
        {
            this.disposables = new List<IDisposable>();
            this.fileSystem = new FileSystemObservable();

            this.refreshCommand = ReactiveCommand.Create();

            var samples =
                Observable.Interval(TimeSpan.FromSeconds(60))
                .Select(i => new object())
                .Merge(this.refreshCommand.Select(i => new object()))
                .Merge(repository.Delay(TimeSpan.FromSeconds(1)).Select(i => new object()));

            var distinctRepository = repository.DistinctUntilChanged(r => r.Path);

            distinctRepository.MapToMember(this, vm => vm.currentRepositoryModel);
            distinctRepository.Select(_ => _.Path).MapToMember(this, vm => vm.fileSystem.Path);

            var activeBranch = repository
                .SelectMany(rm => rm.WhenAny(vm => vm.CurrentBranch, change => change.GetValue()))
                .SampleEx(samples);

            activeBranch
                .ObserveOn(System.Reactive.Concurrency.TaskPoolScheduler.Default)
                .SubscribeOn(System.Reactive.Concurrency.TaskPoolScheduler.Default)
                .Subscribe(branch =>
                {
                    if (branch.IsTracking)
                    {
                        //Fetch repository status.
                        var currentRemote = branch.Remote;

                        var refSpecs = this.currentRepositoryModel.Repository.Network.Remotes.Select(r =>
                                    new
                                    {
                                        FetchRefSpecs = r.FetchRefSpecs
                                                            .Where(frs => frs.Direction == RefSpecDirection.Fetch)
                                                            .Select(frs => frs.Specification),
                                        Remote = r
                                    }
                                );
                        var credentialProvider = new CredentialProvider(screen, store);

                        foreach (var item in refSpecs)
                        {
                            FetchOptions options = new FetchOptions() { CredentialsProvider = credentialProvider.CredentialHandler };
                            try
                            {
                                this.currentRepositoryModel.Repository.Network.Fetch(item.Remote, item.FetchRefSpecs, options);
                            }
                            catch { }
                        }
                    }
                });

            activeBranch
                .Select(b => b.TrackingDetails).Subscribe(_ =>
                {
                    this.Ahead = (_.AheadBy.HasValue) ? _.AheadBy.Value : 0;
                    this.Behind = (_.BehindBy.HasValue) ? _.BehindBy.Value : 0;
                });

            var activeBranchFileStatus =
                activeBranch.AnonymousMerge(fileSystem, 0)
                .AnonymousMerge(this.refreshCommand.AsObservable(), 0)
                .Throttle(TimeSpan.FromSeconds(5))
                .Select(branch =>
                {
                    var opts = new LibGit2Sharp.StatusOptions();

                    opts.DetectRenamesInIndex = true;
                    opts.DetectRenamesInWorkDir = true;
                    opts.Show = StatusShowOption.IndexAndWorkDir;

                    return this.currentRepositoryModel.Repository.RetrieveStatus(opts);
                });

            this.files = new DeltaViewModel<int>
            (
                activeBranchFileStatus.Select(s => s.Modified.Count()),
                activeBranchFileStatus.Select(s => s.Added.Count() + s.Untracked.Count()),
                activeBranchFileStatus.Select(s => s.Removed.Count())
            );

            ConfigureLineChanges(activeBranch);

            ConfigureCommitCommands();

            this.thresholds = new Thresholds(
                this.ObservableForProperty(vm => vm.Behind, false, false).Select(change => change.GetValue()),
                this.ObservableForProperty(vm => vm.Ahead).Select(change => change.GetValue()),
                this.ObservableForProperty(vm => vm.LinesAdded).Select(change => change.GetValue()),
                this.ObservableForProperty(vm => vm.LinesRemoved).Select(change => change.GetValue()),
                this.Files.ObservableForProperty(vm => vm.Added).Select(change => change.GetValue()),
                this.Files.ObservableForProperty(vm => vm.Removed).Select(change => change.GetValue()));
        }
开发者ID:abbottdev,项目名称:gitreminder,代码行数:96,代码来源:ModificationViewModel.cs


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