使用 TFS SDK 从 TFS 获取所有文件夹

发布于 2024-08-21 04:27:56 字数 1469 浏览 5 评论 0原文

我正在创建一个 TFS 工具,它将从 TFS 服务器获取“变更集信息”。

现在,我想提供一个“TFS浏览器”,以便用户可以浏览他想要从中获取信息的“分支/文件夹”。

我正在使用 TreeView 控件和 GetItems 函数从 TFS 获取项目的路径:

private void treeView1_BeforeExpand(object sender, TreeViewCancelEventArgs e)
{
    e.Node.Nodes.RemoveAt(0);
    RecursionType recursion = RecursionType.OneLevel;
    Item[] items = null;

    // Get the latest version of the information for the items.
    ItemSet itemSet = sourceControl.GetItems(e.Node.Tag.ToString(), recursion);
    items = itemSet.Items;

    foreach (Item item in items)
    {
        if (item.ServerItem == e.Node.Tag.ToString()) //Skip self
            continue;

        string filename = Path.GetFileName(item.ServerItem);

        if (Path.GetExtension(filename) == "")
        {
            TreeNode node = new TreeNode(filename, new TreeNode[] { new TreeNode() });
            node.Tag = item.ServerItem;
            e.Node.Nodes.Add(node);
        }
    }
}

下面的代码演示了单击节点中的“展开”按钮后,应用程序将“查询”项目位于当前“分支”(e) 之下。

但是,我不想将文件包含到浏览器中。作为快速而肮脏的检查,我正在检查“路径”是否有扩展名,如果没有,则假设它是一个目录并显示它。一切都很好,直到我发现我们有一个名为“v1.1”的文件夹。

有一个解决方案。我可以重新调用 GetItems 并检查其内容。根据 MSDN:

如果路径参数是一个文件, 返回一组包含的项目 只是那个文件。如果路径是 文件夹,返回一组项目 包含该文件夹中的所有项目。如果 该路径包含通配符 字符,返回一组项目 匹配的指定文件夹 通配符。

但是,每次调用 GetItems 大约需要一秒钟,如果文件夹包含多个文件,则节点的“扩展”将永远持续下去。

那么,有没有办法从 TFS 获取所有“文件夹”?或者任何其他想法如何检查路径是文件夹还是文件?

谢谢!

I am creating a TFS tool that will get "changeset information" from the TFS server.

Now, I want to provide a "TFS Browser" so that the user can browse what "branch/folder" he wants to fetch information from.

I am using a TreeView control and the GetItems function to get the items' path from TFS:

private void treeView1_BeforeExpand(object sender, TreeViewCancelEventArgs e)
{
    e.Node.Nodes.RemoveAt(0);
    RecursionType recursion = RecursionType.OneLevel;
    Item[] items = null;

    // Get the latest version of the information for the items.
    ItemSet itemSet = sourceControl.GetItems(e.Node.Tag.ToString(), recursion);
    items = itemSet.Items;

    foreach (Item item in items)
    {
        if (item.ServerItem == e.Node.Tag.ToString()) //Skip self
            continue;

        string filename = Path.GetFileName(item.ServerItem);

        if (Path.GetExtension(filename) == "")
        {
            TreeNode node = new TreeNode(filename, new TreeNode[] { new TreeNode() });
            node.Tag = item.ServerItem;
            e.Node.Nodes.Add(node);
        }
    }
}

The code below demonstrates that after clicking the "expand" button from a node, the app will "query" the items that are below the current "branch" (e).

However, I don't want to include files to the browser. As a quick and dirty check, I am checking if the "path" has an extension and if not, assume that it is a directory and show it. All was good until I discovered that we have a folder named "v1.1".

There is a solution. I can re-invoke GetItems and check its content. According to MSDN:

If the path argument is a file,
returns a set of Items that contain
just that file. If the path is a
folder, returns a set of Items that
contain all items in that folder. If
the path contains a wildcard
character, returns a set of Items in
the specified folder that match the
wildcard.

However, each call to GetItems take roughly a second and if a folder contains multiple files, the "expansion" of the node takes forever.

So, is there a way to just get all the "folders" from TFS? Or any other idea how to check if a path is a folder or a file?

Thanks!

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

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

发布评论

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

评论(2

笨死的猪 2024-08-28 04:27:57

我刚刚找到的一种解决方案是使用 GetFileTypes 方法来检索在服务器上注册的不同扩展名。然后根据这些扩展检查每个“项目”,如下所示:

if (!Extensions.Contains(Path.GetExtension(item.ServerItem).Replace(".","").ToLower()))
{
    //Add Node
}

但是,这并不是真正的万无一失。如果文件夹名为 FOLDER.DLL 怎么办?

One solution that I have just found is to use the GetFileTypes method to retrieve the different extensions registered on the server. Then check every "item" against these extensions like so:

if (!Extensions.Contains(Path.GetExtension(item.ServerItem).Replace(".","").ToLower()))
{
    //Add Node
}

However, this is not really fool proof. What if a folder is named FOLDER.DLL?

゛清羽墨安 2024-08-28 04:27:56

Item 似乎有一个名为 .ItemType 的成员。你可以对照一下。

It seems that there is a member called .ItemType for Item. You can check against that.

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