public async Task CanCloneARepository() { using (var directory = TestDirectory.Create()) { var cloneObserver = new ReplaySubject <Tuple <string, int> >(); using (await ObservableRepository.Clone( "https://github.com/shiftkey/rxui-design-guidelines.git", directory.Path, cloneObserver)) { Assert.NotEmpty(Directory.GetFiles(directory.Path)); var progressList = await cloneObserver.Select(x => x.Item2).ToList(); Assert.Equal(100, progressList.Last()); } } }
public CloneRepositoryViewModel(string cloneUrl, string localDirectory) { IsEmpty = true; Branches = new ReactiveList <BranchViewModel>(); // omg this hack sucks Progress = new ReplaySubject <Tuple <string, int> >(); var anyProgress = this.WhenAnyObservable(x => x.Progress); progressText = anyProgress.Select(x => x.Item1) .ToProperty(this, x => x.ProgressText, scheduler: RxApp.MainThreadScheduler); progressValue = anyProgress.Select(x => x.Item2) .ToProperty(this, x => x.ProgressValue, scheduler: RxApp.MainThreadScheduler); Clone = ReactiveCommand.CreateAsyncObservable(_ => { Progress = new ReplaySubject <Tuple <string, int> >(); return(ObservableRepository.Clone(cloneUrl, localDirectory, Progress)); }); isCloningObs = Clone.IsExecuting.ToProperty(this, x => x.IsCloning); Clone.Subscribe(_ => { IsEmpty = false; }); repositoryObs = Clone.ToProperty(this, x => x.Repository); this.WhenAnyValue(x => x.Repository) .Where(x => x != null) .Subscribe(RefreshBranches); Checkout = ReactiveCommand.CreateAsyncObservable( this.WhenAny(x => x.SelectedBranch, x => x != null), _ => { Progress = new ReplaySubject <Tuple <string, int> >(); var branch = Repository.Inner.Branches[SelectedBranch.Name]; return(Repository.Checkout(branch, Progress)); }); Checkout.Subscribe(_ => RefreshBranches(Repository)); }