예제 #1
0
        /// <summary>
        /// 1. Check whether this is the first upload for this bug (maybe not necessary)
        /// 2. Calculate algorithm values for the files in the bug
        /// 3. Calculate reviewers for the bug
        /// </summary>
        private void ProcessPatchUpload(IssueTrackerEvent info, bool noComparison, bool fRecalculateMode)
        {
            // 1. Check whether this is the first upload for this bug (maybe not necessary)
            if (PredictedIssues.Contains(info.ChangeId))
            {
                return;     // this is not the first item for this bug. We don't need another prediction.
            }
            // 2. Calculate algorithm values for the files in the bug

            DateTime end = info.When;

            foreach (AlgorithmBase algo in Algorithms)
            {
                algo.UpdateFromSourceUntil(end);
            }

            IList <string> involvedFiles = info.Filenames;

            List <Task> tasks = new List <Task>();

            foreach (AlgorithmBase algorithm in Algorithms)
            {
                tasks.Add(algorithm.CalculateExpertiseForFilesAsync(involvedFiles));
            }

            Task.WaitAll(tasks.ToArray());

            if (noComparison)
            {
                return;
            }

            // 3. Calculate reviewers for the bug

            IEnumerable <int> artifactIds = involvedFiles
                                            .Select(fileName => SourceManager.FindOrCreateFileArtifactId(fileName));

            // Create a list of tasks, one for each algorithm, that compute reviewers for the artifact
            IEnumerable <Task <ComputedReviewer> > computedReviewerTasks = Algorithms.Select(algorithm => algorithm.GetDevelopersForArtifactsAsync(artifactIds)).ToList();

            Task.WaitAll(computedReviewerTasks.ToArray());

            using (ExpertiseDBEntities repository = new ExpertiseDBEntities())
            {
                Bug currentBug = null;

                if (fRecalculateMode)
                {
                    currentBug = repository.Bugs.SingleOrDefault(bug => bug.ChangeId == info.ChangeId);
                }

                if (!fRecalculateMode || null == currentBug)
                {
                    currentBug = new Bug()
                    {
                        ChangeId     = info.ChangeId,
                        RepositoryId = this.RepositoryId
                    };
                    repository.Bugs.Add(currentBug);
                }

                foreach (Task <ComputedReviewer> task in computedReviewerTasks)
                {
                    currentBug.ComputedReviewers.Add(task.Result);
                }

                repository.SaveChanges();
            }
            PredictedIssues.Add(info.ChangeId);
        }