TFS二次开发的数据统计以PBI、Bug、Sprint等为例(一)

在TFS二次开发中,我们可能会根据某一些情况对各个项目的PBI、BUG等工作项进行统计。在本文中将大略讲解如果进行这些数据统计。

  一:连接TFS服务器,并且得到之后需要使用到的类方法。

   /// <summary>
/// tfs的
/// </summary>
private TfsTeamProjectCollection server;
private WorkItemStore workstore;
private TeamSettingsConfigurationService configSvc;
private TfsTeamService teamService;
public String TfsUri { get; set; } /// <summary>
/// 初始化TFSServer
/// </summary>
/// <param name="model"></param>
public TFSServerDto(string tfsUri)
{
this.TfsUri = tfsUri;
Uri uri = new Uri(TfsUri);
server = new TfsTeamProjectCollection(uri);
workstore = (WorkItemStore)server.GetService(typeof(WorkItemStore));
configSvc = server.GetService<TeamSettingsConfigurationService>();
teamService = server.GetService<TfsTeamService>(); }

  二:获取到本TFS Server 指定团队的所有项目

        /// <summary>
/// 获取项目集合
/// </summary>
/// <returns></returns>
public ProjectCollection GetProjectList()
{
return workstore.Projects;
}
public Project GetProject(int projectId)
{
return workstore.Projects.GetById(projectId);
}

  三:根据工作项类型获取工作项集合

        /// <summary>
/// 获取工作项统计
/// </summary>
/// <param name="workitemtype">工作项类型:Bug,Impediment,Product Backlog Item,Task,Task Case</param>
/// <returns></returns>
public WorkItemCollection GetWorkItemCollection(string workitemtype, string projectName)
{
WorkItemCollection queryResults = GetWorkItemCollection(workitemtype,projectName, string.Empty);
return queryResults;
} /// <summary>
/// 获取工作项统计
/// </summary>
/// <param name="workitemtype">工作项类型:Bug,Impediment,Product Backlog Item,Task,Task Case等</param>
/// <param name="condition">查询条件:针对Bug类型的 State=‘New,Approved,Committed,Done,Removed'
/// 针对Impediment类型的State='Open'
/// 针对Product Backlog Item类型的State='New'
/// 针对Task类型的 State='To Do'
/// 针对Task Case类型的 State='Design'
/// <returns></returns>
public WorkItemCollection GetWorkItemCollection(string workitemtype,string projectName,string condition)
{
string sql = @"Select [Title] From WorkItems Where [Work Item Type] = '{0}' and [System.TeamProject] = '{1}' ";
if (!string.IsNullOrEmpty(condition))
{
sql +=" and "+ condition;
}
sql = string.Format(sql, workitemtype, projectName);
WorkItemCollection queryResults = workstore.Query(sql);
return queryResults;
}

  四:获取Sprint信息和开始、结束时间

       /// <summary>
/// 获取项目的Sprint信息
/// </summary>
/// <param name="projectUri">project的Uri信息</param>
/// <returns></returns>
public TeamSettings GetSprintInfo(String projectUri)
{
TeamFoundationTeam team = teamService.QueryTeams(projectUri).First();
IList<Guid> teamGuids = new List<Guid>() { team.Identity.TeamFoundationId };
TeamConfiguration config = configSvc.GetTeamConfigurations(teamGuids).FirstOrDefault();
var members = team.GetMembers(server, MembershipQuery.Direct);
var users = members.Where(m => !m.IsContainer); return config.TeamSettings;
}
/// <summary>
/// 获取项目Sprint的关键信息如开始时间和结束时间
/// </summary>
/// <param name="projectUri"></param>
/// <returns></returns>
public IEnumerable<ScheduleInfo> GetIterationDates(string projectUri)
{
var css = server.GetService<ICommonStructureService4>();
NodeInfo[] structures = css.ListStructures(projectUri);
NodeInfo iterations = structures.FirstOrDefault(n => n.StructureType.Equals("ProjectLifecycle"));
List<ScheduleInfo> schedule = null;
if (iterations != null) {
string projectName = css.GetProject(projectUri).Name;
XmlElement iterationsTree = css.GetNodesXml(new[] { iterations.Uri }, true);
GetIterationDates(iterationsTree.ChildNodes[0], projectName, ref schedule);
}
return schedule;
}
/// <summary>
/// 通过解析XML得到Sprint的开始和结束时间
/// </summary>
/// <param name="node"></param>
/// <param name="projectName"></param>
/// <param name="schedule"></param>
private void GetIterationDates(XmlNode node, string projectName, ref List<ScheduleInfo> schedule)
{ if (schedule == null)
schedule = new List<ScheduleInfo>();
if (node != null)
{
string iterationPath = node.Attributes["Path"].Value;
if (!string.IsNullOrEmpty(iterationPath))
{
// Attempt to read the start and end dates if they exist.
string strStartDate = (node.Attributes["StartDate"] != null) ? node.Attributes["StartDate"].Value : null;
string strEndDate = (node.Attributes["FinishDate"] != null) ? node.Attributes["FinishDate"].Value : null;
DateTime? startDate = null, endDate = null;
if (!string.IsNullOrEmpty(strStartDate) && !string.IsNullOrEmpty(strEndDate))
{
bool datesValid = true;
// Both dates should be valid.
startDate = DateTime.Parse(strStartDate);
endDate = DateTime.Parse(strEndDate);
schedule.Add(new ScheduleInfo
{
Path = iterationPath.Replace(string.Concat("\\", projectName, "\\Iteration"), projectName),
StartDate = startDate,
EndDate = endDate
});
}
}
// Visit any child nodes (sub-iterations).
if (node.FirstChild != null)
{
// The first child node is the <Children> tag, which we'll skip.
for (int nChild = 0; nChild < node.ChildNodes[0].ChildNodes.Count; nChild++)
GetIterationDates(node.ChildNodes[0].ChildNodes[nChild], projectName, ref schedule);
}
}
}

  五:获取团队成员名单

        /// <summary>
/// 获取项目的Sprint信息
/// </summary>
/// <param name="projectUri">project的Uri信息</param>
/// <returns></returns>
public IEnumerable<TeamFoundationIdentity> GetMemberInfo(String projectUri)
{
TeamFoundationTeam team = teamService.QueryTeams(projectUri).First();
var members = team.GetMembers(server, MembershipQuery.Direct);
var users = members.Where(m => !m.IsContainer);
return users;
}

TFS二次开发的数据统计以PBI、Bug、Sprint等为例(一)的更多相关文章

  1. TFS二次开发系列:七、TFS二次开发的数据统计以PBI、Bug、Sprint等为例(一)

    在TFS二次开发中,我们可能会根据某一些情况对各个项目的PBI.BUG等工作项进行统计.在本文中将大略讲解如果进行这些数据统计. 一:连接TFS服务器,并且得到之后需要使用到的类方法. /// < ...

  2. TFS二次开发系列:八、TFS二次开发的数据统计以PBI、Bug、Sprint等为例(二)

    上一篇文章我们编写了此例的DTO层,本文将数据访问层封装为逻辑层,提供给界面使用. 1.获取TFS Dto实例,并且可以获取项目集合,以及单独获取某个项目实体 public static TFSSer ...

  3. TFS二次开发、C#知识点、SQL知识

    TFS二次开发.C#知识点.SQL知识总结目录   TFS二次开发系列 TFS二次开发系列:一.TFS体系结构和概念 TFS二次开发系列:二.TFS的安装 TFS二次开发系列:三.TFS二次开发的第一 ...

  4. TFS二次开发-基线文件管理器(5)-源码文件的读取

      在上一节中,我们在保存标签之前,已经将勾选的文件路径保存到了Listbox中,这里只需要将保存的数据输出去为txt文档就可以做版本控制了.   版本文件比较复杂的是如何读取,也就是如何通过文件路径 ...

  5. TFS二次开发系列:三、TFS二次开发的第一个实例

    首先我们需要认识TFS二次开发的两大获取服务对象的类. 他们分别为TfsConfigurationServer和TfsTeamProjectCollection,他们的不同点在于可以获取不同的TFS ...

  6. TFS二次开发、C#知识点、SQL知识总结目录

    TFS二次开发系列 TFS二次开发系列:一.TFS体系结构和概念 TFS二次开发系列:二.TFS的安装 TFS二次开发系列:三.TFS二次开发的第一个实例 TFS二次开发系列:四.TFS二次开发Wor ...

  7. TFS二次开发系列索引

    TFS二次开发11——标签(Label) TFS二次开发10——分组(Group)和成员(Member) TFS二次开发09——查看文件历史(QueryHistory) TFS二次开发08——分支(B ...

  8. TFS二次开发02——连接TFS

    在上一篇<TFS二次开发01——TeamProjectsPicher>介绍了  TeamProjectsPicher 对象,使用该对象可以很简单的实现连接TFS. 但是如果我们要实现自定义 ...

  9. TFS二次开发系列:五、工作项查询

    本节将讲述如何查询工作项,用于二次开发中定义获取工作项列表. 使用WorkItemStore.Query方法进行查询工作项,其使用的语法和SQL语法类似: Select [标题] from worki ...

随机推荐

  1. HDU 3415 Max Sum of Max-K-sub-sequence 最长K子段和

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=3415 意甲冠军:环.要找出当中9长度小于等于K的和最大的子段. 思路:不能採用最暴力的枚举.题目的数据量是 ...

  2. jquery插件之DataTables 参数介绍

    DataTables(http://www.datatables.net/)应该是我到目前为止见过的,功能最强大的表格解决方案(当然,不计算其它整套框架中的table控件在内). 先把它主页上写的特性 ...

  3. elasticsearch的rest搜索--- 安装

    目录: 一.针对这次装B 的解释 二.下载,安装插件elasticsearch-1.7.0   三.索引的mapping 四. 查询 五.对于相关度的大牛的文档 二.安装   1. 安装head管理插 ...

  4. 为代码减负之&lt;一&gt;触发器(SQL)

    对触发器一词早有耳闻(最早是在耿大妈的数据库视频中),当初看完视频后,对理解不深刻的东西如:触发器,存储过程,事务,日志等等没有具体的去查阅,也没有具体的去尝试,应用.所以才导致了今天的博客(把曾经丢 ...

  5. javascript系列之核心知识点(一)

    JavaScript. The core. 1.对象 2.原型链 3.构造函数 4.执行上下文堆栈 5.执行上下文 6.变量对象 7.活动对象 8.作用域链 9.闭包 10.this值 11.总结 这 ...

  6. HDU 2516 取石子游戏 (博弈论)

    取石子游戏 Problem Description 1堆石子有n个,两人轮流取.先取者第1次能够取随意多个,但不能所有取完.以后每次取的石子数不能超过上次取子数的2倍.取完者胜.先取者负输出" ...

  7. asp.net [AjaxMethod]

    AjaxPro.2.dll cs 代码 using AjaxPro; Utility.RegisterTypeForAjax(typeof(BOMdr_KT)); [Ajax.AjaxMethod() ...

  8. 在打包程序中自动安装SQL Server数据库 .

    原文:在打包程序中自动安装SQL Server数据库 . 1.创建安装项目“Setup1”安装项目 在“文件”菜单上指向“添加项目”,然后选择“新建项目”. 在“添加新项目”对话框中,选择“项目类型” ...

  9. [ACM] hdu 1671 Phone List (特里)

    Phone List Problem Description Given a list of phone numbers, determine if it is consistent in the s ...

  10. view components介绍

    view components介绍 在ASP.NET MVC 6中,view components (VCs) 功能类似于虚拟视图,但是功能更加强大. VCs兼顾了视图和控制器的优点,你可以把VCs ...