Created
November 26, 2015 09:03
-
-
Save borismod/f0960609db8ce415cc3c to your computer and use it in GitHub Desktop.
TFS get annotation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TeamFoundationAnnotationRetriever | |
{ | |
private readonly Regex m_Regex = new Regex(@"^(?<changeset>\d+)(?<codeLine>.*)", RegexOptions.Compiled | RegexOptions.Multiline); | |
public List<Changeset> GetAnnotations(string filepath, string codeText) | |
{ | |
var versionControlServer = CreateVersionControlServer(); | |
return m_Regex.Matches(ExecutePowerTools(filepath)) | |
.Cast<Match>() | |
.Where(m => m.Groups["codeLine"].Value.Contains(codeText)) | |
.Select(v => versionControlServer.GetChangeset(int.Parse(v.Groups["changeset"].Value), false, false)) | |
.ToList(); | |
} | |
private static VersionControlServer CreateVersionControlServer() | |
{ | |
var projectCollection = new TfsTeamProjectCollection(new Uri(@"TFS URL")); | |
var versionControlServer = projectCollection.GetService<VersionControlServer>(); | |
return versionControlServer; | |
} | |
private static string ExecutePowerTools(string filepath) | |
{ | |
using (var process = Process.Start(TfptLocation, string.Format("annotate /noprompt {0}", filepath))) | |
{ | |
process.WaitForExit(); | |
return process.StandardOutput.ReadToEnd(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment