/// <summary>
        /// The get coverage DataCache for resource.
        /// </summary>
        /// <param name="resource">
        /// The resource.
        /// </param>
        /// <param name="currentSource">
        /// The current source.
        /// </param>
        /// <returns>
        /// The <see>
        ///         <cref>Dictionary</cref>
        ///     </see>
        ///     .
        /// </returns>
        public Dictionary <int, CoverageElement> GetCoverageDataForResource(Resource resource, string currentSource)
        {
            var coverageLine = new Dictionary <int, CoverageElement>();

            if (!DataCache.ContainsKey(resource.Key))
            {
                return(coverageLine);
            }

            EditorData element = DataCache[resource.Key];

            ArrayList diffReport = VsSonarUtils.GetSourceDiffFromStrings(element.ServerSource, currentSource, DiffEngineLevel.FastImperfect);

            foreach (var linecov in element.CoverageData)
            {
                int line = VsSonarUtils.EstimateWhereSonarLineIsUsingSourceDifference(linecov.Key, diffReport);

                if (line > 0 && !coverageLine.ContainsKey(line))
                {
                    coverageLine.Add(line, linecov.Value);
                }
            }

            return(coverageLine);
        }
示例#2
0
        public void TestCompare()
        {
            var source      = Path.Combine(this.sampleDataPath, "SonarSource.txt");
            var destination = Path.Combine(this.sampleDataPath, "LocalSource.txt");
            var rep         = VsSonarUtils.GetSourceDiffFromStrings(File.ReadAllText(source), File.ReadAllText(destination));

            Assert.AreEqual(9, rep.Count);
        }
        /// <summary>
        /// The get issues for resource.
        /// </summary>
        /// <param name="resource">
        /// The resource.
        /// </param>
        /// <param name="currentSource">
        /// The current source.
        /// </param>
        /// <returns>
        /// The
        ///     <see>
        ///         <cref>List</cref>
        ///     </see>
        ///     .
        /// </returns>
        public List <Issue> GetIssuesForResource(Resource resource, string currentSource)
        {
            var issues = new List <Issue>();

            if (!DataCache.ContainsKey(resource.Key))
            {
                return(issues);
            }

            EditorData element = DataCache[resource.Key];

            if (element.ServerSource == null)
            {
                return(element.Issues);
            }

            try
            {
                ArrayList diffReport = VsSonarUtils.GetSourceDiffFromStrings(element.ServerSource, currentSource, DiffEngineLevel.FastImperfect);

                foreach (Issue issue in element.Issues)
                {
                    int line = VsSonarUtils.EstimateWhereSonarLineIsUsingSourceDifference(issue.Line, diffReport);

                    if (line >= 0)
                    {
                        issues.Add(issue);
                    }
                }

                return(issues);
            }
            catch (Exception)
            {
                return(element.Issues);
            }
        }