在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[], 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 = ; nChild < node.ChildNodes[].ChildNodes.Count; nChild++)
GetIterationDates(node.ChildNodes[].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二次开发系列:七、TFS二次开发的数据统计以PBI、Bug、Sprint等为例(一)的更多相关文章

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

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

  2. 微信程序开发系列教程(二)使用JavaScript给微信用户发送消息

    我之前的文章 微信程序开发系列教程(一)开发环境搭建 介绍了微信开发环境的搭建,这篇文章我们就来一步步开发一些具体的功能. 功能需求:当有微信用户关注了您的公众号之后,您用JavaScript发送一个 ...

  3. 微信小程序开发系列七:微信小程序的页面跳转

    微信小程序开发系列教程 微信小程序开发系列一:微信小程序的申请和开发环境的搭建 微信小程序开发系列二:微信小程序的视图设计 微信小程序开发系列三:微信小程序的调试方法 微信小程序开发系列四:微信小程序 ...

  4. 《C#微信开发系列(Top)-微信开发完整学习路线》

    年前就答应要将微信开发的学习路线整理给到大家,但是因为年后回来这段时间学校还有公司那边有很多事情需要兼顾,所以没能及时更新文章.今天特地花时间整理了下,话不多说,上图,希望对大家的学习有所帮助哈. 如 ...

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

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

  6. 【Qt程序】基于Qt词典开发系列&lt;十二&gt;呼叫讲述

    我们知道,win7系统自带有讲述人,即能够机器读出当前内容,详细能够将电脑锁定.然后点击左下角的button就可以.之前在用Matlab写扫雷游戏的时候,也以前调用过讲述人来进行游戏的语音提示. 详细 ...

  7. 循序渐进学.Net Core Web Api开发系列【1】:开发环境

    系列目录 循序渐进学.Net Core Web Api开发系列目录 本系列涉及到的源码下载地址:https://github.com/seabluescn/Blog_WebApi 一.本篇概述 本篇不 ...

  8. Solon 开发,七、自定义注解开发汇总

    Solon 开发 一.注入或手动获取配置 二.注入或手动获取Bean 三.构建一个Bean的三种方式 四.Bean 扫描的三种方式 五.切面与环绕拦截 六.提取Bean的函数进行定制开发 七.自定义注 ...

  9. C#.NET微信公众账号接口开发系列文章整理--微信接口开发目录,方便需要的博友查询

    前言: 涉及微信接口开发比较早也做的挺多的,有时间的时候整理了开发过程中一些思路案例,供刚学习微信开发的朋友参考.其实微信接口开发还是比较简单的,但是由于调试比较麻烦,加上微信偶尔也会给开发者挖坑,并 ...

随机推荐

  1. 18.有一个网页地址, 比如PHP开发资源网主页: http://www.phpres.com/index.html,如何得到它的内容?

    方法1(对于PHP5及更高版本): $readcontents = fopen("http://www.phpres.com/index.html", "rb" ...

  2. 使用Docker构建redis集群--最靠谱的版本

    1集群结构说明 集群中有三个主节点,三个从节点,一共六个结点.因此要构建六个redis的docker容器.在宿主机中将这六个独立的redis结点关联成一个redis集群.需要用到官方提供的ruby脚本 ...

  3. shell: bad interpreter: No such file or directory

    执行shell脚本    错误提示如下:    bash: ./back : bad interpreter:No such file or directory 因为操作系统是windows,在win ...

  4. HashSet的故事----Jdk源码解读

    Hash,我们在说HashMap的时候,已经知道Hash是散列,Map是映射了. 那么Set又是什么呢 ? 先来看看Set的翻译是什么 n. [数] 集合:一套:布景:[机] 装置 这里Set所取的含 ...

  5. Web Word和Excel

    暂时收集点资料备用 Excel http://www.cnblogs.com/downmoon/archive/2011/05/30/2063258.html http://www.cnblogs.c ...

  6. 25个实用的jQuery技巧和解决方案

    1. 去除页面的右键菜单 $(document).ready(function(){ $(document).bind(“contextmenu”,function(e){returnfalse;}) ...

  7. Makefile使用库

    这篇文章演示了Makefile使用mysqlpp库和lua库的写法. test.cpp: #include <iostream> #include <stdint.h> #in ...

  8. html布局小练习(百度首页)

    绝对定位百度首页练习 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> &l ...

  9. 在Linux上配置Zabbix的环境

    useradd -s /bin/false zabbix mkdir /usr/local/zabbix_agent mv /home/zihexin/zabbix_agents_3.2.0.linu ...

  10. 第一次接触servlet的知识

    什么是Servlet?① Servlet就是JAVA 类② Servlet是一个继承HttpServlet类的类③ 这个在服务器端运行,用以处理客户端的请求 Servlet相关包的介绍--javax. ...