Example #1
0
        async Task <PullRequestSession> GetSessionInternal(IPullRequestModel pullRequest)
        {
            PullRequestSession session = null;
            WeakReference <PullRequestSession> weakSession;
            var key = Tuple.Create(pullRequest.Base.RepositoryCloneUrl.Owner, pullRequest.Number);

            if (sessions.TryGetValue(key, out weakSession))
            {
                weakSession.TryGetTarget(out session);
            }

            if (session == null)
            {
                var modelService = hosts.LookupHost(HostAddress.Create(repository.CloneUrl))?.ModelService;

                if (modelService != null)
                {
                    session = new PullRequestSession(
                        sessionService,
                        await modelService.GetCurrentUser(),
                        pullRequest,
                        repository,
                        key.Item1,
                        false);
                    sessions[key] = new WeakReference <PullRequestSession>(session);
                }
            }
            else
            {
                await session.Update(pullRequest);
            }

            return(session);
        }
        async Task <PullRequestSession> GetSessionInternal(string owner, string name, int number)
        {
            PullRequestSession session = null;
            WeakReference <PullRequestSession> weakSession;
            var key = Tuple.Create(owner, number);

            if (sessions.TryGetValue(key, out weakSession))
            {
                weakSession.TryGetTarget(out session);
            }

            if (session == null)
            {
                var address     = HostAddress.Create(repository.CloneUrl);
                var pullRequest = await sessionService.ReadPullRequestDetail(address, owner, name, number);

                session = new PullRequestSession(
                    sessionService,
                    await sessionService.ReadViewer(address),
                    pullRequest,
                    repository,
                    key.Item1,
                    false);
                sessions[key] = new WeakReference <PullRequestSession>(session);
            }

            return(session);
        }