在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. Wampserver 2.5 多站点配置方法

    写在开头:本文适用于wampserver2.5版本,和wamp的老版本配置有语法上的区别,笔者正是因为被老版本的配置办法给整迷糊了所以才总结了一篇针对2.5版本的配置方法,如果您还停留在1.x或着已经 ...

  2. Sprint

    Sprint冲刺 1.选题 <寿司点餐系统> 2.app名 <Sushi> 3.团名 ZEG 4.目标 制作一个成型的人性化的寿司点餐系统,介绍各种寿司的材料做法吃法以及价格, ...

  3. noi 1.5 43:质因数分解

    描述 已知正整数 n 是两个不同的质数的乘积,试求出较大的那个质数. 输入 输入只有一行,包含一个正整数 n.对于60%的数据,6 ≤ n ≤ 1000.对于100%的数据,6 ≤ n ≤ 2*10^ ...

  4. 使用Git、Git GUI和TortoiseGit

    1. 关于命令行 我一直建议在命令行中使用Git或者SVN.因为这样可能更加了解他们的工作方式,也不容易遗漏重要的问题和提醒. 在Windows习惯的驱使下,大多数人是不会看弹出的对话框中有什么信息的 ...

  5. jQuery Scroll Follow

    Overview Scroll Follow is a simple jQuery plugin that enables a DOM object to follow the page as the ...

  6. 通什翡翠商城大站协议邮件群发系统日发20-30万封不打码不换ip不需发件箱100%进收件箱

    用一种新的技术思维去群发邮件一种不用换IP,不需要任何发件箱的邮件群发方式一种不需要验证码,不需要**代码变量的邮件群发方式即使需要验证码也能全自动识别验证码的超级智能软件教你最核心的邮件群发思维和软 ...

  7. Apache 打开网页的时候等待时间过长的解决方案

    服务器搭建后经常在打开页面的时候,等待很长时间,有时候,都超过一分钟了,然后才能打开,但是打开后,速度又很快,休息一会再点击,又会很慢了,遇到了这种问题很头疼,由于不是专业做服务器配置的,所以刚开始没 ...

  8. Fiddler 常用文档

    时间飞逝,已经俩月有余没写东西了(本来写的就不多,(^▽^)),最近俩月的苦闷,此处省略 1W 字.... 闲言碎语不多讲,使用 Fiddler 有一小段时间了,今天在这里总结下,一来做个笔记,二来可 ...

  9. 1016. Boundaries on A New Kind of Science 解题报告

    题目链接: http://soj.sysu.edu.cn/1016 题目大意: 给定一个字符串和256条规则,将某条规则应用于字符串,字符串将发生变化,给定一个数max,求出在max步内可以将字符串变 ...

  10. VS2013打开项目Web加载失败

    今天打开一个好久没打开过的老项目,发现web加载失败,如图: 然后重新加载项目,提示: 一开始直接在网上找答案,结果看的答案都不靠谱,只好自己动手了, 先看了 这里面是基础配置:大概看过后,又去看了提 ...