上一篇文章我们编写了此例的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等为例(二)的更多相关文章

  1. TFS二次开发的数据统计以PBI、Bug、Sprint等为例(一)

    TFS二次开发的数据统计以PBI.Bug.Sprint等为例(一) 在TFS二次开发中,我们可能会根据某一些情况对各个项目的PBI.BUG等工作项进行统计.在本文中将大略讲解如果进行这些数据统计. 一 ...

  2. 《C#微信开发系列(Top)-微信开发完整学习路线》

    年前就答应要将微信开发的学习路线整理给到大家,但是因为年后回来这段时间学校还有公司那边有很多事情需要兼顾,所以没能及时更新文章.今天特地花时间整理了下,话不多说,上图,希望对大家的学习有所帮助哈. 如 ...

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

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

  4. 循序渐进学.Net Core Web Api开发系列【1】:开发环境

    系列目录 循序渐进学.Net Core Web Api开发系列目录 本系列涉及到的源码下载地址:https://github.com/seabluescn/Blog_WebApi 一.本篇概述 本篇不 ...

  5. C#.NET微信公众账号接口开发系列文章整理--微信接口开发目录,方便需要的博友查询

    前言: 涉及微信接口开发比较早也做的挺多的,有时间的时候整理了开发过程中一些思路案例,供刚学习微信开发的朋友参考.其实微信接口开发还是比较简单的,但是由于调试比较麻烦,加上微信偶尔也会给开发者挖坑,并 ...

  6. 8天掌握EF的Code First开发系列之2 Code First开发系列之领域建模和管理实体关系

    本文出自8天掌握EF的Code First开发系列,经过自己的实践整理出来. 本篇目录 理解Code First及其约定和配置 创建数据表结构 管理实体关系 三种继承模式 本章小结 本人的实验环境是V ...

  7. BizTalk开发系列(八) BizTalk Server 常识整理

    1.什么是BizTalk Server?     BizTalk 是业务流程管理服务器,用于连接人员,流程,有效管理和提升业务所需的信息.在原有版本业务 流程管理和SOA/ESB 的基础上,第5 个版 ...

  8. arcgis api for js入门开发系列八聚合效果(含源代码)

    上一篇实现了demo的图层控制模块,本篇新增聚合效果,截图如下(源代码见文章底部): 聚合效果实现的思路如下: 1.map.html引用聚合包,项目已经包含进来了的聚合文件夹: <script ...

  9. arcgis api 3.x for js 入门开发系列八聚合效果(附源码下载)

    前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 3.x for js:esri 官网 api,里面详细的介绍 arcgis api 3.x 各个类 ...

随机推荐

  1. laravel5.1学习(2)-- artisan tinker命令

    例如:为users表创建20条测试输入 G:\wamp\www\hcmf>php artisan tinker >>> namespace App; => null &g ...

  2. Android Studio: Failed to sync Gradle project 'xxx' Error:Unable to start the daemon process: could not reserve enough space for object heap.

    创建项目的时候报错: Failed to sync Gradle project 'xxx' Error:Unable to start the daemon process: could not r ...

  3. Python--循环语句

    Python 循环语句 循环语句允许我们执行一个语句或语句组多次,下面是在大多数编程语言中的循环语句的一般形式: Python提供了for循环和while循环(在Python中没有do..while循 ...

  4. UE4入门与精通

    由于目前在使用UE4引擎,多少也有一些心得,比如在日常使用中会遇到一些问题.坑(潜规则)或者一些使用技巧等.本人决定开一个大坑,主要有两个目的:一是可以自己做个记录,二是可以给大家提供一些参考吧.主要 ...

  5. MWeb 2.0 测试版可以下载啦,这次是公开测试,感兴趣的朋友可以试试

    2.0 版是 MWeb 发布以来,最重要的一个版本.MWeb 自去年一月份发布以来,获得了很多朋友的建议,在此非常感谢!没有你们,2.0 版可能就不能出来!然后再次感谢 Producter: http ...

  6. ferret32位安装

    首先在网上找到解决方案: 1.添加对32位的支持 dpkg --add-architecture i386 2.更新 apt-get clean && apt-get update & ...

  7. memcpy内存复制

    memcpy(predata,frame,1920*1080*4);

  8. [转]IntelliJ IDEA 使用心得与常用快捷键

    IntelliJ IDEA 使用心得与常用快捷键 那种酸爽,根本说不出来—————————————————————————— by: Jimi没有BondJimi是谁? 就是洒家啊! 刚开始学习写Ja ...

  9. 我的第一个FluentNHibernate例子

    刚刚接触NHibernate和FluentNHibernate,所以最好的方法是从一个简单的例子入手. 开发环境考虑到是实际情况还有好多朋友没有用VS2015,就用VS2013withUpdate5吧 ...

  10. py2exe使用方法

    一.简介 py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具,这样,你就可以不用装python而在windows系统上运行这个可执行程序. py2e ...