private string CreateCommentedCode(AnnotationList annotations) { var file = annotations.Filename + ".phpvhbackup"; if (!File.Exists(file)) { Cli.WriteLine("Could not find ~Red~{0}~R~", file); return null; } var code = File.ReadAllText(file); var isPhpless = Regex.Matches(code, @"<\?[^=]").Count == 0; string commentedCode; if (isPhpless) { var annot = new Annotation() { HitCount = annotations.Items.First().HitCount }; commentedCode = CreateComment(annot) + code; } else { commentedCode = annotations.Items .OrderByDescending(z => z.Index) .Select(z => new { Index = z.Index, Comment = CreateComment(z) }) .Where(z => z.Index < code.Length) .Aggregate( new StringBuilder(code), (sb, z) => sb.Insert(z.Index, z.Comment)) .ToString(); } return commentedCode; }
private string CreateComment(Annotation annotation) { return string.Format( "\r\n/*\r\n{0}\r\nhit count: {1}\r\n{0}\r\n*/\r\n", new string('-', 32), annotation.HitCount); }