Team Foundation Server (TFS)工具的亮点之一是文件的版本控制。在TFS中实现文件版本控制的类型:

Microsoft.TeamFoundation.Client.TfsTeamProjectCollection;

Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer;

Microsoft.TeamFoundation.VersionControl.Client.ItemSet;

Microsoft.TeamFoundation.VersionControl.Client.Workspace;

Microsoft.TeamFoundation.VersionControl.Client.GetStatus;

Microsoft.TeamFoundation.VersionControl.Client.PendingChange;

Microsoft.TeamFoundation.VersionControl.Client.Conflict;

1. 访问TFS服务器。

TfsTeamProjectCollection server = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("https://vstf-cooper.com:8080/tfs/learning"));
VersionControlServer controlServer = server.GetService<VersionControlServer>();

2. 获取服务器文件列表。

ItemSet set = controlServer.GetItems(@"$/tfs/path1", VersionSpec.Latest, RecursionType.OneLevel, DeletedState.NonDeleted, ItemType.Folder);
foreach (var item in set.Items)
{
string file = item.ServerItem;
}

3. 创建工作区,建立本地映射。工作区文件的影射可以到非常小的子集,如服务器有很多文件夹结点,用户只想更新一个文件夹下文件,则可以直接映射到待更新文件的父文件夹。

Workspace tfsWSpace = controlServer.CreateWorkspace("MyWorkSpace", @"cooper");
tfsWSpace.Map(@"$/tfs/", @"c:\myTFS");

4. 检测服务器文件是否存在。

bool isSourceExist = controlServer.ServerItemExists("$/tfs/path1", ItemType.Folder);

5. 删除服务器上某路径下的文件。

                    // check if destination folder exist, if yes, delete existing folder first
bool isFolderExist = controlServer.ServerItemExists("$/tfs/path1", ItemType.Folder);
if (isFolderExist)
{
// download server files to local
GetStatus status = tfsWSpace.Get(new string[] { "$/tfs/path1"}, VersionSpec.Latest, RecursionType.Full, GetOptions.Overwrite); // delete server files, deleting requires the files exist in local first
int toDelete = tfsWSpace.PendDelete(item.TargetPath, RecursionType.Full);
if (toDelete > )
{
// get pending items in current work space
PendingChange[] pendings = tfsWSpace.GetPendingChanges();
if (pendings.Length > )
{
Conflict[] conflicts = tfsWSpace.QueryConflicts(new string[] { "$/tfs/path1" }, true);
foreach (Conflict conflict in conflicts)
{
conflict.Resolution = Resolution.AcceptMerge;
tfsWSpace.ResolveConflict(conflict);
} // checkin pending changes, return the changeset number as int32
int changeSetNumber = tfsWSpace.CheckIn(tfsWSpace.GetPendingChanges(), "Tool:Delete existing folder and preparing for branch");
}
}
}

6. 添加新文件。首先确保本地文件存在。

// add local files to server, return the total number added
int totalAddFolders = tfsWSpace.PendAdd(@"c:\myTFS\path1\newFolder");
tfsWSpace.CheckIn(tfsWSpace.GetPendingChanges(), "Tool:Add Folder");

7. 分支文件。分支文件,若是文件夹到文件夹,则目标文件夹必须不存在,其父文件夹必须存在。

//Branch items from Developement to Publication
int changeSetID = controlServer.CreateBranch("$/tfs/path1/original", "$/tfs/path1/target", VersionSpec.Latest);
Changeset changeSet = controlServer.GetChangeset(changeSetID);
changeSet.Comment = "Tool:Branch from original to target.";
changeSet.Update();

Team Foundation API - 编程控制文件版本的更多相关文章

  1. Team Foundation API - 编程访问 WorkItem

    Team Foundation Server (TFS)工具的亮点之一是管理日常工作项, 工作项如Bug, Task,Task Case等. 使用TFS API编程访问TFS服务器中的工作项, 步骤如 ...

  2. ORA-00214: control file 控制文件版本不一致

    故障现象:今日学习oracle控制文件移动和修改,发现本机安装oracle数据库启动时只使用了一个控制文件.如下:SQL> select * from V$controlfile; STATUS ...

  3. Team Foundation 中的错误和事件消息

    Visual Studio Team System Team Foundation 中的错误和事件消息 Team Foundation 通过显示错误消息和事件消息来通知您操作成功以及操作失败.一部分错 ...

  4. Team Foundation Server 2013 with Update 3 Install LOG

    [Info   @10:14:58.155] ====================================================================[Info   @ ...

  5. 测试环境搭建心得 vs2008+SQL2008 PHP+APACHE+mysql Team Foundation Server2013

    大四即将结束,大学的最后一个假期,找到一份实习工作,担任测试工程师.在过年前的最后一周入职,干了一周的活儿.主要工作就是搭建测试环境. VMware 主要熟悉VMware软件,装系统基本都没什么问题. ...

  6. Oracle的控制文件

    一.控制文件 oracle的控制文件是极其重要的文件,它是一个较小的二进制文件. 记录了当前数据库的结构信息,同时也包含数据文件及日志文件的信息以及相关的状态,归档信息等等  在参数文件中描述其位置, ...

  7. Oracle 控制文件(CONTROLFILE)

    一.Oracle 控制文件 为二进制文件,初始化大小由CREATE DATABASE指定,可以使用RMAN备份 记录了当前数据库的结构信息,同时也包含数据文件及日志文件的信息以及相关的状态,归档信息等 ...

  8. Oracle 控制文件损坏解决方案

    Oracle 控制文件损坏解决方案 故障一:丢失(损坏)一个控制文件 前台报错:ORA-00205:error in identifying control file,check alert log ...

  9. 初探Team Foundation Server (TFS) 2015 REST API

    REST是一种简洁方便的Web服务,通过基于http协议的远程通信,可以为多种客户端程序提供远程服务,大幅提高了服务器系统的可扩展性. 微软宣布从Team Foundation Server 从201 ...

随机推荐

  1. hdu 1520

    Anniversary party Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  2. PHP可变长函数方法介绍

    1.三个重要函数 func_num_args()  返回实参个数 func_get_arg(i)    返回某个实参的值       func_get_args()        以数组的形式返回实参 ...

  3. jQuery修改后代、兄弟样式

    <div> <div >1</div> <div class="one"> 2 <div>2_1 <div> ...

  4. Storm(2) - Log Stream Processing

    Introduction This chapter will present an implementation recipe for an enterprise log storage and a ...

  5. JDE910笔记1--基础介绍及配置[转]

    1.一般JDE部署后环境: DV:开发环境 PY:测试环境 PD:正式环境 根据端口号区分不同环境,可配置.同时,JDE默认使用分发服务器,不同环境连接为不同的数据库. 2.命名规范: 自定义项目.函 ...

  6. qt 提高ui响应度

    如何使Qt 平台中的GUI保持响应流畅?一般来说耗时较长的操作,分为计算密集型操作和IO密集型操作,对于这两类操作如何提高响应速度. 而从操作的本质上来说,操作又可分为不可分解操作,如在第三方库中耗时 ...

  7. C# 如何用计时器Timer控件实现停留几秒再做切换窗体的操作

    C# Timer用法及实例详解 关于C# Timer类  在C#里关于定时器类就有3个 C# Timer使用的方法1.定义在System.Windows.Forms里 C# Timer使用的方法2.定 ...

  8. html中offsetTop、clientTop、scrollTop、offsetTop

    HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth scrollHeight: 获取对象的滚动高度. scrollLeft:设置或获取位于对 ...

  9. ubuntu 防火墙 添加策略 解决mysql远程访问问题

    ubuntu 的iptables 文件不在 init.d中 不能 service iptables restart 只修改 /etc/iptables 文件也不管用 sudo iptables -L ...

  10. 工具&符号

    持续更新中...... 1.RPC(Remote Procedure Call Protocol)——远程过程调用协议,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议.RP ...