TFS二次开发系列:五、工作项查询_项目管理_非技术区_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 非技术区 > 项目管理 > TFS二次开发系列:五、工作项查询

TFS二次开发系列:五、工作项查询

 2013/8/12 12:19:10  程兴亮  博客园  我要评论(0)
  • 摘要:本节将讲述如何查询工作项,用于二次开发中定义获取工作项列表。使用WorkItemStore.Query方法进行查询工作项,其使用的语法和SQL语法类似:Select[标题]fromworkitemswhere[工作项类型]='任务'and[指派给]='administrator'orderby[标题]我们通过多个步骤来学习,一、我们连接TFS服务://TFSURIUritfsUri=newUri("http://pc-20130113jkun:8080/tfs")
  • 标签:工作 开发

  本节将讲述如何查询工作项,用于二次开发中定义获取工作项列表。

  使用WorkItemStore.Query方法进行查询工作项,其使用的语法和SQL语法类似:

Select [标题]

from workitems

where [工作项类型]='任务' and [指派给] = 'administrator'

order by [标题]

  我们通过多个步骤来学习,一、我们连接TFS服务:

            //TFSURI
            Uri tfsUri = new Uri("http://pc-20130113jkun:8080/tfs");
            TfsTeamProjectCollection projectCollection = new TfsTeamProjectCollection(tfsUri);
            WorkItemStore workItemStore = (WorkItemStore)projectCollection.GetService(typeof(WorkItemStore));

  二、基本查询

            //基本查询
            WorkItemCollection queryResults = workItemStore.Query(@"
                Select  [标题] 
                From WorkItems
                Where [工作项类型] = 'Bug' ");
            foreach (WorkItem item in queryResults)
            {
                Console.WriteLine(" 工作项名称:"+item.Title+" 工作项描述:"+item.Description);
            }

  三、多条件查询和排序

           Console.WriteLine("--------------------------多条件查询和排序-------------------------");
            //多条件查询和排序
            WorkItemCollection itemcollection = workItemStore.Query(@"Select [标题] from workitems 
                where [工作项类型]='任务' and [指派给] = 'administrator' order by [标题] ");
            foreach (WorkItem item in itemcollection)
            {
                Console.WriteLine(" 工作项名称:" + item.Title + " 工作项描述:" + item.Description);
            }

  四、查询结果数量

            Console.WriteLine("--------------------------查询结果数量-------------------------");
            //查询结果数量
            string queryString = @" Select  [标题] From WorkItems Where [工作项类型] = 'Bug'";
            Query query = new Query(workItemStore,queryString); 
            int numWorkItems = query.RunCountQuery();
            Console.WriteLine("工作项数量 " + numWorkItems + " user stories.");

  五、异步查询

            Console.WriteLine("--------------------------异步查询-------------------------");
            //异步查询
            ICancelableAsyncResult callback = query.BeginQuery();
            callback.AsyncWaitHandle.WaitOne(50, false);
            WorkItemCollection result = query.EndQuery(callback);
            foreach (WorkItem item in result)
            {
                Console.WriteLine(" 工作项名称:" + item.Title + " 工作项描述:" + item.Description);
            }

  所有本文的代码皆在下面。

            //TFSURI
            Uri tfsUri = new Uri("http://pc-20130113jkun:8080/tfs");
            TfsTeamProjectCollection projectCollection = new TfsTeamProjectCollection(tfsUri);
            WorkItemStore workItemStore = (WorkItemStore)projectCollection.GetService(typeof(WorkItemStore));
            Console.WriteLine("--------------------------基本查询-------------------------");
            //基本查询
            WorkItemCollection queryResults = workItemStore.Query(@"
                Select  [标题] 
                From WorkItems
                Where [工作项类型] = 'Bug' ");
            foreach (WorkItem item in queryResults)
            {
                Console.WriteLine(" 工作项名称:"+item.Title+" 工作项描述:"+item.Description);
            }

            Console.WriteLine("--------------------------多条件查询和排序-------------------------");
            //多条件查询和排序
            WorkItemCollection itemcollection = workItemStore.Query(@"Select [标题] from workitems 
                where [工作项类型]='任务' and [指派给] = 'administrator' order by [标题] ");
            foreach (WorkItem item in itemcollection)
            {
                Console.WriteLine(" 工作项名称:" + item.Title + " 工作项描述:" + item.Description);
            }

            Console.WriteLine("--------------------------查询结果数量-------------------------");
            //查询结果数量
            string queryString = @" Select  [标题] From WorkItems Where [工作项类型] = 'Bug'";
            Query query = new Query(workItemStore,queryString); 
            int numWorkItems = query.RunCountQuery();
            Console.WriteLine("工作项数量 " + numWorkItems + " user stories.");

            Console.WriteLine("--------------------------异步查询-------------------------");
            //异步查询
            ICancelableAsyncResult callback = query.BeginQuery();
            callback.AsyncWaitHandle.WaitOne(50, false);
            WorkItemCollection result = query.EndQuery(callback);
            foreach (WorkItem item in result)
            {
                Console.WriteLine(" 工作项名称:" + item.Title + " 工作项描述:" + item.Description);
            }

            Console.ReadLine();

  

发表评论
用户名: 匿名