Exemplo n.º 1
0
        public IObservable <AuthenticationResult> LogIn(
            HostAddress address,
            string usernameOrEmail,
            string password)
        {
            var isDotCom = HostAddress.GitHubDotComHostAddress == address;
            var host     = RepositoryHostFactory.Create(address);

            disposables.Add(host);
            return(host.LogIn(usernameOrEmail, password)
                   .Catch <AuthenticationResult, Exception>(Observable.Throw <AuthenticationResult>)
                   .Do(result =>
            {
                bool successful = result.IsSuccess();
                log.Info(CultureInfo.InvariantCulture, "Log in to {3} host '{0}' with username '{1}' {2}",
                         address.ApiUri,
                         usernameOrEmail,
                         successful ? "SUCCEEDED" : "FAILED",
                         isDotCom ? "GitHub.com" : address.WebUri.Host
                         );
                if (successful)
                {
                    if (isDotCom)
                    {
                        GitHubHost = host;
                    }
                    else
                    {
                        EnterpriseHost = host;
                    }
                    connectionManager.AddConnection(address, usernameOrEmail);
                }
            }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// This is only called by the connection manager when logging in connections
        /// that already exist so we don't have to add the connection.
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        public IObservable <AuthenticationResult> LogInFromCache(HostAddress address)
        {
            var isDotCom = HostAddress.GitHubDotComHostAddress == address;

            return(Observable.Defer(async() =>
            {
                var host = await RepositoryHostFactory.Create(address);
                return host.LogInFromCache()
                .Catch <AuthenticationResult, Exception>(Observable.Throw <AuthenticationResult>)
                .ObserveOn(RxApp.MainThreadScheduler)
                .Do(result =>
                {
                    bool successful = result.IsSuccess();
                    if (successful)
                    {
                        if (isDotCom)
                        {
                            GitHubHost = host;
                        }
                        else
                        {
                            EnterpriseHost = host;
                        }
                    }
                });
            }));
        }
Exemplo n.º 3
0
        public IObservable <AuthenticationResult> LogIn(
            HostAddress address,
            string usernameOrEmail,
            string password)
        {
            Guard.ArgumentNotNull(address, nameof(address));
            Guard.ArgumentNotEmptyString(usernameOrEmail, nameof(usernameOrEmail));
            Guard.ArgumentNotEmptyString(password, nameof(password));

            var isDotCom = HostAddress.GitHubDotComHostAddress == address;

            return(Observable.Defer(async() =>
            {
                var host = await RepositoryHostFactory.Create(address);

                return host.LogIn(usernameOrEmail, password)
                .Catch <AuthenticationResult, Exception>(Observable.Throw <AuthenticationResult>)
                .ObserveOn(RxApp.MainThreadScheduler)
                .Do(result =>
                {
                    bool successful = result.IsSuccess();
                    log.Information("Log in to {Host} host '{ApiUri}' with username '{UsernameOrEmail}' {Successful}",
                                    isDotCom ? "GitHub.com" : address.WebUri.Host,
                                    address.ApiUri,
                                    usernameOrEmail,
                                    successful ? "SUCCEEDED" : "FAILED"
                                    );
                    if (successful)
                    {
                        // Make sure that GitHubHost/EnterpriseHost are set when the connections
                        // changed event is raised and likewise that the connection is added when
                        // the property changed notification is sent.
                        if (isDotCom)
                        {
                            githubHost = host;
                        }
                        else
                        {
                            enterpriseHost = host;
                        }

                        connectionManager.AddConnection(address, usernameOrEmail);

                        if (isDotCom)
                        {
                            this.RaisePropertyChanged(nameof(GitHubHost));
                        }
                        else
                        {
                            this.RaisePropertyChanged(nameof(EnterpriseHost));
                        }
                    }
                });
            }));
        }
Exemplo n.º 4
0
        public IObservable <AuthenticationResult> LogIn(
            HostAddress address,
            string usernameOrEmail,
            string password)
        {
            var isDotCom = HostAddress.GitHubDotComHostAddress == address;
            var host     = RepositoryHostFactory.Create(address);

            return(host.LogIn(usernameOrEmail, password)
                   .Catch <AuthenticationResult, Exception>(Observable.Throw <AuthenticationResult>)
                   .Do(result =>
            {
                bool successful = result.IsSuccess();
                log.Info(CultureInfo.InvariantCulture, "Log in to {3} host '{0}' with username '{1}' {2}",
                         address.ApiUri,
                         usernameOrEmail,
                         successful ? "SUCCEEDED" : "FAILED",
                         isDotCom ? "GitHub.com" : address.WebUri.Host
                         );
                if (successful)
                {
                    // Make sure that GitHubHost/EnterpriseHost are set when the connections
                    // changed event is raised and likewise that the connection is added when
                    // the property changed notification is sent.
                    if (isDotCom)
                    {
                        githubHost = host;
                    }
                    else
                    {
                        enterpriseHost = host;
                    }

                    connectionManager.AddConnection(address, usernameOrEmail);

                    if (isDotCom)
                    {
                        this.RaisePropertyChanged(nameof(GitHubHost));
                    }
                    else
                    {
                        this.RaisePropertyChanged(nameof(EnterpriseHost));
                    }
                }
            }));
        }
Exemplo n.º 5
0
        /// <summary>
        /// This is only called by the connection manager when logging in connections
        /// that already exist so we don't have to add the connection.
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        public IObservable <AuthenticationResult> LogInFromCache(HostAddress address)
        {
            var isDotCom = HostAddress.GitHubDotComHostAddress == address;
            var host     = RepositoryHostFactory.Create(address);

            return(host.LogInFromCache()
                   .Catch <AuthenticationResult, Exception>(Observable.Throw <AuthenticationResult>)
                   .Do(result =>
            {
                bool successful = result.IsSuccess();
                if (successful)
                {
                    if (isDotCom)
                    {
                        GitHubHost = host;
                    }
                    else
                    {
                        EnterpriseHost = host;
                    }
                }
            }));
        }