태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.

분류없음2015.03.23 17:38

using Microsoft.TeamFoundation.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;

namespace ClassLibrary1
{
    public class Class1
    {
        public static TfsTeamProjectCollection GetTeamProjectCollection(string collectionName)
        {
            TfsTeamProjectCollection projectCollection = null;

            var networkCredencial = new NetworkCredential
            {
                UserName = @"domain/username",
                Password = "password"
            };

            var uri = "http://mytfs.company.com:8080/tfs/" + collectionName;
            projectCollection = new TfsTeamProjectCollection(new Uri(uri), networkCredencial);

            return projectCollection;
        }

        public static int GetProjectsCount(string collectionName)
        {
            int projects = 0;

            var teamProjectCollection = GetTeamProjectCollection(collectionName);

            if (teamProjectCollection != null)
            {
                teamProjectCollection.EnsureAuthenticated();

                ReadOnlyCollection<CatalogNode> projectNodes = teamProjectCollection.CatalogNode.QueryChildren(
                    new[] { CatalogResourceTypes.TeamProject },
                    false, CatalogQueryOptions.None);

                projects = projectNodes.Count();
            }
            else
            {
                throw new InvalidOperationException("Invalid TeamProject Collection");
            }

            return projects;
        }
    }
}

 

신고
Posted by webmars