Beispiel #1
0
        public override string FormatCodeWithHighlights(string code, List <DbCodeSegment> codeSegments)
        {
            if (codeSegments.Count == 0)
            {
                return(code);
            }
            var codeContents = new StringBuilder(code);
            var offset       = 0;

            try
            {
                foreach (var lineOfCode in codeSegments)
                {
                    codeContents.Insert((lineOfCode.StartByte / 2) + offset, this.StartHighlightMarkUp);
                    offset += this.StartHighlightMarkUp.Length;
                    codeContents.Insert((lineOfCode.EndByte / 2) + offset, this.EndHighlightMarkUp);
                    offset += this.EndHighlightMarkUp.Length;
                }
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine("Unable to highlight code in '{0}', the exception is: {1}", code, ex);

                return(code);
            }
            return(_dataScrubber.Scrub(codeContents.ToString(), "format.scrub"));
        }
        public DbObject ProcessObjectCoverage(DbObject dbObject)
        {
            var dbObjectClone = dbObject.Get();

            if (dbObjectClone.Code == null)
            {
                return(dbObjectClone);
            }

            if (dbObjectClone.CoveredSegments.Count > 0)
            {
                var codeWithHighlights = _dbCodeFormatter.FormatCodeWithHighlights(dbObjectClone.Code,
                                                                                   dbObjectClone.CoveredSegments);
                dbObjectClone.CoveredSegments = ProcessHighlightedCode(codeWithHighlights);

                var functionalHighlightedCode = _dataScrubber.Scrub(codeWithHighlights, "floc.scrub");
                var functionalSegments        = ProcessHighlightedCode(functionalHighlightedCode);
                foreach (var functionalSegment in functionalSegments)
                {
                    dbObjectClone.CoveredCharacters  += functionalSegment.EndByte - functionalSegment.StartByte;
                    dbObjectClone.CoveredLinesOfCode += functionalSegment.LinesOfCode;
                }
            }

            var functionalCode = _dataScrubber.Scrub(dbObjectClone.Code, "floc.scrub");

            dbObjectClone.TotalLoc        = dbObjectClone.Code.Split('\n').Length;
            dbObjectClone.TotalCharacters = dbObjectClone.Code.Length;

            dbObjectClone.TotalFloc = functionalCode.Split('\n').Length;
            dbObjectClone.TotalFunctionalCharacters = functionalCode.Length;

            dbObjectClone.CoveredPercent = (decimal)dbObjectClone.CoveredCharacters / dbObjectClone.TotalFunctionalCharacters;

            return(dbObjectClone);
        }
        public override string FormatCodeWithHighlights(string code, List <DbCodeSegment> codeSegments)
        {
            if (codeSegments.Count == 0)
            {
                return(code);
            }
            var codeContents = new StringBuilder(code);
            var offset       = 0;

            foreach (var lineOfCode in codeSegments)
            {
                codeContents.Insert((lineOfCode.StartByte / 2) + offset, this.StartHighlightMarkUp);
                offset += this.StartHighlightMarkUp.Length;
                codeContents.Insert((lineOfCode.EndByte / 2) + offset, this.EndHighlightMarkUp);
                offset += this.EndHighlightMarkUp.Length;
            }
            return(_dataScrubber.Scrub(codeContents.ToString(), "format.scrub"));
        }