上一篇文章我们编写了此例的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. 从零开始攻略PHP(7)——面向对象(上)

    1.理解面向对象的概念 面向对象软件的一个重要优点是支持和鼓励封装的能力.封装也叫数据隐藏. 在面向对象的软件中,对象是一个被保存数据和操作这些数据的操作方法的唯一.可标识的集合. 对象可以按类进行分 ...

  2. web前端基础知识- Django基础

    上面我们已经知道Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Sessi ...

  3. Android中使用Handler造成内存泄露的分析和解决

    什么是内存泄露?Java使用有向图机制,通过GC自动检查内存中的对象(什么时候检查由虚拟机决定),如果GC发现一个或一组对象为不可到达状态,则将该对象从内存中回收.也就是说,一个对象不被任何引用所指向 ...

  4. jqGrid设置指定行的背景色

    1.在页面中加样式 <style type="text/css"> .SelectBG{ background-color:#AAAAAA; } </style& ...

  5. linux-bash shell学习

    什么是shell?shell就相当于是计算机给我提供的一个操作系统的接口,这里说的bash shell是一种命令行方面的软件,提供给用户来操作系统.

  6. .net之工作流工程展示及代码分享(四)主控制类

    现在应该讲主控制类了,为了不把系统弄得太复杂,所以就用一个类作为主要控制类(服务类),作为前端.后端.业务逻辑的控制类. WorkflowService类的类图如下: 该类的构造函数: public ...

  7. Python语言十分钟快速入门

    Python(蟒蛇)是一种动态解释型的编程语言.Python可以在Windows.UNIX.MAC等多种操作系统上使用,也可以在Java..NET开发平台上使用. AD:[51CTO技术沙龙]移动时代 ...

  8. CEGUI0.8.4引入到自己工程中

    首先要确定你的CEGUI已经完全编译好,若未进行这一步请参照http://www.cnblogs.com/wenguang1996/p/5027522.html 打开VS2012新建C++工程,然后添 ...

  9. logrotate

    logrotate程序是一个日志文件管理工具.用于分割日志文件,删除旧的日志文件,并创建新的日志文件,起到"转储"作用.可以节省磁盘空间. logrotate命令格式:logrot ...

  10. Weblogic的JDBC详解

    WebLogic Server 中的JDBC概述  在 WebLogic Server 中,您可以配置数据库连接,方法是先配置 JDBC 数据源和多数据源,然后将这些 JDBC 资源指定到或部署到 W ...