使用 .NET 获取 Perforce 凭证
很多时候,当我第一次使用需要强制访问的应用程序(Visual Studio、虚幻编辑器)时,它会弹出一个对话框,用户可以在其中输入他们的信息(用户、工作区等)。有谁知道在 .NET 中做到这一点的方法吗?
Lots of times when I use an application that needs perforce access (Visual Studio, Unreal Editor) when I first use it, it will pop up a dialog where the user can enter their information (user, workspace, etc). Does anyone know of a way to do this in .NET?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能看到的是 Perforce SCC 插件的登录对话框。 IDE(例如 Visual Studio)有一个标准 API 可以与源代码控制系统进行通信,但我相信您必须与 Microsoft 签署 NDA(或至少向 Microsoft 支付费用)才能针对它进行编程。
SCC API 一般做什么?
What you're probably seeing is the login dialog from the Perforce SCC plugin. There is a standard API for IDEs (e.g. Visual Studio) to communicate with source control systems, but I believe you have to sign an NDA with (or at least pay a fee to) Microsoft in order to program against it.
what in general does the SCC API do?
P4COM 和 P4.Net 是允许您使用 .NET 语言(以及其他语言)连接 Perforce 的 API。
P4COM and P4.Net are APIs that allow you to interface to Perforce with .NET languages (among others).
Perforce 将客户端设置(例如用户、服务器:端口、客户端等)存储在环境变量中,即 P4USER、P4PORT、P4CLIENT。
在 Windows 上,这些变量存储在注册表中(尽管如果您在 Cygwin 下运行 Windows,它们将作为环境变量存储和读取)。
您可以使用 perforce 命令
p4 set
查看这些变量 - 这将显示当前在该计算机上设置的所有变量。有关所有 perforce 变量的更多信息,请阅读此
无论您是使用
System.Diagnostics.Process
通过 .NET 直接调用p4.exe
,还是使用可用的库之一(例如P4.NET)
或P4COM
那么您运行的任何命令都将使用这些设置作为默认设置。如果您想通过在 .NET 中弹出一个对话框来覆盖这些默认设置,那么您需要自己编写代码。
作为使用 P4COM 的示例,那么您' d 执行以下操作:
1) 创建您自己的对话框来获取您想要的信息,例如用户、客户端等
2)创建一个p4实例,即
P4COM.p4 myp4 = new P4COM.p4();
3) 设置您想要的连接参数,即
myP4.User = 'UserVal'
4) 调用 p4.connect 即
myp4.Connect();
请注意,在 P4COM 中,新创建的 p4 实例类上的各种属性将包含用户、端口等的当前默认值,因此您也可以阅读首先将它们呈现在对话框中,供用户根据需要进行更改。
Perforce stores client side settings such as user, server:port, client etc in environment variables i.e P4USER, P4PORT, P4CLIENT.
On Windows, these variables are stored in the registry ( though if you ran on Windows under say Cygwin they will be stored and read as environment variables ).
You can view these variables using the perforce command
p4 set
- this will display all variables currently set on this machine.For more info about all perforce variable then read this
Whether you call
p4.exe
directly through .NET by usingSystem.Diagnostics.Process
or whether you use one of the available libraries such asP4.NET
orP4COM
then any commands you run will use these settings as default.If you want to override these default settings by popping up a dialog box in .NET then you'll need to code this yourself.
As an example using P4COM then you'd do the following:
1) Create your own dialog to get the info you want such user, client etc
2) Create a p4 instance i.e
P4COM.p4 myp4 = new P4COM.p4();
3) Set the connection parameters you want i.e
myP4.User = 'UserVal'
4) Call p4.connect i.e
myp4.Connect();
Note that in P4COM, the various properties on a newly created p4 instance class will contain the current defaults for user, port etc so you could also read these first then present them in a dialog box to the user for them to change if needed.