Introduction
This tool allows the user to get notifications about changes made in the TFS project. It also provides a quick way to see the project's history and changeset.
Useful when developing in teams - the team leader (or code reviewer) gets a notification whenever a change is made.
Also handy for the developers in the project in order to know what other developers are doing or when a CR was done to their code.
Background
For those less familiar with TFS - Team Foundation Server is a source control product developed by Microsoft. It is similar to other popular source controls such as SVN and GIT. Once you set up a server (either at your work environment or at home), you need to connect to it using your preferred method (for instance Visual Studio) and only then can noTiFS connect to it (it uses the current connection to the server).
Using the Code
The code needs references to TFS assemblies (Microsoft.TeamFoundation.Client
).
Connects to the server and retrieves the projects in it:
var tpc = new TfsTeamProjectCollection(new Uri(txtUrl.Text));
_versionControl = tpc.GetService<VersionControlServer>();
var projects = _versionControl.GetAllTeamProjects(true);
Fetches the history of the project:
var changes = _versionControl.QueryHistory
(new ItemSpec(_project, RecursionType.Full), 100).ToArray();
Checks if there are new commits (items which are not in the current array):
var commits = GetHistory(path);
var newCommits = commits.Where
(commit => _commits[path].All(c => !c.Equals(commit))).ToList();
_commits[path] = commits.ToArray();
if (first)
{
first = false;
continue;
}
foreach (var commit in newCommits)
{
Notify(commit);
}
Opens the history window:
private void btnHistory_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(txtTfPath.Text))
{
throw new Exception("Enter tf.exe path");
}
if (!File.Exists(txtTfPath.Text))
{
throw new Exception("TF exe not found - " + txtTfPath.Text);
}
var info = new ProcessStartInfo(txtTfPath.Text)
{
Arguments = "history /recursive " + _project,
UseShellExecute = false,
CreateNoWindow = true
};
Process.Start(info);
}
catch (Exception ex)
{
ShowError(ex);
}
}
Notifies the user of the change - uses NotifyForm
:
private void Notify(CommitInfo commit)
{
try
{
if (InvokeRequired)
{
BeginInvoke((Action)(() => Notify(commit)));
return;
}
var msg = string.Format
("New Commit - {0} : {1}\n{2}\n{3}", commit.Project, commit.Commiter,
commit.Time, commit.Comment);
NotifyForm.Show(msg, OnHist);
}
catch
{
}
}