P4.NET - 如何列出用户的工作区?

发布于 2024-10-20 11:00:59 字数 318 浏览 1 评论 0原文

我不是 P4.NET 插件方面的专家,但我想在组合框中显示用户的现有工作区,以便我可以将 p4.Client 设置为所选工作区。

using (var p4 = new P4Connection())
            {
                p4.Connect();
                ???               
            }

如何获取现有工作区的列表? 我认为实现此目的的命令行是

p4 clients -m 100 -u username

I am not an expert in P4.NET plugin, but I would like to show the existing workspaces for a user in a combo box, so that I can set the p4.Client to the selected workspace.

using (var p4 = new P4Connection())
            {
                p4.Connect();
                ???               
            }

How do I get the list of existing workspaces?
I think the command line to achieve this would be

p4 clients -m 100 -u username

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

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

发布评论

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

评论(3

微凉 2024-10-27 11:00:59

如果 P4.Net 的行为与官方 Perforce API 类似,那么您可能需要运行:

p4.Run("clients", "-m 100 -u username")

或类似的命令。受到 P4Ruby 文档的启发。

If P4.Net behaves similar to the official Perforce APIs, then you would likely want to run:

p4.Run("clients", "-m 100 -u username")

or similar. Inspired by the P4Ruby documentation.

堇年纸鸢 2024-10-27 11:00:59

好吧,我别无选择,只能回答自己的问题,因为代码太多,无法作为注释插入 jhwist 答案。对不起,杰维斯特。我别无选择。

@appinger,我希望这个答案对您有所帮助。我花了几个小时才弄清楚这个 api 的工作原理。 :)

cmbBoxPerforceWorkspaceLocation 只是您工作区的组合框。顺便说一句,我正在使用Winforms。

我需要从 Windows 用户名中提取一个短名称。 Windows 用户名通常以 xxxx\\用户名开头。在我的代码中,我从长名称中提取用户名并将其保存为短名称。如果您的网络设置不同,则此代码可能必须相应更改。

让我知道它是否对你有用。

using (var p4 = new P4Connection())
            {
                p4.Connect();
                var longName = WindowsIdentity.GetCurrent().Name;
                var shortname = longName.Substring(longName.IndexOf("\\") + 1);
                var records = p4.Run("clients", "-u", shortname);

                cmbBoxPerforceWorkspaceLocation.Items.Clear();

                foreach (P4Record record in records.Records)
                {
                    cmbBoxPerforceWorkspaceLocation.Items.Add(record["client"]);
                }
            }

Ok I have no choice than answering my own question, because the code would be too much to insert as comments to jhwist answer. Sorry jhwist. I had no choice.

@appinger, I hope you find this answer helpful. Took me hours to figure out this api working. :)

cmbBoxPerforceWorkspaceLocation is just your combobox for your workspaces. I am using Winforms by the way.

I need to extract a shortname from the windows username. Windows username starts usually with xxxx\\username. In my code I extract the username out of the longname and save it as shortname. If your network is set differently this code might have to change accordingly.

Let me know if it worked for you.

using (var p4 = new P4Connection())
            {
                p4.Connect();
                var longName = WindowsIdentity.GetCurrent().Name;
                var shortname = longName.Substring(longName.IndexOf("\\") + 1);
                var records = p4.Run("clients", "-u", shortname);

                cmbBoxPerforceWorkspaceLocation.Items.Clear();

                foreach (P4Record record in records.Records)
                {
                    cmbBoxPerforceWorkspaceLocation.Items.Add(record["client"]);
                }
            }
橘亓 2024-10-27 11:00:59

P4.Net 的设计类似于脚本 API,而脚本 API 又是围绕命令行界面设计的。它绝对没有直观的面向对象的界面……这在一开始是令人反感的。但是,如果您从命令行(esp -ztag 标志)开始并将应用程序所需的所有数据/操作组合在一起,您会发现使用 P4.Net 非常容易。由于它与所有脚本 API 类似,因此如果您愿意,您会发现很自然地选择 Python 或 Ruby :-)

P4.Net is designed to be similar to the scripting APIs, which in turn are designed around the command line interface. It definitely does not have a intuitive object-oriented interface... which is off putting at first. But if you start from the command-line (esp -ztag flag) and piece together all data/actions your app needs, you will find it pretty easy to use P4.Net. And since it's similar to all the scripting APIs, you'll find it natural to pickup Python or Ruby if you wish :-)

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