我怎么能打开一个文件编辑(签出)在Perforce使用p4api.net.dll
本文关键字:dll 签出 Perforce 使用 p4api 编辑 net 一个 怎么能 文件 | 更新日期: 2023-09-27 18:19:07
我是c#中P4api的新用户。我想通过c#在Perforce中打开一个文件进行编辑。
我如何在Perforce中访问"仓库"?
我如何选择文件并打开它进行编辑?
这个过程如何在c#中实现?
它是与Perforce服务器连接的代码
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"函数来创建与force server的连接。但是我不知道怎么在仓库里搜索文件?我的函数打开仓库中的所有文件进行编辑,这不是我的愿望。
假设您没有从服务器上运行这段代码。为了更改文件,您需要执行以下步骤:
-
同步你的工作空间(使用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))。