TFS二次开发系列:八、TFS二次开发的数据统计以PBI、Bug、Sprint等为例(二)
上一篇文章我们编写了此例的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() > )
{
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 = , Done = , opening = };
}
}
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 = ;
if(totaleffort!=)
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=;
foreach (WorkItem item in collection)
{
object o=item.Fields.GetById().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") + ).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('\\')+)};
list.Add(m);
}
return list;
} public IEnumerable<ScheduleInfo> GetFinalBugInfo(Project project)
{
IEnumerable<ScheduleInfo> sprintlist = GetSprintDate(project.Uri.ToString());
int newbug = ;
int openbug = ;
int closed = ;
int Totalbug = ;
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;
}
5.通过以上代码的封装,我们可以得到知己展示于前台的TFS数据展示。
TFS二次开发系列:八、TFS二次开发的数据统计以PBI、Bug、Sprint等为例(二)的更多相关文章
- TFS二次开发的数据统计以PBI、Bug、Sprint等为例(一)
TFS二次开发的数据统计以PBI.Bug.Sprint等为例(一) 在TFS二次开发中,我们可能会根据某一些情况对各个项目的PBI.BUG等工作项进行统计.在本文中将大略讲解如果进行这些数据统计. 一 ...
- 《C#微信开发系列(Top)-微信开发完整学习路线》
年前就答应要将微信开发的学习路线整理给到大家,但是因为年后回来这段时间学校还有公司那边有很多事情需要兼顾,所以没能及时更新文章.今天特地花时间整理了下,话不多说,上图,希望对大家的学习有所帮助哈. 如 ...
- TFS二次开发系列:七、TFS二次开发的数据统计以PBI、Bug、Sprint等为例(一)
在TFS二次开发中,我们可能会根据某一些情况对各个项目的PBI.BUG等工作项进行统计.在本文中将大略讲解如果进行这些数据统计. 一:连接TFS服务器,并且得到之后需要使用到的类方法. /// < ...
- 循序渐进学.Net Core Web Api开发系列【1】:开发环境
系列目录 循序渐进学.Net Core Web Api开发系列目录 本系列涉及到的源码下载地址:https://github.com/seabluescn/Blog_WebApi 一.本篇概述 本篇不 ...
- C#.NET微信公众账号接口开发系列文章整理--微信接口开发目录,方便需要的博友查询
前言: 涉及微信接口开发比较早也做的挺多的,有时间的时候整理了开发过程中一些思路案例,供刚学习微信开发的朋友参考.其实微信接口开发还是比较简单的,但是由于调试比较麻烦,加上微信偶尔也会给开发者挖坑,并 ...
- 8天掌握EF的Code First开发系列之2 Code First开发系列之领域建模和管理实体关系
本文出自8天掌握EF的Code First开发系列,经过自己的实践整理出来. 本篇目录 理解Code First及其约定和配置 创建数据表结构 管理实体关系 三种继承模式 本章小结 本人的实验环境是V ...
- BizTalk开发系列(八) BizTalk Server 常识整理
1.什么是BizTalk Server? BizTalk 是业务流程管理服务器,用于连接人员,流程,有效管理和提升业务所需的信息.在原有版本业务 流程管理和SOA/ESB 的基础上,第5 个版 ...
- arcgis api for js入门开发系列八聚合效果(含源代码)
上一篇实现了demo的图层控制模块,本篇新增聚合效果,截图如下(源代码见文章底部): 聚合效果实现的思路如下: 1.map.html引用聚合包,项目已经包含进来了的聚合文件夹: <script ...
- arcgis api 3.x for js 入门开发系列八聚合效果(附源码下载)
前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 3.x for js:esri 官网 api,里面详细的介绍 arcgis api 3.x 各个类 ...
随机推荐
- iOS10 - 访问系统通讯录新方法
所需框架 #import <ContactsUI/ContactsUI.h> 遵循代理 CNContactPickerDelegate 调用通讯录 如果在iOS10的机器上调用以前的ABP ...
- cssSelector定位笔记1
cssSelector定位方法:1.使用class属性定位元素:driver.findElement(By.cssSelector("input.login"));即可以先指定一个 ...
- HDU 5047 Sawtooth(大数优化+递推公式)
http://acm.hdu.edu.cn/showproblem.php?pid=5047 题目大意: 给n条样子像“m”的折线,求它们能把二维平面分成的面最多是多少. 解题思路: 我们发现直线1条 ...
- Linux上 .vimrc文件
在Linux上面对VIM编辑器的格式的设置通常可以提升工作效率,下面对工作机器上的.vimrc文件的内容进行一总结,以备后续的查询 set smarttab set tabstop=4 set shi ...
- Android 自定义 view(四)—— onMeasure 方法理解
前言: 前面我们已经学过<Android 自定义 view(三)-- onDraw 方法理解>,那么接下我们还需要继续去理解自定义view里面的onMeasure 方法 推荐文章: htt ...
- mac的webdriver自动化
下载webdriver-chrome的连接:http://chromedriver.storage.googleapis.com/index.html
- c++ 解包tar
首先我们来看tar文件组成 tar中的数据都是以512字节为单位:tar由三部分组成 “头部+内容+尾部”,其中头部是512字节的头部结构,内容是存放一个文件内容的地方,最后尾部是一个512字节的全零 ...
- Windows Phone 三、样式和资源
定义样式和引用资源 <Page.Resources> <!-- 向资源字典中添加一个键为ButtonBackground值为SolidColorBrush对象 --> < ...
- 【Ngui 学习系列之一:简单组件的操作】
一.Buttonunity edit: Sprite作为父对象和背景 -- Collider -- Button script Label 作为子对象和显示文字代码: private UIButton ...
- 使用SQL语句查询日期(当月天数,当月第一天,当月最后一天,本年最后一天,当月第一个星期) 日期转字符串
取某月天数:,) --当月天数 ,DATEADD(m, DATEDIFF(m,,getdate())+,))) ---当月第一天 ,getdate()) ---当月最后一天 ,dateadd(m,,d ...