Click here to Skip to main content
15,886,806 members
Articles / DevOps
Tip/Trick

noTiFS - TFS Commits Notifications

Rate me:
Please Sign up or sign in to vote.
3.00/5 (2 votes)
17 Feb 2017CPOL1 min read 7.2K   96   2   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:

C#
var tpc = new TfsTeamProjectCollection(new Uri(txtUrl.Text));
_versionControl = tpc.GetService<VersionControlServer>();

var projects = _versionControl.GetAllTeamProjects(true);

Fetches the history of the project:

C#
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):

C#
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:

C#
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:

C#
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- No messages could be retrieved (timeout) --