Click here to Skip to main content
13,260,108 members (46,732 online)
Click here to Skip to main content
Add your own
alternative version

Stats

3.6K views
93 downloads
2 bookmarked
Posted 17 Feb 2017

noTiFS - TFS Commits Notifications

, 17 Feb 2017
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Blondy314
Israel Israel
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionMessage Closed Pin
17-Feb-17 16:06
memberSteve Walker17-Feb-17 16:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 17 Feb 2017
Article Copyright 2017 by Blondy314
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid