예제 #1
0
        /// <summary>
        /// The get duplicated blocks.
        /// </summary>
        /// <param name="secondProject">
        /// The second project.
        /// </param>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        public List<DuplicationData> GetDuplicatedBlocks(SonarProject secondProject)
        {
            var newData = new List<DuplicationData>();

            foreach (var otherData in this.GetDuplicatedData())
            {
                var isFound = false;

                foreach (var group in otherData.DuplicatedGroups)
                {
                    foreach (var block in group.DuplicatedBlocks)
                    {
                        if (this.IsFileFoundInFiles(block.Resource.Key) != null)
                        {
                            continue;
                        }

                        if (secondProject.IsFileFoundInFiles(block.Resource.Key) != null)
                        {
                            isFound = true;
                        }
                    }
                }

                if (isFound)
                {
                    newData.Add(otherData);
                }
            }

            return newData;
        }
        /// <summary>
        /// The set duplication data for single project.
        /// </summary>
        /// <param name="value">
        /// The value.
        /// </param>
        private void SetDuplicationDataForSingleProject(SonarProject project)
        {
            var bw = new BackgroundWorker();

            bw.DoWork += delegate
            {
                this.IsIdle = false;
                if (project == null)
                {
                    return;
                }

                this.DuplicatedData = project.GetDuplicatedData();
                this.CrossProjectResources = this.GetProjectsWithMatchingDuplications(project);
            };

            bw.RunWorkerCompleted += delegate
            {
                this.OnPropertyChanged();
                this.IsIdle = true;
            };

            bw.RunWorkerAsync();
        }
        /// <summary>
        /// The set cross duplication data.
        /// </summary>
        /// <param name="mainSonarProject">
        /// The main sonar project.
        /// </param>
        /// <param name="secondProject">
        /// The second project.
        /// </param>
        private void SetCrossDuplicationData(SonarProject mainSonarProject, SonarProject secondProject)
        {
            var bw = new BackgroundWorker();

            bw.DoWork += delegate
            {
                this.IsIdle = false;
                this.DuplicatedData = mainSonarProject.GetDuplicatedBlocks(secondProject);
            };

            bw.RunWorkerCompleted += delegate
            {
                this.OnPropertyChanged();
                this.IsIdle = true;
            };

            bw.RunWorkerAsync();
        }
        /// <summary>
        /// The get projects with matching duplications.
        /// </summary>
        /// <param name="project">
        /// The project.
        /// </param>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        private List<SonarProject> GetProjectsWithMatchingDuplications(SonarProject project)
        {
            var crossProjectData = new List<SonarProject>();

            foreach (var dup in this.DuplicatedData)
            {
                foreach (var group in dup.DuplicatedGroups)
                {
                    foreach (var block in group.DuplicatedBlocks)
                    {
                        if (project.IsFileFoundInFiles(block.Resource.Key) == null)
                        {
                            foreach (var projectResource in this.ProjectResources)
                            {
                                if (projectResource.IsFileFoundInFiles(block.Resource.Key) != null)
                                {
                                    bool found = false;
                                    foreach (var crossproject in crossProjectData)
                                    {
                                        if (crossproject.Project.Key.Equals(projectResource.Project.Key))
                                        {
                                            found = true;
                                        }
                                    }

                                    if (!found)
                                    {
                                        crossProjectData.Add(projectResource);
                                    }
                                }
                            }
                        }

                    }
                }
            }

            return crossProjectData;
        }