Example #1
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;
                        }
                    }
                });
            }));
        }
        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);
                }
            }));
        }
Example #3
0
        public IObservable <Unit> LogOut(IRepositoryHost host)
        {
            Guard.ArgumentNotNull(host, nameof(host));

            var address  = host.Address;
            var isDotCom = HostAddress.GitHubDotComHostAddress == address;

            return(host.LogOut()
                   .ObserveOn(RxApp.MainThreadScheduler)
                   .Do(result =>
            {
                // reset the logged out host property to null
                // it'll know what to do
                if (isDotCom)
                {
                    GitHubHost = null;
                }
                else
                {
                    EnterpriseHost = null;
                }
                connectionManager.RemoveConnection(address);
                RepositoryHostFactory.Remove(host);
            }));
        }
Example #4
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));
                        }
                    }
                });
            }));
        }
Example #5
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));
                    }
                }
            }));
        }
Example #6
0
        public IObservable <Unit> LogOut(IRepositoryHost host)
        {
            var address  = host.Address;
            var isDotCom = HostAddress.GitHubDotComHostAddress == address;

            return(host.LogOut()
                   .Do(result =>
            {
                // reset the logged out host property to null
                // it'll know what to do
                if (isDotCom)
                {
                    GitHubHost = null;
                }
                else
                {
                    EnterpriseHost = null;
                }
                connectionManager.RemoveConnection(address);
                RepositoryHostFactory.Remove(host);
            }));
        }
Example #7
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;
                    }
                }
            }));
        }