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"); })); }
public PullRequestCacheItem(PullRequest pr, IReadOnlyList <PullRequestFile> files) { Title = pr.Title; Number = pr.Number; Base = new GitReferenceCacheItem { Label = pr.Base.Label, Ref = pr.Base.Ref, Sha = pr.Base.Sha, RepositoryCloneUrl = pr.Base.Repository.CloneUrl, }; Head = new GitReferenceCacheItem { Label = pr.Head.Label, Ref = pr.Head.Ref, Sha = pr.Head.Sha, RepositoryCloneUrl = pr.Head.Repository?.CloneUrl }; CommentCount = pr.Comments + pr.ReviewComments; CommitCount = pr.Commits; Author = new AccountCacheItem(pr.User); Assignee = pr.Assignee != null ? new AccountCacheItem(pr.Assignee) : null; CreatedAt = pr.CreatedAt; UpdatedAt = pr.UpdatedAt; Body = pr.Body; ChangedFiles = files.Select(x => new PullRequestFileCacheItem(x)).ToList(); State = GetState(pr); IsOpen = pr.State == ItemState.Open; Merged = pr.Merged; Key = Number.ToString(CultureInfo.InvariantCulture); Timestamp = UpdatedAt; }
IObservable <AuthenticationResult> LoginWithApiUser(AccountCacheItem user) { return(GetAuthenticationResultForUser(user) .SelectMany(result => { if (result.IsSuccess()) { return ModelService.InsertUser(user).Select(_ => result); } if (result == AuthenticationResult.VerificationFailure) { return loginCache.EraseLogin(Address).Select(_ => result); } return Observable.Return(result); }) .ObserveOn(RxApp.MainThreadScheduler) .Do(result => { if (result.IsSuccess()) { IsLoggedIn = true; } log.Info("Log in from cache for login '{0}' to host '{1}' {2}", user != null ? user.Login : "******", hostAddress.ApiUri, result.IsSuccess() ? "SUCCEEDED" : "FAILED"); })); }
public async Task <IModelService> CreateAsync(IConnection connection) { ModelService result; await cacheLock.WaitAsync(); try { if (!cache.TryGetValue(connection, out result)) { result = new ModelService( await apiClientFactory.Create(connection.HostAddress), await hostCacheFactory.Create(connection.HostAddress), avatarProvider); result.InsertUser(AccountCacheItem.Create(connection.User)); cache.Add(connection, result); } } finally { cacheLock.Release(); } return(result); }
static IObservable <AuthenticationResult> GetAuthenticationResultForUser(AccountCacheItem account) { return(Observable.Return(account == null ? AuthenticationResult.CredentialFailure : account == unverifiedUser ? AuthenticationResult.VerificationFailure : AuthenticationResult.Success)); }
public void SetsIsEnterpriseCorrectly(string htmlUrl, bool expected) { var apiAccount = CreateOctokitUser("foo", htmlUrl); var cachedAccount = new AccountCacheItem(apiAccount); Assert.That(expected, Is.EqualTo(cachedAccount.IsEnterprise)); }
public IssueCommentCacheItem(IssueComment comment) { Id = comment.Id; User = new AccountCacheItem(comment.User); Body = comment.Body; CreatedAt = comment.CreatedAt; }
public IObservable <AuthenticationResult> LogInFromCache() { Func <Task <AuthenticationResult> > f = async() => { try { var user = await loginManager.LoginFromCache(Address, ApiClient.GitHubClient); var accountCacheItem = new AccountCacheItem(user); usage.IncrementLoginCount().Forget(); await ModelService.InsertUser(accountCacheItem); if (user != unverifiedUser.User) { IsLoggedIn = true; return(AuthenticationResult.Success); } else { return(AuthenticationResult.VerificationFailure); } } catch (AuthorizationException) { return(AuthenticationResult.CredentialFailure); } }; return(f().ToObservable()); }
public RepositoryCacheItem(Repository apiRepository) { Name = apiRepository.Name; Owner = AccountCacheItem.Create(apiRepository.Owner); CloneUrl = apiRepository.CloneUrl; Private = apiRepository.Private; Fork = apiRepository.Fork; }
IAccount Create(AccountCacheItem accountCacheItem) { return(new Models.Account( accountCacheItem.Login, accountCacheItem.IsUser, accountCacheItem.IsEnterprise, accountCacheItem.OwnedPrivateRepositoriesCount, accountCacheItem.PrivateRepositoriesInPlanCount, avatarProvider.GetAvatar(accountCacheItem))); }
public PullRequestCacheItem(PullRequest pr) { Title = pr.Title; Number = pr.Number; CommentCount = pr.Comments; Author = new AccountCacheItem(pr.User); CreatedAt = pr.CreatedAt; UpdatedAt = pr.UpdatedAt; Key = Number.ToString(CultureInfo.InvariantCulture); Timestamp = UpdatedAt; }
public PullRequestCacheItem(PullRequest pr) { Title = pr.Title; Number = pr.Number; CommentCount = pr.Comments + pr.ReviewComments; Author = new AccountCacheItem(pr.User); Assignee = pr.Assignee != null ? new AccountCacheItem(pr.Assignee) : null; CreatedAt = pr.CreatedAt; UpdatedAt = pr.UpdatedAt; IsOpen = pr.State == ItemState.Open; Key = Number.ToString(CultureInfo.InvariantCulture); Timestamp = UpdatedAt; }
public RepositoryCacheItem(Repository apiRepository) { Id = apiRepository.Id; Name = apiRepository.Name; Owner = AccountCacheItem.Create(apiRepository.Owner); CloneUrl = apiRepository.CloneUrl; Private = apiRepository.Private; Fork = apiRepository.Fork; Key = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", Owner.Login, Name); CreatedAt = apiRepository.CreatedAt; UpdatedAt = apiRepository.UpdatedAt; Timestamp = apiRepository.UpdatedAt; }
public PullRequestReviewCacheItem(IPullRequestReviewModel review) { Id = review.Id; NodeId = review.NodeId; User = new AccountCacheItem { Login = review.User.Login, AvatarUrl = review.User.AvatarUrl, }; Body = review.Body; State = review.State; SubmittedAt = review.SubmittedAt; }
public PullRequestReviewCommentCacheItem(PullRequestReviewComment comment) { Id = comment.Id; Path = comment.Path; Position = comment.Position; OriginalPosition = comment.OriginalPosition; CommitId = comment.CommitId; OriginalCommitId = comment.OriginalCommitId; DiffHunk = comment.DiffHunk; User = new AccountCacheItem(comment.User); Body = comment.Body; CreatedAt = comment.CreatedAt; }
public PullRequestReviewCommentCacheItem(IPullRequestReviewCommentModel comment) { Id = comment.Id; NodeId = comment.NodeId; PullRequestReviewId = comment.PullRequestReviewId; Path = comment.Path; Position = comment.Position; OriginalPosition = comment.OriginalPosition; CommitId = comment.CommitId; OriginalCommitId = comment.OriginalCommitId; DiffHunk = comment.DiffHunk; User = new AccountCacheItem { Login = comment.User.Login, AvatarUrl = comment.User.AvatarUrl, }; Body = comment.Body; CreatedAt = comment.CreatedAt; IsPending = comment.IsPending; }
public IObservable <AuthenticationResult> LogIn(string usernameOrEmail, string password) { Guard.ArgumentNotEmptyString(usernameOrEmail, nameof(usernameOrEmail)); Guard.ArgumentNotEmptyString(password, nameof(password)); return(Observable.Defer(async() => { var user = await loginManager.Login(Address, ApiClient.GitHubClient, usernameOrEmail, password); var accountCacheItem = new AccountCacheItem(user); usage.IncrementLoginCount().Forget(); await ModelService.InsertUser(accountCacheItem); if (user != unverifiedUser.User) { IsLoggedIn = true; return Observable.Return(AuthenticationResult.Success); } else { return Observable.Return(AuthenticationResult.VerificationFailure); } })); }
public IObservable <Unit> InsertUser(AccountCacheItem user) { return(hostCache.InsertObject("user", user)); }