Perforce API for the .Net CLR P4.Net

P4Connection Class

A connection to a Perforce server instance.

For a list of all members of this type, see P4Connection Members.

System.Object
   P4API.P4Connection

[Visual Basic]
Public Class P4Connection
    Implements IDisposable
[C#]
public class P4Connection : IDisposable

Remarks

The P4Connection class is the main player in P4.Net. This represents a connection to the Perforce server. Every utility that uses P4.Net will have some variation of the following code:

P4Connection p4 = new P4Connection();
p4.Connect();

// Run some commands
p4.Disconnect();

Rule number 1: Always remember to disconnect. This frees unmanaged memory, and cleanly disconnects from the Perforce server. P4Connection implements IDisposable, and the Dispose and Disconnect methods can be used interchangeably.

P4.Net is based off the command-line syntax (as are most other Perforce APIs). Almost all of the commands you issue in P4.Net will use the same arguments as the p4 client executable. For example, say you need to find the latest submitted changelist under a given path (//depot/path).

From the command line:

c:\> p4 changes -m1 -s submitted //depot/path/...

From P4.Net:

P4Connect p4 = new P4Connection();
p4.Connect();
P4Recordset changes = p4.Run("changes", "-m1", "-s", "submitted", "//depot/path/...");
p4.Disconnect();

If you don’t know what all the arguments for p4 changes mean, then p4 help changes is your best friend. The first step in building anything with P4.Net, is to know the exact command lines you’d run manually.

Requirements

Namespace: P4API

Assembly: p4api (in p4api.dll)

See Also

P4Connection Members | P4API Namespace