0

我正在尝试使用 p4api.net apis 开发基于 C# 的构建工具。我是 perforce p4api.net 的新手。我按照从他们的网站下载的 p4api.net 库中给出的说明进行操作,但从未成功在 perforce 上运行基本命令。我附上了一段应该从 Perforce 获取客户端的代码。如有错误请指正。代码在执行 GetClients() 时引发运行时错误(未处理的预期)。

static void Main(string[] args)
{
    string uri = "perforce:1666";
    string user = "User1";

    Server server = new Server(new ServerAddress(uri));
    Repository rep = new Repository(server);
    Connection con = rep.Connection;

    con.UserName = user;
    con.Client = new Client();

    // connect to the server
    con.Connect(null);

    // run the command against the current repository
    IList<Client> changes = rep.GetClients(null);
}

任何有关执行 C# 文档/示例的有用指南将不胜感激。

谢谢,马杜

4

2 回答 2

3

票证通过 p4 登录授予用户。如果您使用 P4V 或其他客户端登录,除非您明确 p4 注销,否则票证在到期之前仍然有效。您可以在连接之后和运行命令之前在 P4API.NET 中创建此凭据:

        // connect to the server
        con.Connect(null);
        string password = "pw";
        Credential cred = con.Login(password, null, null);
        con.Credential = cred;
于 2012-07-27T14:17:22.223 回答
2

您确定异常来自 GetClients 吗?我成功运行了您的代码,但是当我将 uri 更改为不存在的服务器:端口时,我在 con.Connect(null) 处得到未处理的异常。

确认您确实可以使用 User1 访问 perforce:1666 服务器,并且 User1 不需要该服务器上的密码。

于 2012-07-27T12:40:17.090 回答