Example #1
0
        static RepositoryCloneViewModel CreateTarget(
            IOperatingSystem os = null,
            IConnectionManager connectionManager     = null,
            IRepositoryCloneService service          = null,
            IUsageService usageService               = null,
            IUsageTracker usageTracker               = null,
            IRepositorySelectViewModel gitHubTab     = null,
            IRepositorySelectViewModel enterpriseTab = null,
            IGitService gitService         = null,
            IRepositoryUrlViewModel urlTab = null,
            string defaultClonePath        = defaultPath)
        {
            os = os ?? Substitute.For <IOperatingSystem>();
            connectionManager = connectionManager ?? CreateConnectionManager("https://github.com");
            service           = service ?? CreateRepositoryCloneService(defaultClonePath);
            usageService      = usageService ?? CreateUsageService();
            usageTracker      = usageTracker ?? Substitute.For <IUsageTracker>();
            gitHubTab         = gitHubTab ?? CreateSelectViewModel();
            enterpriseTab     = enterpriseTab ?? CreateSelectViewModel();
            gitService        = gitService ?? CreateGitService(true, "https://github.com/owner/repo");
            urlTab            = urlTab ?? CreateRepositoryUrlViewModel();

            return(new RepositoryCloneViewModel(
                       os,
                       connectionManager,
                       service,
                       gitService,
                       usageService,
                       usageTracker,
                       gitHubTab,
                       enterpriseTab,
                       urlTab));
        }
Example #2
0
        public RepositoryCloneViewModel(
            IOperatingSystem os,
            IConnectionManager connectionManager,
            IRepositoryCloneService service,
            IGitService gitService,
            IUsageTracker usageTracker,
            IDialogService dialogService,
            IRepositorySelectViewModel gitHubTab,
            IRepositorySelectViewModel enterpriseTab)
        {
            this.os = os;
            this.connectionManager = connectionManager;
            this.service           = service;
            this.gitService        = gitService;
            this.usageTracker      = usageTracker;
            this.dialogService     = dialogService;

            GitHubTab     = gitHubTab;
            EnterpriseTab = enterpriseTab;
            tabs          = new IRepositoryCloneTabViewModel[] { GitHubTab, EnterpriseTab };

            var repository = this.WhenAnyValue(x => x.SelectedTabIndex)
                             .SelectMany(x => tabs[x].WhenAnyValue(tab => tab.Repository));

            Path = service.DefaultClonePath;
            repository.Subscribe(x => UpdatePath(x));

            pathWarning = Observable.CombineLatest(
                repository,
                this.WhenAnyValue(x => x.Path),
                ValidatePathWarning)
                          .ToProperty(this, x => x.PathWarning);

            var canClone = Observable.CombineLatest(
                repository, this.WhenAnyValue(x => x.Path),
                (repo, path) => repo != null && !service.DestinationFileExists(path) &&
                (!service.DestinationDirectoryExists(path) || service.DestinationDirectoryEmpty(path)));

            var canOpen = Observable.CombineLatest(
                repository, this.WhenAnyValue(x => x.Path),
                (repo, path) => repo != null && !service.DestinationFileExists(path) && service.DestinationDirectoryExists(path) &&
                !service.DestinationDirectoryEmpty(path));

            Browse = ReactiveCommand.Create(() => BrowseForDirectory());
            Clone  = ReactiveCommand.CreateFromObservable(
                () => repository.Select(x => new CloneDialogResult(Path, x?.CloneUrl)),
                canClone);
            Open = ReactiveCommand.CreateFromObservable(
                () => repository.Select(x => new CloneDialogResult(Path, x?.CloneUrl)),
                canOpen);

            LoginAsDifferentUser = ReactiveCommand.CreateFromTask(LoginAsDifferentUserAsync);
        }
Example #3
0
        public RepositoryCloneViewModel(
            IOperatingSystem os,
            IConnectionManager connectionManager,
            IRepositoryCloneService service,
            IUsageService usageService,
            IUsageTracker usageTracker,
            IRepositorySelectViewModel gitHubTab,
            IRepositorySelectViewModel enterpriseTab,
            IRepositoryUrlViewModel urlTab)
        {
            this.os = os;
            this.connectionManager = connectionManager;
            this.service           = service;
            this.usageService      = usageService;
            this.usageTracker      = usageTracker;

            GitHubTab     = gitHubTab;
            EnterpriseTab = enterpriseTab;
            UrlTab        = urlTab;
            tabs          = new IRepositoryCloneTabViewModel[] { GitHubTab, EnterpriseTab, UrlTab };

            var repository = this.WhenAnyValue(x => x.SelectedTabIndex)
                             .SelectMany(x => tabs[x].WhenAnyValue(tab => tab.Repository));

            Path = service.DefaultClonePath;
            repository.Subscribe(x => UpdatePath(x));

            pathError = Observable.CombineLatest(
                repository,
                this.WhenAnyValue(x => x.Path),
                ValidatePath)
                        .ToProperty(this, x => x.PathError);

            var canClone = Observable.CombineLatest(
                repository,
                this.WhenAnyValue(x => x.PathError),
                (repo, error) => (repo, error))
                           .Select(x => x.repo != null && x.error == null);

            Browse = ReactiveCommand.Create().OnExecuteCompleted(_ => BrowseForDirectory());
            Clone  = ReactiveCommand.CreateAsyncObservable(
                canClone,
                _ => repository.Select(x => new CloneDialogResult(Path, x)));
        }
Example #4
0
        static RepositoryCloneViewModel CreateTarget(
            IOperatingSystem os = null,
            IConnectionManager connectionManager     = null,
            IRepositoryCloneService service          = null,
            IRepositorySelectViewModel gitHubTab     = null,
            IRepositorySelectViewModel enterpriseTab = null,
            IRepositoryUrlViewModel urlTab           = null)
        {
            os = os ?? Substitute.For <IOperatingSystem>();
            connectionManager = connectionManager ?? CreateConnectionManager("https://github.com");
            service           = service ?? CreateRepositoryCloneService();
            gitHubTab         = gitHubTab ?? CreateSelectViewModel();
            enterpriseTab     = enterpriseTab ?? CreateSelectViewModel();
            urlTab            = urlTab ?? Substitute.For <IRepositoryUrlViewModel>();

            return(new RepositoryCloneViewModel(
                       os,
                       connectionManager,
                       service,
                       gitHubTab,
                       enterpriseTab,
                       urlTab));
        }