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 各个类 ...
随机推荐
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 错误解决
今天在做LNMP的时候,启动nginx服务,无法开启,导致网页打不开.把服务从起一下发现提示错误如下: Starting nginx: nginx: [emerg] bind() to 0.0.0.0 ...
- RDIFramework.NET — 基于.NET的快速信息化系统开发框架 — 系列目录
RDIFramework.NET — 基于.NET的快速信息化系统开发框架 — 系列目录 RDIFramework.NET,基于.NET的快速信息化系统开发.整合框架,给用户和开发者最佳的.Net框架 ...
- AppSettings和connectionStrings的却别(转)
AppSettings是ASP.NET1.1时期用的,在.NET Framework 2.0中,新增了ConnectionStrings. 1.<connectionStrings> &l ...
- peoplesoft SQR language
Understanding SQR Data Elements !Variables!Variables are storage places for text or numbers that you ...
- 挂FORM时找不到对应的功能(function)
表单 功能都已经定义,但是在菜单中增加时候没有这个可选的项. 解决办法:由于是功能太多,LOV显示限制为30000,因此将功能名前加CUX,提升其排序即可.也可以修改LOV显示限制数量.
- sqlserver 锁与阻塞
DDL/索引重建 会申请 Sch-M锁 with (nolock) 会申请 Sch-S锁 with (nolock)会阻塞 sch-M, 同样Sch-M也会 阻塞with (nolock) 索引重建2 ...
- Log(android.util.Log)(option+return)
Log.v() verbose 琐碎,详细 Log.d() debug 调试 Log.i() info 信息,重要,分析行为 Log.w() wain 警告 log.e() error 错误 参数:t ...
- 二十六、Java--------反射
反射 正常情况下,我们必须知道一个类的完整路径后才可以实例化对象,但是在Java也可以通过一个对象来找到其所在类的信息,这其实就是Class的功能. 可以看到此时的所有操作都是反着来,这就是反射. p ...
- 3173: [Tjoi2013]最长上升子序列
原题:http://www.lydsy.com/JudgeOnline/problem.php?id=3173 题解:促使我写这题的动力是,为什么百度遍地是Treap,黑人问号??? 这题可以用线段树 ...
- SQL语句 还原未知逻辑名称数据库
1. 查看 SQL Server 2000 中 Northwind 数据库文件的逻辑文件名(logical file name)和物理文件路径(operation system file name): ...