2017-05-29 5 views
0

私はVisual Studio Team Servicesにアクセスするための.NETライブラリを使用しています。私はマイクロソフトの面倒なデザイン上の欠陥を回避しようとしています。明らかに、サーバー/アカウントごとに複数のコレクションを持つことはできませんので、マイクロソフトではさらにthey map to the same thingを作成しているので、この例ではコレクションと呼ばれるいくつかのアカウントを使用する必要があります。すべての作業項目をすべてのTeam Servicesアカウントで取得するにはどうすればよいですか?

私が実際に達成しようとしているのは、私がメンバーになっているすべてのコレクションのすべての作業項目をリストにすることです。 GetAllCollections()を使用してすべてのコレクションを取得するQueryWorkItems()メソッドがあります。その方法はテストされ、それは動作し、私は持っている2つのアカウントを返します。全体をトリガーするトップレベルのメソッドはAssignedWorkItems()です。次のように私のコードは次のとおりです。

 public static List<TfsTeamProjectCollection> GetAllCollections() 
     { 
      // Get collections/accounts associated with user 
      string request = "https://app.vssps.visualstudio.com/_apis/Accounts?memberId=" + versionControl.AuthorizedIdentity.TeamFoundationId + "&api-version=3.2-preview"; 
      string content = MakeRequestToAPI(request).Result; 
      dynamic results = JsonConvert.DeserializeObject<dynamic>(content); 
      List<TfsTeamProjectCollection> collections = new List<TfsTeamProjectCollection>(); 
      // Iterate through all collections 
      Parallel.ForEach((IEnumerable<dynamic>)results.value, collection => 
      { 
       TfsTeamProjectCollection col = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri((string)collection.accountUri)); 
       collections.Add(col); 
      }); 
      return collections; 
     } 


     public static List<WorkItem> QueryWorkItems(string query) 
     { 
      List<WorkItem> workItems = new List<WorkItem>(); 
      List<TfsTeamProjectCollection> collections = GetAllCollections(); 
      //Parallel.ForEach(collections, collection => 
      foreach(var collection in collections) 
      { 
       WorkItemCollection items = collection.GetService<WorkItemStore>().Query(query); 
       // Add each work item to the overall list 
       Parallel.For(0, items.Count, i => 
       { 
        Console.WriteLine(items[i].Title); 
        lock (workItems) 
        { 
         workItems.Add(items[i]); 
        } 
       }); 
      } 

      return workItems; 
     } 

     public static List<WorkItem> AssignedWorkItems() 
     { 
      Init(); //initializes variables like projectName, workItemStore and VersionControlServer(versionControl) 
      string myItems = "select * from issue where [System.AssignedTo][email protected]"; 
      return QueryWorkItems(myItems); 
     } 

私はAssignedWorkItemsメソッドを呼び出すと、私はデフォルトの接続すでにセットアップを持っているにもかかわらず、ログインプロンプトを取得した:i入力した後enter image description here

私の資格情報しかし、この行に:

WorkItemCollection items = collection.GetService().Query(query);

私は次のエラーを取得する:

An unhandled exception of type 'Microsoft.TeamFoundation.TeamFoundationServiceUnavailableException' occurred in Microsoft.TeamFoundation.Client.dll

Additional information: TF31002: Unable to connect to this Team Foundation Server: https://xxxxxx.vssps.visualstudio.com/ .

Team Foundation Server Url: https://xxxxxx.vssps.visualstudio.com/

Possible reasons for failure include:

  • The name, port number, or protocol for the Team Foundation Server is incorrect.

  • The Team Foundation Server is offline.

  • The password has expired or is incorrect.

面白いことは、私がこれを実行するたびに、私が持っている2つのコレクションの間で前後にエラーが切り替わるということです。なぜこれが起こっているのか、どんな考えですか?

答えて

1

QueryWorkItemsをテストできます。

入手したエラーメッセージに基づいて、https://account.visualstudio.comの代わりにの形式でcollectionsに格納されているVSTS URLのようです。そのため、コレクションに格納されているURL GetAllCollectionsが正しいことを確認してください。

私はQueryWorkItemsを確認するために、このGetAllCollections方法使用:

public static List<TfsTeamProjectCollection> GetAllCollections() 
{ 

    List<TfsTeamProjectCollection> collections = new List<TfsTeamProjectCollection>(); 

    NetworkCredential cred1 = new NetworkCredential("username for Alternate authentication", "password for Alternate authentication"); 
    TfsTeamProjectCollection tpc1 = new TfsTeamProjectCollection(new Uri("https://account1.visualstudio.com"), cred1); 

    collections.Add(tpc1); 

    NetworkCredential cred2 = new NetworkCredential("username for Alternate authentication", "password for Alternate authentication"); 
    TfsTeamProjectCollection tpc2 = new TfsTeamProjectCollection(new Uri("https://account2.visualstudio.com"), cred2); 

    collections.Add(tpc2); 
    return collections; 
} 
+0

をおかげで、これは問題であるように思われました。私は本当に資格を設定する必要がありますか?私がログインしていない場合はログインプロンプトが表示されます。 資格情報を設定する必要がある場合、すべてのコレクションに対して同じ資格情報を設定することはできませんか?私は後にすべてのメンバーです。 – sonicadv27

+0

コード実行時に資格情報を入力しないようにするだけで済みます。代わりに 'TfsTeamProjectCollectionFactory.GetTeamProjectCollection(新しいUri(" https://account.visualstudio.com "))'を使用することもできます。 –

関連する問題