Esempio n. 1
0
        private static string FixAttributeContent(Match m, CompetitionTarget competitionTarget)
        {
            var attributeStartText = m.Groups[1].Value;
            var attributeEndText   = m.Groups[4].Value;

            var attributeWithoutBraces        = !attributeStartText.EndsWith("(");
            var attributeWithoutMinMax        = !m.Groups[2].Success;
            var attributeHasAdditionalContent = !attributeEndText.StartsWith(")");

            var result = new StringBuilder(m.Length + 10);

            result.Append(attributeStartText);

            if (attributeWithoutBraces)
            {
                result.Append('(');
                AppendMinMax(result, competitionTarget);
                result.Append(')');
            }
            else
            {
                AppendMinMax(result, competitionTarget);
                if (attributeWithoutMinMax && attributeHasAdditionalContent)
                {
                    result.Append(", ");
                }
            }

            result.Append(attributeEndText);
            return(result.ToString());
        }
Esempio n. 2
0
        private static bool TryFixBenchmarkAttribute(
            AnnotateContext annotateContext,
            string fileName, int firstCodeLine,
            CompetitionTarget competitionTarget)
        {
            var result          = false;
            var sourceFileLines = annotateContext.GetFileLines(fileName);

            for (var i = firstCodeLine - 2; i >= 0; i--)
            {
                var line = sourceFileLines[i];
                if (_breakIfRegex.IsMatch(line))
                {
                    break;
                }

                var line2 = _attributeRegex.Replace(
                    line,
                    m => FixAttributeContent(m, competitionTarget), 1);
                if (line2 != line)
                {
                    annotateContext.ReplaceLine(fileName, i, line2);
                    result = true;
                    break;
                }
            }
            return(result);
        }
Esempio n. 3
0
        private static void AppendMinMax(StringBuilder result, CompetitionTarget competitionTarget)
        {
            if (!competitionTarget.IgnoreMin)
            {
                result.Append(competitionTarget.MinText);
                result.Append(", ");
            }

            // Always prints
            result.Append(competitionTarget.MaxText);
        }
Esempio n. 4
0
        private static bool TryGetSourceInfo(CompetitionTarget competitionTarget, out string fileName, out int firstCodeLine)
        {
            fileName      = null;
            firstCodeLine = 0;
            var methodSymbols = SymbolHelpers.TryGetSymbols(competitionTarget.Target.Method);

            if (methodSymbols != null)
            {
                var count      = methodSymbols.SequencePointCount;
                var docs       = new ISymbolDocument[count];
                var offsets    = new int[count];
                var lines      = new int[count];
                var columns    = new int[count];
                var endlines   = new int[count];
                var endcolumns = new int[count];
                methodSymbols.GetSequencePoints(offsets, docs, lines, columns, endlines, endcolumns);

                fileName      = docs[0].URL;
                firstCodeLine = lines.Min();
            }
            return(fileName != null);
        }
        private bool TryFixBenchmarkResource(
            AnnotateContext annotateContext, string xmlFileName,
            CompetitionTarget competitionTarget)
        {
            var competitionName = competitionTarget.CompetitionName;
            var candidateName   = competitionTarget.CandidateName;

            var xdoc        = annotateContext.GetXmlAnnotation(xmlFileName);
            var competition = GetOrAdd(xdoc.Root, CompetitionTargetHelpers.CompetitionNode, competitionName);
            var candidate   = GetOrAdd(competition, CompetitionTargetHelpers.CandidateNode, candidateName);

            var minText = !competitionTarget.IgnoreMin ? competitionTarget.MinText : null;
            // Always prints
            var maxText = competitionTarget.MaxText;

            SetAttribute(candidate, CompetitionTargetHelpers.MinRatioAttribute, minText);
            SetAttribute(candidate, CompetitionTargetHelpers.MaxRatioAttribute, maxText);

            annotateContext.MarkAsChanged(xmlFileName);

            return(true);
        }