2013-07-19 19 views
5

Yerel olarak ya da kodla eşlenmemiş proje olduğunu öğrenmem gerekiyor. foreach'u workItemStore = new WorkItemStore(projects) için yapabildiğimden ve IsMapped veya MappingPath gibi herhangi bir proje bilgisi alabildiğimden Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory.GetTeamProjectCollection() kullanarak tüm TFS projelerini alabilirim.Program, TFS'de projelendirilmiş olarak nasıl kontrol edilir?

Bilgi Gerekli olan Visual Studio'daki Team Explorer'ın Kaynak Denetim Gezgini'nden kolayca erişilebiliyor, ancak bunu C# kodundan yapmam gerekiyor. Denedim budur

:

var projects = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(_tfsServerUri)); 
projects.Authenticate(); 
var workItemStore = new WorkItemStore(projects); 
foreach (Project pr in workItemStore.Projects) 
    { 
     pr.IsLocal; 
    } 

UPD: CEVAP

Miker cevabı iyidir, ama bir kusuru vardır eklemek istiyorum. Kök dizininiz eşlendiyse ancak yerel bilgisayarınızda bu kök dizinden tüm projeleriniz yoksa, Miker'in çözümü tüm projelerini geri döndürecektir.

TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(_tfsServerUri)); 
teamProjectCollection.Authenticate(); 
VersionControlServer versionControl = teamProjectCollection.GetService<VersionControlServer>(); 

string computerName = Environment.MachineName; 
WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent(); 
// get yours local workspaces 
Workspace[] workspaces = versionControl.QueryWorkspaces(null, windowsIdentity.Name, computerName); 

foreach (Project pr in workItemStore.Projects) 
    { 
     var mapped = false; 

     foreach (Workspace workspace in workspaces) 
     { 
      var path = workspace.TryGetLocalItemForServerItem("$/" + pr.Name); 
      if (!String.IsNullOrEmpty(path) && Directory.Exists(path)) 
      { 
       mapped = true; 
      } 
     } 
    // do what you want with mapped project 
    } 

cevap

3

Bu genel bir yaklaşım daha, ama sadece işaret derlenmiş olup ihtiyaçlarınız (için özelleştirmek için yönetecek düşünüyorum: Eğer kod, bu şekilde hareket etmek istemiyorsanız, işte çözüm yöne doğru):

string project = "TeamProject1"; 
string serverPath = "$/"+project; 
string computername = "myComputer"; // possibly Environment.Computer or something like that 
var tpc= TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(_tfsServerUri)); 
tpc.Authenticate(); 
// connect to VersionControl 
VersionControlServer sourceControl = (VersionControlServer)tpc.GetService(typeof(VersionControlServer)); 
// iterate the local workspaces 
foreach (Workspace workspace in sourceControl.QueryWorkspaces(null, null, computername)) 
{ 
    // check mapped folders 
    foreach (WorkingFolder folder in workspace.Folders) 
    { 
    // e.g. $/TeamProject1 contains $/ if the root is mapped to local 
    if (serverPath.Contains(folder.ServerItem) && !folder.IsCloaked) 
    { 
     Console.WriteLine(serverPath + " is mapped under "+ folder.LocalItem); 
     Console.WriteLine("Workspacename: "+workspace.Name); 
    } 
    } 
} 
İlgili konular