[英]Connect and check out methods
我有一种方法可以连接到tfs并检出文件。 我必须将其分为2种方法,因为它们不会连续发生。 但是我不确定如何将其分为两种方法,因为如果执行检出操作,这意味着我必须再次获取凭据和项目集合?
public static void Connect(String server, string path)
{
try
{
Uri serverUri = new Uri(server + "/tfs");
ICredentialsProvider credentials = new UICredentialsProvider();
TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(serverUri, credentials);
tpc.EnsureAuthenticated();
VersionControlServer versionControl = tpc.GetService<VersionControlServer>();
Workspace workspace = versionControl.TryGetWorkspace(path);
workspace.PendEdit(path);
}
我建议您不要将函数设为静态,而是可以将变量仅存储在类级别(如果它们是静态的,则仍可以将它们存储在类级别,但是至少这样可以对寿命有一定的范围:
public class TfsWrapper
{
private TfsTeamProjectCollection tpc = null;
private VersionControlServer versionControl = null;
public TfsWrapper(string server, ...)
{
try
{
Uri serverUri = new Uri(server + "/tfs");
ICredentialsProvider credentials = new UICredentialsProvider();
tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(serverUri, credentials);
tpc.EnsureAuthenticated();
versionControl = tpc.GetService<VersionControlServer>();
}
}
public void Checkout(string path)
{
Workspace workspace = versionControl.TryGetWorkspace(path);
workspace.PendEdit(path);
}
我建议您使用此代码,他会处理许多服务器和凭据之间的封装和重构方面
链接: http : //blogs.msdn.com/b/buckh/archive/2012/03/10/team-foundation-version-control-client-api-example-for-tfs-2010-and-newer.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.