在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. java环境变量的设置

    java安装好后需要配置一下环境变量,配置方法如下: 1.在系统变量里添加两条记录: 1)变量名:JAVA_HOME,变量值为java安装路径,如:C:\Program Files\Java\jdk1 ...

  2. git/github学习笔记

    郑重提示,本文来自这里,如果喜欢,请关注原作者. 1. git 版本控制系统 相比CVS\SVN优势: - 支持离线开发,离线Repository- 强大的分支功能,适合多个独立开发者协作- 速度块 ...

  3. Android--带你一点点封装项目 MVP+BaseActivity+Retrofit+Dagger+RxJava(一)

    1,其实早就想把这些东西给封装封装的,一直没有时间,今天刚好项目进入到测试阶段了,Bug同事在哪儿测试的飞起,但发现提bug的尽然是我(得意脸),然后上午把ios的包测试了一下,顺便把服务器给测挂了( ...

  4. chkconfig命令详解

    chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. 使用语法:chkconfig [--ad ...

  5. [osx] 设置crontab

    比较坑爹,直接使用 crontab -e 设置是没有效果的,只能这样设置 env EDITOR=vi crontab -e Have fun with Max OSX

  6. Angular初学

    简介: angularjs是基本js开发的一个前端类库,主要致力于减轻开发人员在开发Ajax应用过程中的痛苦,适合来做单应用. 客户端模板: Angualr中,模板和数据都会被发送到浏览器中,然后在客 ...

  7. 并发框架Disruptor浅析

    1.引言 Disruptor是一个开源的Java框架,它被设计用于在生产者—消费者(producer-consumer problem,简称PCP)问题上获得尽量高的吞吐量(TPS)和尽量低的延迟.D ...

  8. phpcms V9 常用函数 及 代码整理

    常用函数 及 常用代码 总结如下 <?php //转换字符串或者数组的编码 str_charset($in_charset, $out_charset, $str_or_arr) //获取菜单 ...

  9. [转] How to debug a ARM Cortex-M hard fault exception

    how to debug a ARM Cortex-M hard fault exception

  10. Codefroces 750C:New Year and Rating(思维)

    http://codeforces.com/contest/750/problem/C 题意:有n场比赛,每场比赛有一个c,代表比赛结束后分数的增长情况,有一个d,代表这场比赛在div1或者div2打 ...