GitHub.Models.RepositoryHost.LoginWithApiUser C# (CSharp) Method

LoginWithApiUser() private method

private LoginWithApiUser ( UserAndScopes userAndScopes ) : IObservable
userAndScopes UserAndScopes
return IObservable
        IObservable<AuthenticationResult> LoginWithApiUser(UserAndScopes userAndScopes)
        {
            return GetAuthenticationResultForUser(userAndScopes)
                .SelectMany(result =>
                {
                    if (result.IsSuccess())
                    {
                        var accountCacheItem = new AccountCacheItem(userAndScopes.User);
                        usage.IncrementLoginCount().Forget();
                        return ModelService.InsertUser(accountCacheItem).Select(_ => result);
                    }

                    if (result == AuthenticationResult.VerificationFailure)
                    {
                        return loginCache.EraseLogin(Address).Select(_ => result);
                    }
                    return Observable.Return(result);
                })
                .ObserveOn(RxApp.MainThreadScheduler)
                .Do(result =>
                {
                    if (result.IsSuccess())
                    {
                        SupportsGist = userAndScopes.Scopes?.Contains("gist") ?? true;
                        IsLoggedIn = true;
                    }

                    log.Info("Log in from cache for login '{0}' to host '{1}' {2}",
                        userAndScopes?.User?.Login ?? "(null)",
                        hostAddress.ApiUri,
                        result.IsSuccess() ? "SUCCEEDED" : "FAILED");
                });
        }