试图让谁写的code。通过寻找一个给定的文件名,并使用TFS一个项目行号 [英] Trying to get who wrote the code by looking at a given file name and its line number on a project by using TFS

查看:187
本文介绍了试图让谁写的code。通过寻找一个给定的文件名,并使用TFS一个项目行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个小的应用程序将使用TFS API。

I am trying to write an small application that will use TFS API .

我将有一个方法,而这个方法有三个参数,如项目名称,文件名和行号。然后,它给了我是谁写的code那部分人的姓名。

I will have a method and this method takes three parameters such as project name, filename, and the line number. Then it gives me the name of the person who wrote that part of code.

public string GetProgrammer(string projectname, string file, int linenumber)
{

     //implementation

     return programmerName;
}

我已经做了一些搜索TFS API,但我无法找到解决这一问题的确切信息。是否TFS API提供这些信息?

I have made some search for TFS API but I couldnt find an exact information to solve this problem. Does TFS API provide this information ?

在此先感谢,

推荐答案

非常好的问题。然而,有可以使用这样做没有直接的方法。相反,你需要做到以下几点,

Excellent Question. However, there is no direct method you could use to do this. Instead you will need to do the following,

public string GetProgrammer(string projectname, string file, int linenumber)
{ 
    // 1. Connect To TFS get the project name that you have passed
    var tfs = TfsTeamProjectCollectionFactory
                  .GetTeamProjectCollection(new Uri("TfsUrl"));
    var vsStore = tfs.GetService<VersionControlServer>();
    var myProject = vsStore.TryGetTeamProject(projectName);

    // 2. Use the versionControlServer Service and get a history
    // i.e. all changesets that fall under the parent 'filename' 
    // with recursion.none
    var histories = service.GetBranchHistory(
            new ItemSpec[] { new ItemSpec (filePath, RecursionType.None) },
            VersionSpec.Latest);

    // 3. Loop through each changeset and build your code block adding 
    // the name of the user who owns the changeset in a List. 
    foreach (BranchHistoryTreeItem history in histories[0])
    {
        var change = service.GetChangeset(
            history.Relative.BranchToItem.ChangesetId,
            true, 
            true);

        if (change.WorkItems.ToList().Count == 0)
        {
            // Create your file compiling the changes from each check-in 
            // and lets say store in stream
        }
    }

    // 4. Now pass the line number, in what ever code block it falls 
    // you should get the details of the user, changeset and other details 
    // to return.
    // Query the stream build in the last step for the line number  
    return programmerName;
}

一些悬而未决的问题, - 好几次,在同一行或相当的code中的相同的块是由多个用户在一个文件中的发展修改。如何打算处理这个问题?

Some outstanding questions, - Several times, the same line or rather the same block of code is modified by several users in the development of a file. How to you plan to handle that?

看这些博客文章,可能会帮助您开始在连接到TFS,使用versionControlServer得到的变更,通过变更集文件和环路。 http://geekswithblogs.net/TarunArora/category/12804.aspx

Look at these blog posts that might help you get started on connecting to TFS, using the versionControlServer to get changesets for a file and loop through changesets. http://geekswithblogs.net/TarunArora/category/12804.aspx

HTH 欢呼声中,塔伦

HTH Cheers, Tarun

这篇关于试图让谁写的code。通过寻找一个给定的文件名,并使用TFS一个项目行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆