上一篇文章我们编写了此例的DTO层,本文将数据访问层封装为逻辑层,提供给界面使用。

  1.获取TFS Dto实例,并且可以获取项目集合,以及单独获取某个项目实体

        public static TFSServerBll Instance = new TFSServerBll();public TFSServerDto dto;public TFSServerBll(){dto = new TFSServerDto("http://server:8080/tfs/Project/");}public TFSServerBll(string TfsUri){dto = new TFSServerDto(TfsUri);}/// <summary>/// 获取项目集合/// </summary>/// <returns></returns>public ProjectCollection GetProjectList(){return dto.GetProjectList();}//根据projectId获取Project实体public Project GetProject(int projectId){return dto.GetProject(projectId);}

  2.根据规则获取项目的PBI/Bug等信息

        /// <summary>/// 获取项目的所有数据/// </summary>/// <param name="project"></param>public void GetProjectInfo(Project project){TfsSprint projectSprint = GetSprintInfo(project.Uri.ToString());GetProjectSprintPBIandBUG(projectSprint, project);}/// <summary>/// 获取某项目所有Sprint的PBI和BUG/// </summary>/// <param name="projectSprint"></param>/// <param name="project"></param>public void GetProjectSprintPBIandBUG(TfsSprint projectSprint, Project project){IEnumerable<ScheduleInfo> list = GetFinalBugInfo(project);foreach (Sprint sprint in projectSprint.SprintList){sprint.PBIInfo = GetSimplePbi(project.Name, sprint.SprintPath);if (list.Count() > 0){foreach (ScheduleInfo info in list){if (info.Path == sprint.SprintPath){sprint.BugInfo = new TfsBug() { New = info.NewBug, Done = info.Closed, opening = info.OpenBug };break;}}}else{sprint.BugInfo = new TfsBug() { New = 0, Done = 0, opening =0 };}}string s = "";}private TfsPBI GetSimplePbi(string projectName, string IterationSprint){WorkItemCollection total = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[Iteration Path]='" + IterationSprint + "'");WorkItemCollection doneCollection = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[State]='Done' and [Iteration Path]='" + IterationSprint + "'");double totaleffort = GetPBIEffort(total);double doneeffort = GetPBIEffort(doneCollection);double effortPercent = doneeffort / totaleffort;TfsPBI pbiinfo = new TfsPBI(){Total = total.Count,Done = doneCollection.Count,EffoctPercent = effortPercent,EffoctCurrent = (int)doneeffort,EffoctTotal = (int)totaleffort};return pbiinfo;}private TfsBug GetSimpleBug(string projectName, string IterationSprint){WorkItemCollection total = dto.GetWorkItemCollection("Bug", projectName, "[Iteration Path]='" + IterationSprint + "'");WorkItemCollection NewCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='New' and [Iteration Path]='" + IterationSprint + "'");WorkItemCollection doneCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='Done' and [Iteration Path]='" + IterationSprint + "'");WorkItemCollection RemovedCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='Removed' and [Iteration Path]='" + IterationSprint + "'");TfsBug buginfo = new TfsBug(){Total = total.Count,New = NewCollection.Count,Done = doneCollection.Count,Removed=RemovedCollection.Count};return buginfo;}

  3.另外一些获取Bug/PBI信息的组成方式

        /// <summary>/// 获得某项目的BUG数量信息/// </summary>/// <param name="projectName"></param>/// <returns></returns>public TfsBug GetBugInfo(string projectName, string IterationSprint){WorkItemCollection bugCollection = dto.GetWorkItemCollection("Bug", projectName, "[Iteration Path]='" + IterationSprint + "'");WorkItemCollection bugNewCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='New' and [Iteration Path]='" + IterationSprint + "'");WorkItemCollection bugApprovedCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='Approved' and [Iteration Path]='" + IterationSprint + "'");WorkItemCollection bugCommittedCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='Committed' and [Iteration Path]='" + IterationSprint + "'");WorkItemCollection bugDoneCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='Done' and [Iteration Path]='" + IterationSprint + "'");WorkItemCollection bugRemovedCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='Removed' and [Iteration Path]='" + IterationSprint + "'");TfsBug buginfo = new TfsBug(){Total = bugCollection.Count,New = bugNewCollection.Count,Approved = bugApprovedCollection.Count,Committed = bugCommittedCollection.Count,Done = bugDoneCollection.Count,Removed = bugRemovedCollection.Count};return buginfo;}/// <summary>/// 获取整个项目的PBI信息/// </summary>/// <param name="projectName"></param>/// <returns></returns>public ProjectView GetAllInfo(String projectName){WorkItemCollection total = dto.GetWorkItemCollection("Product Backlog Item", projectName, string.Empty);WorkItemCollection doneCollection = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[State]='Done'");WorkItemCollection RemovedCollection = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[State]='Removed'");double totaleffort = GetPBIEffort(total);double doneeffort = GetPBIEffort(doneCollection);double removedeffort = GetPBIEffort(RemovedCollection);double effortPercent = 0;if(totaleffort!=0)effortPercent = doneeffort / totaleffort;WorkItemCollection RiskOpenCollection = dto.GetWorkItemCollection("Impediment", projectName, "[State]='Open'");int riskopenCount = RiskOpenCollection.Count;WorkItemCollection totalBug = dto.GetWorkItemCollection("Bug", projectName, string.Empty);WorkItemCollection doneCollectionBug = dto.GetWorkItemCollection("Bug", projectName, "[State]='Done'");WorkItemCollection RemovedCollectionBug = dto.GetWorkItemCollection("Bug", projectName, "[State]='Removed'");int openbugCount = totalBug.Count - doneCollectionBug.Count - RemovedCollectionBug.Count;ProjectView view = new ProjectView() { PbiPercent = effortPercent, OpenBugCount = openbugCount, OpenRiskCount = riskopenCount, TotalPbiEffort = totaleffort};return view;}/// <summary>/// 获得某项目的PBI数量信息/// </summary>/// <param name="projectName"></param>/// <returns></returns>public TfsPBI GetPBIInfo(string projectName, string IterationSprint){WorkItemCollection total = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[Iteration Path]='" + IterationSprint + "'");WorkItemCollection newcollection = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[State]='New' and [Iteration Path]='" + IterationSprint + "'");WorkItemCollection approvedCollection = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[State]='Approved' and [Iteration Path]='" + IterationSprint + "'");WorkItemCollection committedCollection = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[State]='Committed' and [Iteration Path]='" + IterationSprint + "'");WorkItemCollection doneCollection = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[State]='Done' and [Iteration Path]='" + IterationSprint + "'");WorkItemCollection removedCollection = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[State]='Removed' and [Iteration Path]='" + IterationSprint + "'");double totaleffort = GetPBIEffort(total);double doneeffort=GetPBIEffort(doneCollection);double effortPercent = doneeffort / totaleffort;TfsPBI pbiinfo = new TfsPBI(){Total = total.Count,New = newcollection.Count,Approved = approvedCollection.Count,Committed = committedCollection.Count,Done = doneCollection.Count,Removed = removedCollection.Count,EffoctPercent = effortPercent,EffoctCurrent=(int)doneeffort,EffoctTotal=(int)totaleffort};return pbiinfo;}public double GetPBIEffort(WorkItemCollection collection){double totalEff=0;foreach (WorkItem item in collection){object o=item.Fields.GetById(10009).Value;if (o != null)totalEff += (double)o;}return totalEff;}

  4.获取Sprint,Risk等信息集合

        /// <summary>/// 获得某项目的Risk数量信息/// </summary>/// <param name="projectName"></param>/// <returns></returns>public List<TfsRiskInfo> GetRiskInfo(string projectName){WorkItemCollection RiskOpenCollection = dto.GetWorkItemCollection("Impediment", projectName, "[State]='Open'");List<TfsRiskInfo> list = new List<TfsRiskInfo>();foreach (WorkItem item in RiskOpenCollection){list.Add(new TfsRiskInfo() { RiskInfo=item.Description, RiskStatus="Open",RiskId=item.Id.ToString()});}return list;}/// <summary>/// 获取Sprint信息/// </summary>/// <param name="projectUri"></param>/// <returns></returns>public TfsSprint GetSprintInfo(String projectUri){TeamSettings setting= dto.GetSprintInfo(projectUri);TfsSprint tfssprint = new TfsSprint();tfssprint.CurrentIterationPath=setting.CurrentIterationPath;tfssprint.SprintCount=setting.IterationPaths.Count();IEnumerable<string> ea_items =from name in setting.IterationPaths.ToList()where name.Contains("Sprint")select name;List<Sprint> list = new List<Sprint>();foreach (string path in ea_items){string sprintnum = path.Substring(path.LastIndexOf("Sprint") + 6).Trim();string sprintname ="Sprint "+sprintnum;if(!string.IsNullOrEmpty(sprintnum))list.Add(new Sprint() { SprintName = sprintname, SprintNum = int.Parse(sprintnum), SprintPath = path });}list.Sort((x, y) => x.SprintNum - y.SprintNum);tfssprint.SprintList = list;return tfssprint;}public IEnumerable<ScheduleInfo> GetSprintDate(string projectUri){ return dto.GetIterationDates(projectUri);}/// <summary>/// 获取团队成员信息/// </summary>/// <param name="projectUri"></param>/// <returns></returns>public List<TfsMember> GetMemberInfo(String projectUri){var list=new List<TfsMember>();var members=dto.GetMemberInfo(projectUri);foreach (TeamFoundationIdentity member in members){var m = new TfsMember() { UserName=member.DisplayName,UserSimpleName=member.UniqueName.Substring(member.UniqueName.IndexOf('\\')+1)};list.Add(m);}return list;}public IEnumerable<ScheduleInfo> GetFinalBugInfo(Project project){IEnumerable<ScheduleInfo> sprintlist = GetSprintDate(project.Uri.ToString());int newbug = 0;int openbug = 0;int closed = 0;int Totalbug = 0;foreach (ScheduleInfo info in sprintlist){TfsBug bug = GetSingleBug(project.Name, info.StartDate,info.EndDate);info.NewBug = bug.New;info.Closed = bug.Done;Totalbug += bug.New;openbug = Totalbug - info.Closed;info.OpenBug = openbug;}return sprintlist;}private TfsBug GetSingleBug(string projectName,DateTime? createdate,DateTime? enddate){WorkItemCollection total = dto.GetWorkItemCollection("Bug", projectName, "[Created Date]>'" + createdate + "' and [Closed Date]<'"+enddate+"'");WorkItemCollection NewCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='New' and [Created Date]>'" + createdate + "' and [Closed Date]<'" + enddate + "'");WorkItemCollection doneCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='Done' and [Created Date]>'" + createdate + "' and [Closed Date]<'" + enddate + "'");TfsBug buginfo = new TfsBug(){Total = total.Count,New = NewCollection.Count,Done = doneCollection.Count};return buginfo;}
本文转自程兴亮博客园博客,原文链接:http://www.cnblogs.com/chengxingliang/p/3431939.html,如需转载请自行联系原作者

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

  1. Android蓝牙开发系列文章-玩转BLE开发(一)

    我们在<Android蓝牙开发系列文章-策划篇>中计划讲解一下蓝牙BLE,现在开始第一篇:Android蓝牙开发系列文章-玩转BLE开发(一).计划要写的BLE文章至少分四篇,其他三篇分别 ...

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

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

  3. 今天你写控件了吗?----ASP.net控件开发系列(八)

    怎样更改默认的控件分析逻辑  ------用PersistChildren(false)和ControlBuilder来定制ASP.net对控件标签对中的内容的分析 "我的地盘,我做主&qu ...

  4. EOS智能合约开发系列(八): 账户和权限

    知识星球地址:https://t.zsxq.com/uRrZbiM 欢迎访问知识星球,并留言探讨.

  5. Android 10.0 SystemUI下拉状态栏UI定制化开发系列(八)

    目录 1.概述 2.核心代码部分 3.核心代码分析 3.1状态栏黑色透明背景的分析

  6. 微信公众号开发系列-12、微信前端开发利器:WeUI

    1.前言 通过前面系列文章的学习与讲解,相信大家已经对微信的开发有了一个全新的认识.后端基本能够基于盛派的第三方sdk搞定大部分事宜,剩下的就是前端了.关于手机端的浏览器的兼容性问题相信一直是开发者们 ...

  7. 微信程序开发系列教程(一)开发环境搭建

    1. 您得从微信官方平台注册一个微信订阅号: https://mp.weixin.qq.com 2. 这个教程使用nodejs开发微信订阅号对应的消息服务器,因此需要具备基本的nodejs开发技能. ...

  8. IOS开发系列之阿堂教程:构建开发IOS应用的虚拟机开发环境实践

    说到IOS的开发,不能不说 到一个问题,如何配置和构建一个IOS的开发环境!我下面要说的主要是针对没有MAC Apple机的网友,如何安装和配置一个属于自己的IOS开发环境.如果已经有MAC 苹果机的 ...

  9. 嵌入式开发系列005-嵌入式产品开发体验

    1. 通过举例说明嵌入式产品开发特点 产品1是关于无操作系统的MCU项目: 产品2是关于运行RTOS的MCU项目: 产品3是关于运行Linux/Android的MPU项目. 产品1是智能台灯 其功能是 ...

最新文章

  1. LeetCode简单题之两栋颜色不同且距离最远的房子
  2. php memcache
  3. Linux的notifier机制在TP中的应用【转】
  4. 用YACC/LEX 设计计算机语言
  5. SAP导出Excel错点拒绝处理
  6. ACL 2019 开源论文 | 基于知识库和大规模网络文本的问答系统
  7. 读书笔记之《程序员必读的职业规划书》
  8. pytorch 正向与反向传播的过程 获取模型的梯度(gradient),并绘制梯度的直方图
  9. php如何把图片存入oracle,在PHP中将图片存放ORACLE中
  10. Python实现十大经典排序算法
  11. 互信息python代码_转:标准化互信息NMI计算步骤及其Python实现
  12. 查找有序数组中某个数首次出现的位置
  13. 【光学】基于matlab夫琅禾费圆孔衍射【含Matlab源码 062期】
  14. 【python路上小记】匹配11位电话正则表达式
  15. 高职高考要计算机证,高职高考的报名条件需要技能证书
  16. 服务器如何设置内网IP地址
  17. Phoenix升级:Error: Cluster is being concurrently upgraded from 4.7.x to 4.8.x.
  18. svc android,安卓svc命令使用总结
  19. 计算机识别不到硬盘,电脑认不到硬盘怎么回事 电脑开机认不到硬盘处理方法...
  20. 浅谈聚合支付系统的安全性

热门文章

  1. Linux内核总线系统 —— 通用总线和平台设备
  2. 虚拟机中Linux配置java-jdk和tomcat
  3. 去哪儿网一面:工厂方法模式
  4. 程序员入职请前辈吃饭,一桌五人 网友五字神评论亮了
  5. c++面向对象的学生管理系统
  6. [CVPR‘22 SLPT] Sparse Local Patch Transformer for Robust Face Alignment and Landmarks Inherent Relat
  7. 几位深受妇科病困扰的女明星
  8. 妙手回春,AI修复让老旧视频重焕新生
  9. Spring Security(15)——权限鉴定结构
  10. 域名 超过注册日两年_域名 – “注册商注册过期日期”与实际到期日之间的关系...