Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

noTiFS - TFS Commits Notifications

0.00/5 (No votes)
17 Feb 2017 1  
An application which communicates with your TFS server - notifies about changes and shows a quick history

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
        {
        }
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here