0

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

Ganesh Sittampalam
  • 28,821
  • 4
  • 79
  • 98

2 Answers2

3

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;
p4bill
  • 109
  • 1
  • Hello again, Thanks for the response. I am failing to fetch credential. Upon login, i get credential to be null. Any ideas? (Fyi pls, in our environment, the server issues tickets which are valid for 12 hours only). Another question, I fail to create a client thru C#. Any clues for this pls. – Madhu Cheluvaraju Jul 30 '12 at 07:30
  • login will return a null credential if the password is incorrect. Are you replacing "pw" with your actual password. The ticket timeout should not be an issue. Contact me at bbaffy at (the company who's api we are discussing) – p4bill Aug 02 '12 at 17:26
2

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.

p4bill
  • 109
  • 1
  • Hey, thanks a ton for the response. It now worked alright. What I did was, I had the perforce client started (that means perforce ticket was on) and re-run my code. How do I resolve this problem? The machine where I run the build tool will not have Perforce client up and running with a valid ticket all the time. – Madhu Cheluvaraju Jul 27 '12 at 13:19