我正在使用 p4api.net 编写一个 VS C# 应用程序来访问 P4 服务器。P4V 应用程序使用给定的用户/密码访问存款罚款。使用 p4api.net API,代码使用从表单传入的服务器/用户/密码字符串无一例外地执行 Connect() 和 Login() 方法:
rep.Connection.Connect(options);
rep.Connection.Login(password, options);
下面是实际代码:
String conStr = mServerConnection.Text;
String user = mUserText.Text;
String password = mPaswordTxt.Text;
try
{
Server server = new Server(new ServerAddress(conStr));
rep = new Repository(server);
rep.Connection.UserName = user;
Options options = new Options();
Options["Password"] = password;
rep.Connection.Client = new Client();
rep.Connection.Connect(options);
rep.Connection.Login(password, options);
}
catch (Exception ex)
{
rep = null;
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
然而,在另一个访问 P4“//depot”根目录的调用期间,API 调用 _repository.GetDepotDirs() 将返回“Perforce Password (P4PASSWD) invalid or unset”异常。请看下面的代码:
public bool Expand()
{
if (String.IsNullOrEmpty(depotPath))
return false;
// if we have the depot path, get a list of the subdirectories from the depot
if (!String.IsNullOrEmpty(depotPath))
{
IList<string> subdirs = _repository.GetDepotDirs(null, String.Format("{0}/*", depotPath));
我在某处读到需要设置环境变量 P4TICKETS,所以我在 DOS 提示符下进行了设置:
p4 set P4TICKETS=C:\Documents and Settings\my_user_name
但这并没有解决问题。我会很感激你的帮助。谢谢。