【问题标题】:How can I open a file for edit (check-out) in Perforce using p4api.net.dll如何使用 p4api.net.dll 在 Perforce 中打开文件进行编辑(签出)
【发布时间】:2013-06-20 12:39:22
【问题描述】:

我是 C# 中的 P4api 的新用户。我想通过 C# 在 Perforce 中打开一个文件进行编辑。

如何访问 Perforce 中的“仓库”?
如何选择一个文件并打开它进行编辑?
程序在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 服务器的连接。但我不知道如何在仓库中搜索文件?我的函数会打开 depot 中的所有文件进行编辑,这不是我的意愿。

【问题讨论】:

  • 如果你想打开一个特定的文件,而不是多个文件,那么将你的路径从 '//depot/main/src/...' 更改为 '//depot/main/src/ my/specific/file.cs'

标签: c# perforce vcs-checkout


【解决方案1】:

我假设您没有从服务器运行此代码。 要更改文件,您需要执行以下步骤。

  1. 同步您的工作区(使用 p4v 您将获得命令)。

  2. 创建更改列表

    //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. 编辑您的文件 - 文件现在位于您的计算机中,因此您不需要 perforce 进行编辑。

  4. 协调(p4v 会给您命令)(并将文件附加到步骤 2 中创建的更改列表)。

  5. 提交变更列表 (changelist.submit()) + repository.updatechangelist(changelist))。

【讨论】:

  • 我找到了另一个要打开编辑的 Weg。但现在我不能“提交”,因为必须更改“描述”字段。当我运行我的程序时,我变成了这个错误“p4api.net.dll 中发生了‘Perforce.P4.P4Exception’类型的第一次机会异常。p4api.net 中发生了‘Perforce.P4.P4Exception’类型的未处理异常。 dll”。有人有想法吗?谢谢
  • 我错过了“协调”命令。我使用 p4win 但不是 p4v。我没有找到另一个命令,它做同样的事情,比如协调。有人有想法吗?谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-19
  • 2013-06-25
  • 1970-01-01
  • 2020-04-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多