Ejemplo n.º 1
0
 public static IObservable <bool> IsLoggedIn(this IConnectionManager cm, IRepositoryHosts hosts, HostAddress address)
 {
     return(cm.Connections.ToObservable()
            .Where(c => c.HostAddress.Equals(address))
            .SelectMany(c => c.Login())
            .Any(c => hosts.LookupHost(c.HostAddress).IsLoggedIn));
 }
 public static IObservable<bool> IsLoggedIn(this IConnectionManager cm, IRepositoryHosts hosts, HostAddress address)
 {
     return cm.Connections.ToObservable()
             .Where(c => c.HostAddress.Equals(address))
             .SelectMany(c => c.Login())
             .Any(c => hosts.LookupHost(c.HostAddress).IsLoggedIn);
 }
Ejemplo n.º 3
0
        public LoginControlViewModel(
            IRepositoryHosts hosts,
            ILoginToGitHubViewModel loginToGitHubViewModel,
            ILoginToGitHubForEnterpriseViewModel loginToGitHubEnterpriseViewModel)
        {
            Title = Resources.LoginTitle;
            RepositoryHosts = hosts;
            GitHubLogin = loginToGitHubViewModel;
            EnterpriseLogin = loginToGitHubEnterpriseViewModel;

            isLoginInProgress = this.WhenAny(
                x => x.GitHubLogin.IsLoggingIn,
                x => x.EnterpriseLogin.IsLoggingIn,
                (x, y) => x.Value || y.Value
            ).ToProperty(this, vm => vm.IsLoginInProgress);

            loginMode = this.WhenAny(
                x => x.RepositoryHosts.GitHubHost.IsLoggedIn,
                x => x.RepositoryHosts.EnterpriseHost.IsLoggedIn,
                (x, y) =>
                {
                    var canLogInToGitHub = x.Value == false;
                    var canLogInToEnterprise = y.Value == false;

                    return canLogInToGitHub && canLogInToEnterprise ? LoginMode.DotComOrEnterprise
                        : canLogInToGitHub ? LoginMode.DotComOnly
                        : canLogInToEnterprise ? LoginMode.EnterpriseOnly
                        : LoginMode.None;

                }).ToProperty(this, x => x.LoginMode);

            AuthenticationResults = Observable.Merge(
                loginToGitHubViewModel.Login,
                EnterpriseLogin.Login);
        }
Ejemplo n.º 4
0
 public static IObservable <bool> IsLoggedIn(this IConnectionManager cm, IRepositoryHosts hosts)
 {
     Guard.ArgumentNotNull(hosts, nameof(hosts));
     return(cm.Connections.ToObservable()
            .SelectMany(c => c.Login())
            .Any(c => hosts.LookupHost(c.HostAddress).IsLoggedIn));
 }
        public LoginControlViewModel(
            IRepositoryHosts hosts,
            ILoginToGitHubViewModel loginToGitHubViewModel,
            ILoginToGitHubForEnterpriseViewModel loginToGitHubEnterpriseViewModel)
        {
            Title           = Resources.LoginTitle;
            RepositoryHosts = hosts;
            GitHubLogin     = loginToGitHubViewModel;
            EnterpriseLogin = loginToGitHubEnterpriseViewModel;

            isLoginInProgress = this.WhenAny(
                x => x.GitHubLogin.IsLoggingIn,
                x => x.EnterpriseLogin.IsLoggingIn,
                (x, y) => x.Value || y.Value
                ).ToProperty(this, vm => vm.IsLoginInProgress);

            loginMode = this.WhenAny(
                x => x.RepositoryHosts.GitHubHost.IsLoggedIn,
                x => x.RepositoryHosts.EnterpriseHost.IsLoggedIn,
                (x, y) =>
            {
                var canLogInToGitHub     = x.Value == false;
                var canLogInToEnterprise = y.Value == false;

                return(canLogInToGitHub && canLogInToEnterprise ? LoginMode.DotComOrEnterprise
                        : canLogInToGitHub?LoginMode.DotComOnly
                       : canLogInToEnterprise ? LoginMode.EnterpriseOnly
                        : LoginMode.None);
            }).ToProperty(this, x => x.LoginMode);

            AuthenticationResults = Observable.Amb(
                loginToGitHubViewModel.Login,
                EnterpriseLogin.Login);
            CancelCommand = ReactiveCommand.Create();
        }
 public static IObservable<IConnection> GetLoggedInConnections(this IConnectionManager cm, IRepositoryHosts hosts)
 {
     Guard.ArgumentNotNull(hosts, nameof(hosts));
     return cm.Connections.ToObservable()
             .SelectMany(c => c.Login())
             .Where(c => hosts.LookupHost(c.HostAddress).IsLoggedIn);
 }
Ejemplo n.º 7
0
        public UIController(IUIProvider uiProvider, IRepositoryHosts hosts, IUIFactory factory,
                            IConnectionManager connectionManager)
        {
            this.factory           = factory;
            this.uiProvider        = uiProvider;
            this.hosts             = hosts;
            this.connectionManager = connectionManager;
            uiObjects = new Dictionary <UIControllerFlow, Dictionary <UIViewType, IUIPair> >();

#if DEBUG
            if (Application.Current != null && !Splat.ModeDetector.InUnitTestRunner())
            {
                var waitDispatcher = RxApp.MainThreadScheduler as WaitForDispatcherScheduler;
                if (waitDispatcher != null)
                {
                    Debug.Assert(DispatcherScheduler.Current.Dispatcher == Application.Current.Dispatcher,
                                 "DispatcherScheduler is set correctly");
                }
                else
                {
                    Debug.Assert(((DispatcherScheduler)RxApp.MainThreadScheduler).Dispatcher == Application.Current.Dispatcher,
                                 "The MainThreadScheduler is using the wrong dispatcher");
                }
            }
#endif
            machines = new Dictionary <UIControllerFlow, StateMachine <UIViewType, Trigger> >();
            ConfigureLogicStates();

            uiStateMachine = new StateMachineType(UIViewType.None);
            triggers       = new Dictionary <Trigger, StateMachineType.TriggerWithParameters <ViewWithData> >();
            ConfigureUIHandlingStates();
        }
Ejemplo n.º 8
0
        public GitHubPaneViewModel(IGitHubServiceProvider serviceProvider,
                                   ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder,
                                   IConnectionManager cm, IRepositoryHosts hosts, IUIProvider uiProvider, IVisualStudioBrowser vsBrowser,
                                   IUsageTracker usageTracker)
            : base(serviceProvider, apiFactory, holder)
        {
            Guard.ArgumentNotNull(serviceProvider, nameof(serviceProvider));
            Guard.ArgumentNotNull(apiFactory, nameof(apiFactory));
            Guard.ArgumentNotNull(holder, nameof(holder));
            Guard.ArgumentNotNull(cm, nameof(cm));
            Guard.ArgumentNotNull(hosts, nameof(hosts));
            Guard.ArgumentNotNull(uiProvider, nameof(uiProvider));
            Guard.ArgumentNotNull(vsBrowser, nameof(vsBrowser));
            Guard.ArgumentNotNull(usageTracker, nameof(usageTracker));

            this.connectionManager = cm;
            this.hosts             = hosts;
            this.uiProvider        = uiProvider;
            this.usageTracker      = usageTracker;

            CancelCommand = ReactiveCommand.Create();
            Title         = "GitHub";
            Message       = String.Empty;
            browser       = vsBrowser;

            this.WhenAnyValue(x => x.Control.DataContext)
            .OfType <IPanePageViewModel>()
            .Select(x => x.WhenAnyValue(y => y.Title))
            .Switch()
            .Subscribe(x => Title = x ?? "GitHub");
        }
Ejemplo n.º 9
0
        public UIController(IGitHubServiceProvider gitHubServiceProvider,
                            IRepositoryHosts hosts, IUIFactory factory,
                            IConnectionManager connectionManager)
        {
            this.factory = factory;
            this.gitHubServiceProvider = gitHubServiceProvider;
            this.hosts             = hosts;
            this.connectionManager = connectionManager;

#if DEBUG
            if (Application.Current != null && !Splat.ModeDetector.InUnitTestRunner())
            {
                var waitDispatcher = RxApp.MainThreadScheduler as WaitForDispatcherScheduler;
                if (waitDispatcher != null)
                {
                    Debug.Assert(DispatcherScheduler.Current.Dispatcher == Application.Current.Dispatcher,
                                 "DispatcherScheduler is set correctly");
                }
                else
                {
                    Debug.Assert(((DispatcherScheduler)RxApp.MainThreadScheduler).Dispatcher == Application.Current.Dispatcher,
                                 "The MainThreadScheduler is using the wrong dispatcher");
                }
            }
#endif
            ConfigureLogicStates();

            uiStateMachine = new StateMachineType(UIViewType.None);

            ConfigureUIHandlingStates();
        }
 public EnsureLoggedInSection(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder,
     IConnectionManager cm, IRepositoryHosts hosts, IVSServices vsServices)
     : base(apiFactory, holder, cm)
 {
     IsVisible = false;
     this.hosts = hosts;
     this.vsServices = vsServices;
 }
Ejemplo n.º 11
0
 public EnsureLoggedInSection(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder,
                              IConnectionManager cm, IRepositoryHosts hosts, ITeamExplorerServices teServices)
     : base(apiFactory, holder, cm)
 {
     IsVisible       = false;
     this.hosts      = hosts;
     this.teServices = teServices;
 }
Ejemplo n.º 12
0
        public LogoutRequiredViewModel(IRepositoryHosts repositoryHosts, INotificationService notificationService)
        {
            this.repositoryHosts = repositoryHosts;
            this.notificationService = notificationService;

            Title = Resources.LogoutRequiredTitle;
            Logout = ReactiveCommand.CreateAsyncObservable(OnLogout);
            Icon = Octicon.mark_github;
        }
Ejemplo n.º 13
0
        public LogoutRequiredViewModel(IRepositoryHosts repositoryHosts, INotificationService notificationService)
        {
            this.repositoryHosts     = repositoryHosts;
            this.notificationService = notificationService;

            Title  = Resources.LogoutRequiredTitle;
            Logout = ReactiveCommand.CreateAsyncObservable(OnLogout);
            Icon   = Octicon.mark_github;
        }
Ejemplo n.º 14
0
        protected LoginTabViewModel(IRepositoryHosts repositoryHosts, IVisualStudioBrowser browser)
        {
            Guard.ArgumentNotNull(repositoryHosts, nameof(repositoryHosts));
            Guard.ArgumentNotNull(browser, nameof(browser));

            RepositoryHosts = repositoryHosts;

            UsernameOrEmailValidator = ReactivePropertyValidator.For(this, x => x.UsernameOrEmail)
                                       .IfNullOrEmpty(Resources.UsernameOrEmailValidatorEmpty)
                                       .IfMatch(@"\s", Resources.UsernameOrEmailValidatorSpaces);

            PasswordValidator = ReactivePropertyValidator.For(this, x => x.Password)
                                .IfNullOrEmpty(Resources.PasswordValidatorEmpty);

            canLogin = this.WhenAny(
                x => x.UsernameOrEmailValidator.ValidationResult.IsValid,
                x => x.PasswordValidator.ValidationResult.IsValid,
                (x, y) => x.Value && y.Value).ToProperty(this, x => x.CanLogin);

            Login = ReactiveCommand.CreateAsyncObservable(this.WhenAny(x => x.CanLogin, x => x.Value), LogIn);

            Login.ThrownExceptions.Subscribe(ex =>
            {
                if (ex.IsCriticalException())
                {
                    return;
                }

                log.Info(string.Format(CultureInfo.InvariantCulture, "Error logging into '{0}' as '{1}'", BaseUri, UsernameOrEmail), ex);

                if (ex is Octokit.ForbiddenException)
                {
                    Error = new UserError(Resources.LoginFailedForbiddenMessage, ex.Message);
                }
                else
                {
                    Error = new UserError(ex.Message);
                }
            });

            isLoggingIn = Login.IsExecuting.ToProperty(this, x => x.IsLoggingIn);

            Reset = ReactiveCommand.CreateAsyncTask(_ => Clear());

            NavigateForgotPassword = new RecoveryCommand(Resources.ForgotPasswordLink, _ =>
            {
                browser.OpenUrl(new Uri(BaseUri, GitHubUrls.ForgotPasswordPath));
                return(RecoveryOptionResult.RetryOperation);
            });

            SignUp = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(GitHubUrls.Plans);
                return(Observable.Return(Unit.Default));
            });
        }
Ejemplo n.º 15
0
 public GitHubPaneViewModel(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder,
                            IConnectionManager cm, IRepositoryHosts hosts)
     : base(apiFactory, holder)
 {
     this.connectionManager = cm;
     this.hosts             = hosts;
     syncContext            = SynchronizationContext.Current;
     CancelCommand          = ReactiveCommand.Create();
     Title = "GitHub";
 }
Ejemplo n.º 16
0
        protected IConnection SetupConnection(IServiceProvider provider, IRepositoryHosts hosts,
                                              IRepositoryHost host)
        {
            var connection = provider.GetConnection();

            connection.Login().Returns(Observable.Return(connection));
            hosts.LookupHost(connection.HostAddress).Returns(host);
            host.IsLoggedIn.Returns(true);
            return(connection);
        }
Ejemplo n.º 17
0
        protected LoginTabViewModel(IRepositoryHosts repositoryHosts, IVisualStudioBrowser browser)
        {
            RepositoryHosts = repositoryHosts;

            UsernameOrEmailValidator = ReactivePropertyValidator.For(this, x => x.UsernameOrEmail)
                                       .IfNullOrEmpty("Please enter your username or email address")
                                       .IfMatch(@"\s", "Username or email address must not have spaces");

            PasswordValidator = ReactivePropertyValidator.For(this, x => x.Password)
                                .IfNullOrEmpty("Please enter your password");

            canLogin = this.WhenAny(
                x => x.UsernameOrEmailValidator.ValidationResult.IsValid,
                x => x.PasswordValidator.ValidationResult.IsValid,
                (x, y) => x.Value && y.Value).ToProperty(this, x => x.CanLogin);

            Login = ReactiveCommand.CreateAsyncObservable(this.WhenAny(x => x.CanLogin, x => x.Value), LogIn);

            Login.ThrownExceptions.Subscribe(ex =>
            {
                if (ex.IsCriticalException())
                {
                    return;
                }

                log.Info(string.Format(CultureInfo.InvariantCulture, "Error logging into '{0}' as '{1}'", BaseUri,
                                       UsernameOrEmail), ex);
                if (ex is Octokit.ForbiddenException)
                {
                    ShowLogInFailedError = true;
                    LoginFailedMessage   = "Make sure to use your password and not a Personal Access token to log in.";
                }
                else
                {
                    ShowConnectingToHostFailed = true;
                }
            });

            isLoggingIn = Login.IsExecuting.ToProperty(this, x => x.IsLoggingIn);

            Reset = ReactiveCommand.CreateAsyncTask(_ => Clear());

            NavigateForgotPassword = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(new Uri(BaseUri, GitHubUrls.ForgotPasswordPath));
                return(Observable.Return(Unit.Default));
            });

            SignUp = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(GitHubUrls.Plans);
                return(Observable.Return(Unit.Default));
            });
        }
        public LoginToGitHubViewModel(IRepositoryHosts repositoryHosts, IVisualStudioBrowser browser)
            : base(repositoryHosts, browser)
        {
            BaseUri = HostAddress.GitHubDotComHostAddress.WebUri;

            NavigatePricing = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(GitHubUrls.Pricing);
                return(Observable.Return(Unit.Default));
            });
        }
 public static IRepositoryPublishViewModel GetViewModel(
     IRepositoryHosts hosts = null,
     IRepositoryPublishService service = null,
     IVSServices vsServices = null,
     IConnectionManager connectionManager = null)
 {
     hosts = hosts ?? Substitutes.RepositoryHosts;
     service = service ?? Substitute.For<IRepositoryPublishService>();
     vsServices = vsServices ?? Substitute.For<IVSServices>();
     connectionManager = connectionManager ?? Substitutes.ConnectionManager;
     return new RepositoryPublishViewModel(hosts, service, vsServices, connectionManager);
 }
Ejemplo n.º 20
0
 public static IRepositoryPublishViewModel GetViewModel(
     IRepositoryHosts hosts               = null,
     IRepositoryPublishService service    = null,
     IVSServices vsServices               = null,
     IConnectionManager connectionManager = null)
 {
     hosts             = hosts ?? Substitutes.RepositoryHosts;
     service           = service ?? Substitute.For <IRepositoryPublishService>();
     vsServices        = vsServices ?? Substitute.For <IVSServices>();
     connectionManager = connectionManager ?? Substitutes.ConnectionManager;
     return(new RepositoryPublishViewModel(hosts, service, vsServices, connectionManager));
 }
        public LoginToGitHubViewModel(IRepositoryHosts repositoryHosts, IVisualStudioBrowser browser)
            : base(repositoryHosts, browser)
        {
            baseUri = HostAddress.GitHubDotComHostAddress.WebUri;

            NavigatePricing = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(GitHubUrls.Pricing);
                return Observable.Return(Unit.Default);

            });
        }
 public static IRepositoryPublishViewModel GetViewModel(
     IRepositoryHosts hosts = null,
     IRepositoryPublishService service = null,
     INotificationService notificationService = null,
     IConnectionManager connectionManager = null)
 {
     hosts = hosts ?? Substitutes.RepositoryHosts;
     service = service ?? Substitute.For<IRepositoryPublishService>();
     notificationService = notificationService ?? Substitute.For<INotificationService>();
     connectionManager = connectionManager ?? Substitutes.ConnectionManager;
     return new RepositoryPublishViewModel(hosts, service, notificationService, connectionManager);
 }
 public static IRepositoryPublishViewModel GetViewModel(
     IRepositoryHosts hosts                   = null,
     IRepositoryPublishService service        = null,
     INotificationService notificationService = null,
     IConnectionManager connectionManager     = null)
 {
     hosts               = hosts ?? Substitutes.RepositoryHosts;
     service             = service ?? Substitute.For <IRepositoryPublishService>();
     notificationService = notificationService ?? Substitute.For <INotificationService>();
     connectionManager   = connectionManager ?? Substitutes.ConnectionManager;
     return(new RepositoryPublishViewModel(hosts, service, notificationService, connectionManager));
 }
Ejemplo n.º 24
0
        protected LoginTabViewModel(IRepositoryHosts repositoryHosts, IVisualStudioBrowser browser)
        {
            RepositoryHosts = repositoryHosts;

            UsernameOrEmailValidator = ReactivePropertyValidator.For(this, x => x.UsernameOrEmail)
                .IfNullOrEmpty("Please enter your username or email address")
                .IfMatch(@"\s", "Username or email address must not have spaces");

            PasswordValidator = ReactivePropertyValidator.For(this, x => x.Password)
                .IfNullOrEmpty("Please enter your password");

            canLogin = this.WhenAny(
                x => x.UsernameOrEmailValidator.ValidationResult.IsValid,
                x => x.PasswordValidator.ValidationResult.IsValid,
                (x, y) => x.Value && y.Value).ToProperty(this, x => x.CanLogin);

            Login = ReactiveCommand.CreateAsyncObservable(this.WhenAny(x => x.CanLogin, x => x.Value), LogIn);

            Login.ThrownExceptions.Subscribe(ex =>
            {
                if (ex.IsCriticalException()) return;

                log.Info(string.Format(CultureInfo.InvariantCulture, "Error logging into '{0}' as '{1}'", BaseUri,
                    UsernameOrEmail), ex);
                if (ex is Octokit.ForbiddenException)
                {
                    ShowLogInFailedError = true;
                    LoginFailedMessage = "Make sure to use your password and not a Personal Access token to log in.";
                }
                else
                {
                    ShowConnectingToHostFailed = true;
                }
            });

            isLoggingIn = Login.IsExecuting.ToProperty(this, x => x.IsLoggingIn);

            Reset = ReactiveCommand.CreateAsyncTask(_ => Clear());

            NavigateForgotPassword = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(new Uri(BaseUri, GitHubUrls.ForgotPasswordPath));
                return Observable.Return(Unit.Default);
            });

            SignUp = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(GitHubUrls.Plans);
                return Observable.Return(Unit.Default);
            });
        }
Ejemplo n.º 25
0
        protected LoginTabViewModel(IRepositoryHosts repositoryHosts, IVisualStudioBrowser browser)
        {
            RepositoryHosts = repositoryHosts;

            UsernameOrEmailValidator = ReactivePropertyValidator.For(this, x => x.UsernameOrEmail)
                .IfNullOrEmpty(Resources.UsernameOrEmailValidatorEmpty)
                .IfMatch(@"\s", Resources.UsernameOrEmailValidatorSpaces);

            PasswordValidator = ReactivePropertyValidator.For(this, x => x.Password)
                .IfNullOrEmpty(Resources.PasswordValidatorEmpty);

            canLogin = this.WhenAny(
                x => x.UsernameOrEmailValidator.ValidationResult.IsValid,
                x => x.PasswordValidator.ValidationResult.IsValid,
                (x, y) => x.Value && y.Value).ToProperty(this, x => x.CanLogin);

            Login = ReactiveCommand.CreateAsyncObservable(this.WhenAny(x => x.CanLogin, x => x.Value), LogIn);

            Login.ThrownExceptions.Subscribe(ex =>
            {
                if (ex.IsCriticalException()) return;

                log.Info(string.Format(CultureInfo.InvariantCulture, "Error logging into '{0}' as '{1}'", BaseUri, UsernameOrEmail), ex);
                if (ex is Octokit.ForbiddenException)
                {
                    UserError.Throw(new UserError(Resources.LoginFailedForbiddenMessage));
                }
                else
                {
                    UserError.Throw(new UserError(ex.Message));
                }
            });

            isLoggingIn = Login.IsExecuting.ToProperty(this, x => x.IsLoggingIn);

            Reset = ReactiveCommand.CreateAsyncTask(_ => Clear());

            NavigateForgotPassword = new RecoveryCommand(Resources.ForgotPasswordLink, _ =>
            {
                browser.OpenUrl(new Uri(BaseUri, GitHubUrls.ForgotPasswordPath));
                return RecoveryOptionResult.RetryOperation;
            });

            SignUp = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(GitHubUrls.Plans);
                return Observable.Return(Unit.Default);
            });
        }
        public PullRequestSessionManager(
            IPullRequestService service,
            IPullRequestSessionService sessionService,
            IRepositoryHosts hosts,
            ITeamExplorerServiceHolder teamExplorerService)
        {
            Guard.ArgumentNotNull(service, nameof(service));
            Guard.ArgumentNotNull(sessionService, nameof(sessionService));
            Guard.ArgumentNotNull(hosts, nameof(hosts));

            this.service        = service;
            this.sessionService = sessionService;
            this.hosts          = hosts;
            teamExplorerService.Subscribe(this, x => RepoChanged(x).Forget());
        }
 public static IRepositoryPublishViewModel SetupConnectionsAndViewModel(
     IRepositoryHosts hosts = null,
     IRepositoryPublishService service = null,
     INotificationService notificationService = null,
     IConnectionManager cm = null,
     string uri = GitHubUrls.GitHub)
 {
     cm = cm ?? Substitutes.ConnectionManager;
     hosts = hosts ?? Substitute.For<IRepositoryHosts>();
     var adds = new List<HostAddress>();
     var hsts = new List<IRepositoryHost>();
     var conns = new List<IConnection>();
     SetupConnections(hosts, cm, adds, conns, hsts, uri);
     hsts[0].ModelService.GetAccounts().Returns(Observable.Return(new ReactiveList<IAccount>()));
     cm.Connections.Returns(new ObservableCollection<IConnection>(conns));
     return GetViewModel(hosts, service, notificationService, cm);
 }
Ejemplo n.º 28
0
        public GitHubPaneViewModel(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder,
            IConnectionManager cm, IRepositoryHosts hosts, INotificationDispatcher notifications)
            : base(apiFactory, holder)
        {
            this.connectionManager = cm;
            this.hosts = hosts;
            syncContext = SynchronizationContext.Current;
            CancelCommand = ReactiveCommand.Create();
            Title = "GitHub";
            Message = String.Empty;

            this.WhenAnyValue(x => x.Control.DataContext)
                .OfType<BaseViewModel>()
                .Select(x => x.WhenAnyValue(y => y.Title))
                .Switch()
                .Subscribe(x => Title = x ?? "GitHub");
        }
Ejemplo n.º 29
0
        public GitHubPaneViewModel(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder,
                                   IConnectionManager cm, IRepositoryHosts hosts, INotificationDispatcher notifications)
            : base(apiFactory, holder)
        {
            this.connectionManager = cm;
            this.hosts             = hosts;
            syncContext            = SynchronizationContext.Current;
            CancelCommand          = ReactiveCommand.Create();
            Title   = "GitHub";
            Message = String.Empty;

            this.WhenAnyValue(x => x.Control.DataContext)
            .OfType <BaseViewModel>()
            .Select(x => x.WhenAnyValue(y => y.Title))
            .Switch()
            .Subscribe(x => Title = x ?? "GitHub");
        }
        public static IRepositoryPublishViewModel SetupConnectionsAndViewModel(
            IRepositoryHosts hosts                   = null,
            IRepositoryPublishService service        = null,
            INotificationService notificationService = null,
            IConnectionManager cm = null,
            string uri            = GitHubUrls.GitHub)
        {
            cm    = cm ?? Substitutes.ConnectionManager;
            hosts = hosts ?? Substitute.For <IRepositoryHosts>();
            var adds  = new List <HostAddress>();
            var hsts  = new List <IRepositoryHost>();
            var conns = new List <IConnection>();

            SetupConnections(hosts, cm, adds, conns, hsts, uri);
            hsts[0].ModelService.GetAccounts().Returns(Observable.Return(new ReactiveList <IAccount>()));
            cm.Connections.Returns(new ObservableCollection <IConnection>(conns));
            return(GetViewModel(hosts, service, notificationService, cm));
        }
Ejemplo n.º 31
0
 public GitHubPublishSection(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder,
                             IConnectionManager cm, Lazy <IVisualStudioBrowser> browser,
                             IRepositoryHosts hosts)
     : base(apiFactory, holder, cm)
 {
     lazyBrowser    = browser;
     this.hosts     = hosts;
     Title          = Resources.GitHubPublishSectionTitle;
     Name           = "GitHub";
     Provider       = "GitHub, Inc";
     Description    = Resources.BlurbText;
     ShowLogin      = false;
     ShowSignup     = false;
     ShowGetStarted = false;
     IsVisible      = false;
     IsExpanded     = true;
     InitializeSectionView();
 }
Ejemplo n.º 32
0
        public GitHubPublishSection(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder,
            IConnectionManager cm, Lazy<IVisualStudioBrowser> browser,
            IRepositoryHosts hosts)
            : base(apiFactory, holder, cm)
        {

            lazyBrowser = browser;
            this.hosts = hosts;
            Title = Resources.GitHubPublishSectionTitle;
            Name = "GitHub";
            Provider = "GitHub, Inc";
            Description = Resources.BlurbText;
            ShowLogin = false;
            ShowSignup = false;
            ShowGetStarted = false;
            IsVisible = false;
            IsExpanded = true;
            InitializeSectionView();
        }
Ejemplo n.º 33
0
        public GitHubPaneViewModel(IGitHubServiceProvider serviceProvider,
                                   ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder,
                                   IConnectionManager cm, IRepositoryHosts hosts, IUIProvider uiProvider)
            : base(serviceProvider, apiFactory, holder)
        {
            this.connectionManager = cm;
            this.hosts             = hosts;
            this.uiProvider        = uiProvider;

            CancelCommand = ReactiveCommand.Create();
            Title         = "GitHub";
            Message       = String.Empty;

            this.WhenAnyValue(x => x.Control.DataContext)
            .OfType <BaseViewModel>()
            .Select(x => x.WhenAnyValue(y => y.Title))
            .Switch()
            .Subscribe(x => Title = x ?? "GitHub");
        }
        public static void SetupConnections(IRepositoryHosts hosts, IConnectionManager cm,
            List<HostAddress> adds, List<IConnection> conns, List<IRepositoryHost> hsts,
            string uri)
        {
            var add = HostAddress.Create(new Uri(uri));
            var host = Substitute.For<IRepositoryHost>();
            var conn = Substitute.For<IConnection>();
            host.Address.Returns(add);
            conn.HostAddress.Returns(add);
            adds.Add(add);
            hsts.Add(host);
            conns.Add(conn);

            if (add.IsGitHubDotCom())
                hosts.GitHubHost.Returns(host);
            else
                hosts.EnterpriseHost.Returns(host);
            hosts.LookupHost(Arg.Is(add)).Returns(host);
        }
        public LoginToGitHubForEnterpriseViewModel(IRepositoryHosts hosts, IVisualStudioBrowser browser) : base(hosts, browser)
        {
            EnterpriseUrlValidator = ReactivePropertyValidator.For(this, x => x.EnterpriseUrl)
                                     .IfNullOrEmpty("Please enter an Enterprise URL")
                                     .IfNotUri("Please enter a valid Enterprise URL")
                                     .IfGitHubDotComHost("Not an Enterprise server. Please enter an Enterprise URL");

            canLogin = this.WhenAny(
                x => x.UsernameOrEmailValidator.ValidationResult.IsValid,
                x => x.PasswordValidator.ValidationResult.IsValid,
                x => x.EnterpriseUrlValidator.ValidationResult.IsValid,
                (x, y, z) => x.Value && y.Value && z.Value)
                       .ToProperty(this, x => x.CanLogin);

            NavigateLearnMore = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(GitHubUrls.LearnMore);
                return(Observable.Return(Unit.Default));
            });
        }
Ejemplo n.º 36
0
        public GitHubPublishSection(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder,
            IConnectionManager cm, Lazy<IVisualStudioBrowser> browser,
            IRepositoryHosts hosts)
            : base(apiFactory, holder, cm)
        {

            lazyBrowser = browser;
            this.hosts = hosts;
            Title = "Publish to GitHub";
            Name = "GitHub";
            Provider = "GitHub, Inc";
            Description = "Powerful collaboration, code review, and code management for open source and private projects.";
            ShowLogin = false;
            ShowSignup = false;
            ShowGetStarted = false;
            IsVisible = false;
            IsExpanded = true;
            var view = new GitHubInvitationContent();
            SectionContent = view;
            view.DataContext = this;
        }
Ejemplo n.º 37
0
        public GitHubPublishSection(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder,
                                    IConnectionManager cm, Lazy <IVisualStudioBrowser> browser,
                                    IRepositoryHosts hosts)
            : base(apiFactory, holder, cm)
        {
            lazyBrowser    = browser;
            this.hosts     = hosts;
            Title          = "Publish to GitHub";
            Name           = "GitHub";
            Provider       = "GitHub, Inc";
            Description    = "Powerful collaboration, code review, and code management for open source and private projects.";
            ShowLogin      = false;
            ShowSignup     = false;
            ShowGetStarted = false;
            IsVisible      = false;
            IsExpanded     = true;
            var view = new GitHubInvitationContent();

            SectionContent   = view;
            view.DataContext = this;
        }
        public LoginToGitHubForEnterpriseViewModel(IRepositoryHosts hosts, IVisualStudioBrowser browser) : base(hosts, browser)
        {
            EnterpriseUrlValidator = ReactivePropertyValidator.For(this, x => x.EnterpriseUrl)
                .IfNullOrEmpty(Resources.EnterpriseUrlValidatorEmpty)
                .IfNotUri(Resources.EnterpriseUrlValidatorInvalid)
                .IfGitHubDotComHost(Resources.EnterpriseUrlValidatorNotAGitHubHost);

            canLogin = this.WhenAny(
                x => x.UsernameOrEmailValidator.ValidationResult.IsValid,
                x => x.PasswordValidator.ValidationResult.IsValid,
                x => x.EnterpriseUrlValidator.ValidationResult.IsValid,
                (x, y, z) => x.Value && y.Value && z.Value)
                .ToProperty(this, x => x.CanLogin);

            NavigateLearnMore = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(GitHubUrls.LearnMore);
                return Observable.Return(Unit.Default);

            });
        }
Ejemplo n.º 39
0
        public LoginToGitHubForEnterpriseViewModel(IRepositoryHosts hosts, IVisualStudioBrowser browser) : base(hosts, browser)
        {
            Guard.ArgumentNotNull(hosts, nameof(hosts));
            Guard.ArgumentNotNull(browser, nameof(browser));

            EnterpriseUrlValidator = ReactivePropertyValidator.For(this, x => x.EnterpriseUrl)
                                     .IfNullOrEmpty(Resources.EnterpriseUrlValidatorEmpty)
                                     .IfNotUri(Resources.EnterpriseUrlValidatorInvalid)
                                     .IfGitHubDotComHost(Resources.EnterpriseUrlValidatorNotAGitHubHost);

            canLogin = this.WhenAny(
                x => x.UsernameOrEmailValidator.ValidationResult.IsValid,
                x => x.PasswordValidator.ValidationResult.IsValid,
                x => x.EnterpriseUrlValidator.ValidationResult.IsValid,
                (x, y, z) => x.Value && y.Value && z.Value)
                       .ToProperty(this, x => x.CanLogin);

            NavigateLearnMore = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(GitHubUrls.LearnMore);
                return(Observable.Return(Unit.Default));
            });
        }
Ejemplo n.º 40
0
        public GitHubPaneViewModel(IGitHubServiceProvider serviceProvider,
                                   ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder,
                                   IConnectionManager cm, IRepositoryHosts hosts, IUIProvider uiProvider, IVisualStudioBrowser vsBrowser,
                                   IUsageTracker usageTracker)
            : base(serviceProvider, apiFactory, holder)
        {
            Guard.ArgumentNotNull(serviceProvider, nameof(serviceProvider));
            Guard.ArgumentNotNull(apiFactory, nameof(apiFactory));
            Guard.ArgumentNotNull(holder, nameof(holder));
            Guard.ArgumentNotNull(cm, nameof(cm));
            Guard.ArgumentNotNull(hosts, nameof(hosts));
            Guard.ArgumentNotNull(uiProvider, nameof(uiProvider));
            Guard.ArgumentNotNull(vsBrowser, nameof(vsBrowser));
            Guard.ArgumentNotNull(usageTracker, nameof(usageTracker));

            this.connectionManager = cm;
            this.hosts             = hosts;
            this.uiProvider        = uiProvider;
            this.usageTracker      = usageTracker;

            CancelCommand = ReactiveCommand.Create();
            Title         = "GitHub";
            Message       = String.Empty;
            browser       = vsBrowser;

            this.WhenAnyValue(x => x.Control.DataContext)
            .Subscribe(x =>
            {
                var pageViewModel = x as IPanePageViewModel;
                var searchable    = x as ISearchablePanePageViewModel;
                controlViewModel  = x as IViewModel;

                Title           = pageViewModel?.Title ?? "GitHub";
                IsSearchEnabled = searchable != null;
                SearchQuery     = searchable?.SearchQuery;
            });
        }
        public static void SetupConnections(IRepositoryHosts hosts, IConnectionManager cm,
                                            List <HostAddress> adds, List <IConnection> conns, List <IRepositoryHost> hsts,
                                            string uri)
        {
            var add  = HostAddress.Create(new Uri(uri));
            var host = Substitute.For <IRepositoryHost>();
            var conn = Substitute.For <IConnection>();

            host.Address.Returns(add);
            conn.HostAddress.Returns(add);
            adds.Add(add);
            hsts.Add(host);
            conns.Add(conn);

            if (add.IsGitHubDotCom())
            {
                hosts.GitHubHost.Returns(host);
            }
            else
            {
                hosts.EnterpriseHost.Returns(host);
            }
            hosts.LookupHost(Arg.Is(add)).Returns(host);
        }
Ejemplo n.º 42
0
        public UIController(IUIProvider uiProvider, IRepositoryHosts hosts, IExportFactoryProvider factory,
            IConnectionManager connectionManager, Lazy<ITwoFactorChallengeHandler> lazyTwoFactorChallengeHandler)
        {
            this.factory = factory;
            this.uiProvider = uiProvider;
            this.hosts = hosts;
            this.connectionManager = connectionManager;
            this.lazyTwoFactorChallengeHandler = lazyTwoFactorChallengeHandler;

#if DEBUG
            if (Application.Current != null && !Splat.ModeDetector.InUnitTestRunner())
            {
                var waitDispatcher = RxApp.MainThreadScheduler as WaitForDispatcherScheduler;
                if (waitDispatcher != null)
                {
                    Debug.Assert(DispatcherScheduler.Current.Dispatcher == Application.Current.Dispatcher,
                       "DispatcherScheduler is set correctly");
                }
                else
                {
                    Debug.Assert(((DispatcherScheduler)RxApp.MainThreadScheduler).Dispatcher == Application.Current.Dispatcher,
                        "The MainThreadScheduler is using the wrong dispatcher");
                }
            }
#endif
            machine = new StateMachine<UIViewType, Trigger>(UIViewType.None);

            machine.Configure(UIViewType.Login)
                .OnEntry(() =>
                {
                    RunView(UIViewType.Login);
                })
                .Permit(Trigger.Next, UIViewType.TwoFactor)
                // Added the following line to make it easy to login to both GitHub and GitHub Enterprise 
                // in DesignTimeStyleHelper in order to test Publish.
                .Permit(Trigger.Cancel, UIViewType.End)
                .PermitIf(Trigger.Finish, UIViewType.End, () => currentFlow == UIControllerFlow.Authentication)
                .PermitIf(Trigger.Finish, UIViewType.Create, () => currentFlow == UIControllerFlow.Create)
                .PermitIf(Trigger.Finish, UIViewType.Clone, () => currentFlow == UIControllerFlow.Clone)
                .PermitIf(Trigger.Finish, UIViewType.Publish, () => currentFlow == UIControllerFlow.Publish);

            machine.Configure(UIViewType.TwoFactor)
                .SubstateOf(UIViewType.Login)
                .OnEntry(() =>
                {
                    RunView(UIViewType.TwoFactor);
                })
                .Permit(Trigger.Cancel, UIViewType.End)
                .PermitIf(Trigger.Next, UIViewType.End, () => currentFlow == UIControllerFlow.Authentication)
                .PermitIf(Trigger.Next, UIViewType.Create, () => currentFlow == UIControllerFlow.Create)
                .PermitIf(Trigger.Next, UIViewType.Clone, () => currentFlow == UIControllerFlow.Clone)
                .PermitIf(Trigger.Next, UIViewType.Publish, () => currentFlow == UIControllerFlow.Publish);

            machine.Configure(UIViewType.Create)
                .OnEntry(() =>
                {
                    RunView(UIViewType.Create);
                })
                .Permit(Trigger.Cancel, UIViewType.End)
                .Permit(Trigger.Next, UIViewType.End);

            machine.Configure(UIViewType.Clone)
                .OnEntry(() =>
                {
                    RunView(UIViewType.Clone);
                })
                .Permit(Trigger.Cancel, UIViewType.End)
                .Permit(Trigger.Next, UIViewType.End);

            machine.Configure(UIViewType.Publish)
                .OnEntry(() =>
                {
                    RunView(UIViewType.Publish);
                })
                .Permit(Trigger.Cancel, UIViewType.End)
                .Permit(Trigger.Next, UIViewType.End);

            machine.Configure(UIViewType.End)
                .OnEntry(() =>
                {
                    uiProvider.RemoveService(typeof(IConnection));
                    transition.OnCompleted();
                })
                .Permit(Trigger.Next, UIViewType.Finished);

            // it might be useful later to check which triggered
            // made us enter here (Cancel or Next) and set a final
            // result accordingly, which is why UIViewType.End only
            // allows a Next trigger
            machine.Configure(UIViewType.Finished);
        }
 public static IObservable<bool> IsLoggedIn(this IConnection connection, IRepositoryHosts hosts)
 {
     Guard.ArgumentNotNull(hosts, nameof(hosts));
     return connection?.Login().Any(c => hosts.LookupHost(c.HostAddress).IsLoggedIn) ?? Observable.Return(false);
 }
Ejemplo n.º 44
0
 public static IObservable <IConnection> GetLoggedInConnections(this IConnectionManager cm, IRepositoryHosts hosts)
 {
     return(cm.Connections.ToObservable()
            .SelectMany(c => c.Login())
            .Where(c => hosts.LookupHost(c.HostAddress).IsLoggedIn));
 }
 public ConnectionRepositoryHostMap(IUIProvider provider, IRepositoryHosts hosts)
     : this(provider.TryGetService<IConnection>(), hosts)
 {
 }
 protected ConnectionRepositoryHostMap(IConnection connection, IRepositoryHosts hosts)
     : this(hosts.LookupHost(connection.HostAddress))
 {
 }
        public RepositoryPublishViewModel(
            IRepositoryHosts hosts,
            IRepositoryPublishService repositoryPublishService,
            INotificationService notificationService,
            IConnectionManager connectionManager,
            IUsageTracker usageTracker)
        {
            this.notificationService = notificationService;
            this.hosts = hosts;
            this.usageTracker = usageTracker;

            title = this.WhenAny(
                x => x.SelectedHost,
                x => x.Value != null ?
                    string.Format(CultureInfo.CurrentCulture, Resources.PublishToTitle, x.Value.Title) :
                    Resources.PublishTitle
            )
            .ToProperty(this, x => x.Title);

            Connections = connectionManager.Connections;
            this.repositoryPublishService = repositoryPublishService;

            if (Connections.Any())
                SelectedConnection = Connections.FirstOrDefault(x => x.HostAddress.IsGitHubDotCom()) ?? Connections[0];

            accounts = this.WhenAny(x => x.SelectedConnection, x => x.Value != null ? hosts.LookupHost(x.Value.HostAddress) : RepositoryHosts.DisconnectedRepositoryHost)
                .Where(x => !(x is DisconnectedRepositoryHost))
                .SelectMany(host => host.ModelService.GetAccounts())
                .ObserveOn(RxApp.MainThreadScheduler)
                .ToProperty(this, x => x.Accounts, initialValue: new ReadOnlyCollection<IAccount>(new IAccount[] {}));

            this.WhenAny(x => x.Accounts, x => x.Value)
                .WhereNotNull()
                .Where(accts => accts.Any())
                .Subscribe(accts => {
                    var selectedAccount = accts.FirstOrDefault();
                    if (selectedAccount != null)
                        SelectedAccount = accts.FirstOrDefault();
                });

            isHostComboBoxVisible = this.WhenAny(x => x.Connections, x => x.Value)
                .WhereNotNull()
                .Select(h => h.Count > 1)
                .ToProperty(this, x => x.IsHostComboBoxVisible);

            InitializeValidation();

            PublishRepository = InitializePublishRepositoryCommand();

            canKeepPrivate = CanKeepPrivateObservable.CombineLatest(PublishRepository.IsExecuting,
                (canKeep, publishing) => canKeep && !publishing)
                .ToProperty(this, x => x.CanKeepPrivate);

            isPublishing = PublishRepository.IsExecuting
                .ToProperty(this, x => x.IsPublishing);

            var defaultRepositoryName = repositoryPublishService.LocalRepositoryName;
            if (!string.IsNullOrEmpty(defaultRepositoryName))
                RepositoryName = defaultRepositoryName;

            this.WhenAny(x => x.SelectedConnection, x => x.SelectedAccount,
                (a,b) => true)
                .Where(x => RepositoryNameValidator.ValidationResult != null && SafeRepositoryNameWarningValidator.ValidationResult != null)
                .Subscribe(async _ =>
                {
                    var name = RepositoryName;
                    RepositoryName = null;
                    await RepositoryNameValidator.ResetAsync();
                    await SafeRepositoryNameWarningValidator.ResetAsync();
                    RepositoryName = name;
                });
        }
 public EnsureLoggedInSectionSync(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder,
     IConnectionManager cm, IRepositoryHosts hosts, ITeamExplorerServices teServices)
     : base(apiFactory, holder, cm, hosts, teServices)
 {}
Ejemplo n.º 49
0
        public UIController(IUIProvider uiProvider, IRepositoryHosts hosts, IExportFactoryProvider factory,
                            IConnectionManager connectionManager, Lazy <ITwoFactorChallengeHandler> lazyTwoFactorChallengeHandler)
        {
            this.factory                       = factory;
            this.uiProvider                    = uiProvider;
            this.hosts                         = hosts;
            this.connectionManager             = connectionManager;
            this.lazyTwoFactorChallengeHandler = lazyTwoFactorChallengeHandler;

#if DEBUG
            if (Application.Current != null && !Splat.ModeDetector.InUnitTestRunner())
            {
                var waitDispatcher = RxApp.MainThreadScheduler as WaitForDispatcherScheduler;
                if (waitDispatcher != null)
                {
                    Debug.Assert(DispatcherScheduler.Current.Dispatcher == Application.Current.Dispatcher,
                                 "DispatcherScheduler is set correctly");
                }
                else
                {
                    Debug.Assert(((DispatcherScheduler)RxApp.MainThreadScheduler).Dispatcher == Application.Current.Dispatcher,
                                 "The MainThreadScheduler is using the wrong dispatcher");
                }
            }
#endif
            machine = new StateMachine <UIViewType, Trigger>(UIViewType.None);

            machine.Configure(UIViewType.Login)
            .OnEntry(() =>
            {
                RunView(UIViewType.Login);
            })
            .Permit(Trigger.Next, UIViewType.TwoFactor)
            // Added the following line to make it easy to login to both GitHub and GitHub Enterprise
            // in DesignTimeStyleHelper in order to test Publish.
            .Permit(Trigger.Cancel, UIViewType.End)
            .PermitIf(Trigger.Finish, UIViewType.End, () => currentFlow == UIControllerFlow.Authentication)
            .PermitIf(Trigger.Finish, UIViewType.Create, () => currentFlow == UIControllerFlow.Create)
            .PermitIf(Trigger.Finish, UIViewType.Clone, () => currentFlow == UIControllerFlow.Clone)
            .PermitIf(Trigger.Finish, UIViewType.Publish, () => currentFlow == UIControllerFlow.Publish);

            machine.Configure(UIViewType.TwoFactor)
            .SubstateOf(UIViewType.Login)
            .OnEntry(() =>
            {
                RunView(UIViewType.TwoFactor);
            })
            .Permit(Trigger.Cancel, UIViewType.End)
            .PermitIf(Trigger.Next, UIViewType.End, () => currentFlow == UIControllerFlow.Authentication)
            .PermitIf(Trigger.Next, UIViewType.Create, () => currentFlow == UIControllerFlow.Create)
            .PermitIf(Trigger.Next, UIViewType.Clone, () => currentFlow == UIControllerFlow.Clone)
            .PermitIf(Trigger.Next, UIViewType.Publish, () => currentFlow == UIControllerFlow.Publish);

            machine.Configure(UIViewType.Create)
            .OnEntry(() =>
            {
                RunView(UIViewType.Create);
            })
            .Permit(Trigger.Cancel, UIViewType.End)
            .Permit(Trigger.Next, UIViewType.End);

            machine.Configure(UIViewType.Clone)
            .OnEntry(() =>
            {
                RunView(UIViewType.Clone);
            })
            .Permit(Trigger.Cancel, UIViewType.End)
            .Permit(Trigger.Next, UIViewType.End);

            machine.Configure(UIViewType.Publish)
            .OnEntry(() =>
            {
                RunView(UIViewType.Publish);
            })
            .Permit(Trigger.Cancel, UIViewType.End)
            .Permit(Trigger.Next, UIViewType.End);

            machine.Configure(UIViewType.End)
            .OnEntry(() =>
            {
                uiProvider.RemoveService(typeof(IConnection));
                transition.OnCompleted();
            })
            .Permit(Trigger.Next, UIViewType.Finished);

            // it might be useful later to check which triggered
            // made us enter here (Cancel or Next) and set a final
            // result accordingly, which is why UIViewType.End only
            // allows a Next trigger
            machine.Configure(UIViewType.Finished);
        }
Ejemplo n.º 50
0
 protected ConnectionRepositoryHostMap(IConnection connection, IRepositoryHosts hosts)
     : this(hosts.LookupHost(connection.HostAddress))
 {
 }
Ejemplo n.º 51
0
 public ConnectionRepositoryHostMap(IServiceProvider provider, IRepositoryHosts hosts)
     : this(provider.GetService <IConnection>(), hosts)
 {
 }
        public RepositoryPublishViewModel(
            IRepositoryHosts hosts,
            IRepositoryPublishService repositoryPublishService,
            INotificationService notificationService,
            IConnectionManager connectionManager,
            IUsageTracker usageTracker)
        {
            this.notificationService = notificationService;
            this.hosts        = hosts;
            this.usageTracker = usageTracker;

            title = this.WhenAny(
                x => x.SelectedHost,
                x => x.Value != null ?
                string.Format(CultureInfo.CurrentCulture, Resources.PublishToTitle, x.Value.Title) :
                Resources.PublishTitle
                )
                    .ToProperty(this, x => x.Title);

            Connections = connectionManager.Connections;
            this.repositoryPublishService = repositoryPublishService;

            if (Connections.Any())
            {
                SelectedConnection = Connections.FirstOrDefault(x => x.HostAddress.IsGitHubDotCom()) ?? Connections[0];
            }

            accounts = this.WhenAny(x => x.SelectedConnection, x => x.Value != null ? hosts.LookupHost(x.Value.HostAddress) : RepositoryHosts.DisconnectedRepositoryHost)
                       .Where(x => !(x is DisconnectedRepositoryHost))
                       .SelectMany(host => host.ModelService.GetAccounts())
                       .ObserveOn(RxApp.MainThreadScheduler)
                       .ToProperty(this, x => x.Accounts, initialValue: new ReadOnlyCollection <IAccount>(new IAccount[] {}));

            this.WhenAny(x => x.Accounts, x => x.Value)
            .WhereNotNull()
            .Where(accts => accts.Any())
            .Subscribe(accts => {
                var selectedAccount = accts.FirstOrDefault();
                if (selectedAccount != null)
                {
                    SelectedAccount = accts.FirstOrDefault();
                }
            });

            isHostComboBoxVisible = this.WhenAny(x => x.Connections, x => x.Value)
                                    .WhereNotNull()
                                    .Select(h => h.Count > 1)
                                    .ToProperty(this, x => x.IsHostComboBoxVisible);

            InitializeValidation();

            PublishRepository = InitializePublishRepositoryCommand();

            canKeepPrivate = CanKeepPrivateObservable.CombineLatest(PublishRepository.IsExecuting,
                                                                    (canKeep, publishing) => canKeep && !publishing)
                             .ToProperty(this, x => x.CanKeepPrivate);

            isPublishing = PublishRepository.IsExecuting
                           .ToProperty(this, x => x.IsPublishing);

            var defaultRepositoryName = repositoryPublishService.LocalRepositoryName;

            if (!string.IsNullOrEmpty(defaultRepositoryName))
            {
                RepositoryName = defaultRepositoryName;
            }

            this.WhenAny(x => x.SelectedConnection, x => x.SelectedAccount,
                         (a, b) => true)
            .Where(x => RepositoryNameValidator.ValidationResult != null && SafeRepositoryNameWarningValidator.ValidationResult != null)
            .Subscribe(async _ =>
            {
                var name       = RepositoryName;
                RepositoryName = null;
                await RepositoryNameValidator.ResetAsync();
                await SafeRepositoryNameWarningValidator.ResetAsync();
                RepositoryName = name;
            });
        }