コード例 #1
0
        async private Task <Dictionary <ProjectKey, IEnumerable <MergeRequest> > > loadMergeRequestsAsync()
        {
            ProjectBasedContext pbc = (ProjectBasedContext)_dataCacheConnectionContext.CustomData;

            Dictionary <ProjectKey, IEnumerable <MergeRequest> > mergeRequests =
                new Dictionary <ProjectKey, IEnumerable <MergeRequest> >();

            Exception exception = null;

            async Task loadProject(ProjectKey project)
            {
                if (exception != null)
                {
                    return;
                }

                try
                {
                    IEnumerable <MergeRequest> projectMergeRequests = await loadProjectMergeRequestsAsync(project);

                    mergeRequests.Add(project, projectMergeRequests);
                }
                catch (BaseLoaderException ex)
                {
                    if (isForbiddenProjectException(ex))
                    {
                        _dataCacheConnectionContext.Callbacks.OnForbiddenProject?.Invoke(project);
                    }
                    else if (isNotFoundProjectException(ex))
                    {
                        _dataCacheConnectionContext.Callbacks.OnNotFoundProject?.Invoke(project);
                    }
                    else
                    {
                        exception = ex;
                    }
                }
            }

            await TaskUtils.RunConcurrentFunctionsAsync(pbc.Projects, x => loadProject(x),
                                                        () => Constants.MergeRequestLoaderProjectBatchLimits, () => exception != null);

            if (exception != null)
            {
                throw exception;
            }
            return(mergeRequests);
        }
コード例 #2
0
        async private Task <IEnumerable <Project> > loadProjectsAsync()
        {
            ProjectBasedContext pbc = (ProjectBasedContext)_dataCacheConnectionContext.CustomData;

            List <Project> projects = new List <Project>();

            Exception exception = null;

            async Task loadProject(string projectName)
            {
                if (exception != null)
                {
                    return;
                }

                try
                {
                    Project project = await call(() => _operator.GetProjectAsync(projectName),
                                                 String.Format("Cancelled loading project \"{0}\"", projectName),
                                                 String.Format("Cannot load project \"{0}\"", projectName));

                    projects.Add(project);
                }
                catch (BaseLoaderException ex)
                {
                    exception = ex;
                }
            }

            await TaskUtils.RunConcurrentFunctionsAsync(pbc.Projects, projectKey => loadProject(projectKey.ProjectName),
                                                        () => Constants.ProjectListLoaderBatchLimits, () => exception != null);

            if (exception != null)
            {
                throw exception;
            }

            return(projects);
        }