我是c#中P4api的新用户。我想通过C#在Perforce中打开一个文件进行编辑。
如何访问Perforce中的“depot”?
如何选择a文件并将其打开进行编辑?
如何在c#中实现程序?
它是与Perforce Server连接的代码
public void Connection()
{
Repository rep = null;
Server server = null;
try
{
// ** Initialise the connection variable **//
string uri = "perforcep4:1666";
string user = "9955";
string ws_client = "9955_7111";
// ** Define the server, repository and connection **//
server = new Server(new ServerAddress(uri));
rep = new Repository(server);
Connection con = rep.Connection;
// ** Use the connection varaibles for this connection **//
con.UserName = user;
con.Client = new Client();
con.Client.Name = ws_client;
// ** Connect to the server **//
con.Connect(null);
}
catch (Exception ex)
{
rep = null;
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
现在这是我编写的用于在Perforce中打开文件进行编辑的功能。
public void CheckOutFile()
{
connection();
DepotPath path = new DepotPath("//depot/main/src/...");
P4Command cmd = new P4Command(rep, "edit", true, String.Format("{0}/...", path));
P4CommandResult result = cmd.Run();
}
此函数调用函数“connection”以创建与perforce服务器的连接。但我不知道如何在仓库中搜索文件?我的函数打开仓库中的所有文件进行编辑,这不是我的愿望。
答案 0 :(得分:1)
我假设您没有从服务器运行此代码。 要更改文件,您需要执行以下步骤。
同步您的工作区(使用p4v,您将获得命令)。
创建更改列表
//creation of new changelist
public Changelist CreateNewChangelistInWorkspace(string workspace_name, string change_description)
{
Repository rep = P4Core.Instance.GetRepository(workspace_name);
Client client = rep.GetClient(workspace_name);
client.Host = string.Empty;
rep.UpdateClient(client);
//creating changelist
Changelist cl = new Changelist();
cl.Description = change_description;
cl.ClientId = workspace_name;
cl = rep.CreateChangelist(cl);
return cl;
}
编辑您的文件 - 这些文件现在位于您的计算机中,因此您无需进行编辑。
协调(p4v将为您提供命令)(并将文件附加到步骤2中创建的更改列表)。
提交更改列表(changelist.submit())+ repository.updatechangelist(changelist))。