简体   繁体   English

无法检索perforce客户端

[英]Cannot retrieve perforce clients

I am trying to develop a C# based build tool using p4api.net apis. 我正在尝试使用p4api.net API开发基于C#的构建工具。 I am new to perforce p4api.net. 我是perforce p4api.net的新手。 I followed the instructions given in p4api.net library downloaded from their site, but was never successful in running a basic command on perforce. 我遵循从其站点下载的p4api.net库中给出的说明,但是在perforce上运行基本命令始终未能成功。 I am attaching piece of code which is supposed to fetch clients from Perforce. 我附上了一段应该从Perforce获取客户端的代码。 Please correct it, if am wrong. 如果有误,请更正。 The code throws a run time error (unhandled expection) while executing GetClients(). 该代码在执行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);
}

Any useful guide to perforce C# documents/examples would be appreciated. 任何有用的perforce C#文档/示例指南都将不胜感激。

Thanks, Madhu 谢谢,Madhu

tickets are granted to the user by p4 login. 通过p4登录将票证授予用户。 If you login with P4V or another client the ticket should still be valid until expiration unless you explicitly p4 logout. 如果您使用P4V或其他客户端登录,那么该票证在到期之前应该仍然有效,除非您明确地注销了p4。 You can create this credential in P4API.NET after you connect and before you run a command: 在连接之后并且在运行命令之前,可以在P4API.NET中创建此凭据:

        // connect to the server
        con.Connect(null);
        string password = "pw";
        Credential cred = con.Login(password, null, null);
        con.Credential = cred;

Are you sure that the exception is coming from GetClients? 您确定异常来自GetClients吗? I ran your code successfully, but when I changed uri to a non-existent server:port I get the unhandled exception at con.Connect(null). 我成功运行了您的代码,但是当我将uri更改为不存在的server:port时,我在con.Connect(null)处收到未处理的异常。

Confirm that you do have access to a perforce:1666 server with User1 and that User1 does not require a password on that server. 确认您确实可以使用User1访问perforce:1666服务器,并且User1不需要该服务器上的密码。

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

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