尝试使用 TFS 查看项目上的给定文件名及其行号来了解代码的编写者

发布于 2024-11-24 13:01:07 字数 328 浏览 0 评论 0原文

我正在尝试编写一个使用 TFS API 的小型应用程序。

我将有一个方法,该方法采用三个参数,例如项目名称、文件名和行号。然后它给了我编写该部分代码的人的名字。

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

     //implementation

     return programmerName;
}

我对 TFS API 进行了一些搜索,但找不到解决此问题的确切信息。 TFS API 是否提供此信息?

提前致谢,

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

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

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 ?

Thanks in advance,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

口干舌燥 2024-12-01 13:01:07

很好的问题。但是,没有直接的方法可以用来执行此操作。相反,您需要执行以下操作,

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

一些悬而未决的问题,
- 在文件开发过程中,同一行或同一代码块多次被多个用户修改。你打算如何处理这个问题?

查看这些博客文章,它们可能会帮助您开始连接到 TFS、使用 versionControlServer 获取文件的更改集并循环更改集。 http://geekswithblogs.net/TarunArora/category/12804.aspx

HTH
干杯,塔伦

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

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?

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
Cheers, Tarun

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文