简体   繁体   English

如何使用p4api.net.dll在Perforce中打开文件进行编辑(签出)

[英]How can I open a file for edit (check-out) in Perforce using p4api.net.dll

I am a new user the P4api in c#. 我是C#中的P4api的新用户。 I want to open a file for editing in Perforce through C#. 我想打开一个文件,以通过C#在Perforce中进行编辑。

How can I access the "depot" in Perforce? 如何在Perforce中访问“软件仓库”?
How can I choose the a file and open it for edit? 如何选择一个文件并打开进行编辑?
How shall the procedure be realized in c#? 如何在c#中实现该过程?

That it is the code for the connection with Perforce Server 这是与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);
    }
}

Now this is the function I have writted to open a file for editing in Perforce. 现在,这就是我编写的用于在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();
}

This function calls the function "connection" to create a connection with perforce server. 该函数调用函数“连接”以创建与perforce服务器的连接。 But I don't know how can I search a file in the depot? 但是我不知道如何在软件仓库中搜索文件? My function opens all files in depot for edit and that is not my wish. 我的职能是打开软件仓库中的所有文件进行编辑,这不是我的愿望。

I assume that you not run this code from the server. 我假设您没有从服务器运行此代码。 In order to change file you need to do the folowing steps. 为了更改文件,您需要执行以下步骤。

  1. Sync your workspace (using p4v you will get the command). 同步您的工作空间(使用p4v您将获得命令)。

  2. Create changelist 创建变更清单

     //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; } 
  3. edit your files - The files locate in your computer now so you not need perforce for edit. 编辑文件-文件现在位于您的计算机中,因此您不需要perforce进行编辑。

  4. reconcile (p4v will give you the command) (and will attach the files to the change list created in step 2). 协调(p4v将为您提供命令)(并将文件附加到在步骤2中创建的更改列表中)。

  5. submit the changelist (changelist.submit()) + repository.updatechangelist(changelist)). 提交变更清单(changelist.submit())+ repository.updatechangelist(变更清单)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM