This 2 functions will help you start working.
public Repository GetRepository(string i_Workspace, string i_Username, string i_Password, string i_Server)
{
Repository rep;
Server server;
ServerAddress address;
// Create the repository
address = new ServerAddress(i_Server + ":1666");
server = new Server(address);
rep = new Repository(server);
rep.Connection.UserName = i_Username;
Perforce.P4.Options options = new Perforce.P4.Options();
options["Password"] = i_Password;
Environment.SetEnvironmentVariable("P4PASSWD", i_Password);
rep.Connection.Client = new Client();
if (i_Workspace != null && i_Workspace != string.Empty)
{
rep.Connection.Client.Name = i_Workspace;
}
rep.Connection.Connect(options);
rep.Connection.CommandTimeout = System.TimeSpan.Zero;
rep.Connection.Login(i_Password);
return rep;
}
private Client createWorkspace(string i_DepotPath, string i_RootDirectory)
{
string workspaceName = "workspace" + new Random().Next().ToString();
Repository rep = GetRepository(string.Empty);
Client client = new Client();
client.Name = workspaceName;
client.Root = i_RootDirectory;
client.OwnerName = k_DefaultUser;
client.ViewMap = new ViewMap();
client.Options = ClientOption.AllWrite;
client.LineEnd = LineEnd.Local;
client.SubmitOptions = new ClientSubmitOptions(false, SubmitType.SubmitUnchanged);
string depotPath = i_DepotPath + "/...";
String clientPath;
//clientPath = String.Format("//{0}/{1}/...", client.Name, i_DepotPath.Replace("//depot/", string.Empty));
clientPath = "//" + client.Name + "/...";
MapEntry entry = new MapEntry(MapType.Include, new DepotPath(depotPath), new ClientPath(clientPath));
client.ViewMap.Add(entry);
rep.CreateClient(client);
return client;
}