Houman
Houman

Reputation: 66320

P4.NET - How to list user's workspaces?

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

Upvotes: 3

Views: 2782

Answers (3)

Shawn
Shawn

Reputation: 1

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 :-)

Upvotes: 0

Houman
Houman

Reputation: 66320

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"]);
                }
            }

Upvotes: 2

user100766
user100766

Reputation:

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.

Upvotes: 4

Related Questions