Question

I am trying to develop a C# based build tool using p4api.net apis. I am new to perforce p4api.net. I followed the instructions given in p4api.net library downloaded from their site, but was never successful in running a basic command on perforce. I am attaching piece of code which is supposed to fetch clients from Perforce. Please correct it, if am wrong. The code throws a run time error (unhandled expection) while executing GetClients().

static void Main(string[] args)
{
    string uri = "perforce:1666";
    string user = "User1";

    Server server = new Server(new ServerAddress(uri));
    Repository rep = new Repository(server);
    Connection con = rep.Connection;

    con.UserName = user;
    con.Client = new Client();

    // connect to the server
    con.Connect(null);

    // run the command against the current repository
    IList<Client> changes = rep.GetClients(null);
}

Any useful guide to perforce C# documents/examples would be appreciated.

Thanks, Madhu

Was it helpful?

Solution

Are you sure that the exception is coming from GetClients? I ran your code successfully, but when I changed uri to a non-existent server:port I get the unhandled exception at con.Connect(null).

Confirm that you do have access to a perforce:1666 server with User1 and that User1 does not require a password on that server.

OTHER TIPS

tickets are granted to the user by p4 login. If you login with P4V or another client the ticket should still be valid until expiration unless you explicitly p4 logout. You can create this credential in P4API.NET after you connect and before you run a command:

        // connect to the server
        con.Connect(null);
        string password = "pw";
        Credential cred = con.Login(password, null, null);
        con.Credential = cred;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top