c# - 使用 QueryBuilds 从 TFS 查询构建的性能非常低
问题描述
BuildDetail.KeepForever
我正在尝试访问具有“无限期保留”标志(属性)的本地 TFS 2015 服务器中的每个构建,但该QueryBuilds()
函数需要很长时间才能获取所有构建。
我真正需要的是KeepForever
和DropLocation
属性。
我发现您可以使用该IBuildDetailSpec
界面获得更高的效率,但我找不到我将获得该KeepForever
属性的选项。
我当前的代码片段:
public void BackupOnlyRetainedBuilds(string TeamProjectName, string DestinationPath)
{
defs[...]
Uri configurationServerUri = new Uri("http://builder:8080/tfs");
TfsTeamProjectCollection server = new TfsTeamProjectCollection(configurationServerUri);
//get builds server
buildServer = (IBuildServer)server.GetService(typeof(IBuildServer));
//set up an array of all build definition from a spcific team project.
IBuildDefinition[] bda = buildServer.QueryBuildDefinitions(TeamProjectName);
//check each build definition.
foreach (var buildDefinition in bda)
{
//set an array of builds history.
IBuildDetail[] bha = buildDefinition.QueryBuilds();
//check each build from build history build details.
foreach (var buildDetails in bha)
{
//check if build is retained.
if (buildDetails.KeepForever == true)
{
string dropLocationPath = buildDetails.DropLocation;
//check if drop folder exists.
if (Directory.Exists(dropLocationPath))
{
//create all of the directories.
foreach (string dirPath in Directory.GetDirectories(dropLocationPath, "*",
SearchOption.AllDirectories))
Directory.CreateDirectory(dirPath.Replace(dropLocationPath, DestinationPath));
//copy all the files & Replaces any files with the same name.
foreach (string newPath in Directory.GetFiles(dropLocationPath, "*.*",
SearchOption.AllDirectories))
File.Copy(newPath, newPath.Replace(dropLocationPath, DestinationPath), true);
}
}
}
}
}
解决方案
您可以告诉QueryBuilds
不要从我的修补版本中获取所有构建细节,而只获取您感兴趣的那些tfsbuild.exe
:
buildDetailSpec = this.BuildServer.CreateBuildDetailSpec(...)
buildDetailSpec.QueryDeletedOption = !forDestroy ? QueryDeletedOption.IncludeDeleted : QueryDeletedOption.OnlyDeleted;
buildDetailSpec.InformationTypes = null;
IBuildQueryResult buildQueryResult = this.BuildServer.QueryBuilds(buildDetailSpec);
或者使用QueryBuildsUri
并传递它(string[]) null, QueryOptions.None
:
IBuildDetail[] buildDetailArray = this.BuildServer.QueryBuildsByUri(list2.ToArray(), (string[]) null, QueryOptions.None, QueryDeletedOption.IncludeDeleted);
您可能需要将一组特定InformationTypes
的数据传递给它,具体取决于您在备份工具中所需的数据。
推荐阅读
- java - 如何使用 for 循环将一些数据插入到类的索引数组中以及如何查看它们?
- c# - 实体框架在事务中调用存储过程
- javascript - 上传多个文件(使用ajax)后,拖放不起作用
- python - FailedPreconditionError: Attempting to use uninitialized value training/Adam/*
- sql - 使用一行命令将 nvarchar 转换为 Date 类型
- kubernetes - 如果可以使用副本集创建 pod 和副本,为什么我们需要部署?
- android - 向 Tomcat 机器发送实时开发者通知以进行应用内购买
- elasticsearch - Kibana 不使用现有的 .kibana 索引
- sql - 如何选择某条记录
- mysql - 休眠中的异常:无法创建请求的服务