2017-03-28 13 views
1

アプリケーションの大量収集をテスト中にMicrosoft Graph CSharp SDKに対してコーディングしています。私は自分のコードにページングの問題があることに気づいた。 OneDriveのテスト用のアカウントに1000個の1Kバイトのファイルを追加しました。コードを実行してすべてのファイルにアクセスできるかどうかを確認しました。残念ながら、私は1つのフォルダ内の200個のファイルしか見ることができませんでした。全部で1000個ではありませんでした。Microsoft Graph CSharp SDK - DriveItems-ページングが機能していないため、1000個のアイテムのうち200個のアイテムを取り出すことができません。

私はオンラインでこのGitHubを見つけました(現在は閉じています)bug

NextPageRequestnullと表示されています。私はちょうどこれにバグがないことを確認し、私が正しくNextPageRequestを使用していることを確認したいと思っていました。

コード:

public Collection<DriveItem> GetSubItems(string id, string username) 
{ 
    Collection<DriveItem> response = new Collection<DriveItem>(); 
    var retryCount = 0; 

    try 
    { 

     response = RetryPolicy.Default.Retry<Exception, Collection<DriveItem>>(
     this.maxRetryCount, 
     RetryDurationStrategies.ExponentialBackoff, 
     (exception, timeSpan) => 
     { 
      retryCount++; 
      this.LogInfo(Strings.RetryPolicyMessage, exception.Message, timeSpan); 
     }, 
     () => 
     { 
      var driveItems = new List<DriveItem>(); 
      var driveItemsPage = this.GraphServiceClient.GetItemAndChildrenTask(id, username); 
      var result = driveItemsPage.Result; 
      driveItems.AddRange(result.Children.CurrentPage); 

      while (result.Children.NextPageRequest != null) 
      { 
       var nextPageResult = result.Children.NextPageRequest.GetAsync(); 
       var nextPage = nextPageResult.Result; 
       driveItems.AddRange(nextPage.CurrentPage); 
      } 

      Collection<DriveItem> driveItemsList = new Collection<DriveItem>(driveItems); 

      return driveItemsList; 
     }); 
    } 
    catch (ServiceException ex) 
    { 
     switch (ex.Error.Code) 
     { 
      case ItemNotFound: 
       this.LogWarning(ex, Strings.OneDriveItemNotFound, ex.Message); 
       break; 
      case InvalidRequestItemId: 
       this.LogWarning(ex, Strings.OneDriveUserNotFound, ex.Message); 
       break; 
      default: 
       this.LogWarning(ex, Strings.OneDriveGenericException, ex.Message); 
       break; 
     } 
    } 
    catch (AdalServiceException ex) 
    { 
     switch (ex.ErrorCode) 
     { 
      case InvalidClient: 
       this.LogWarning(ex, Strings.AdalInvalidClientErrorMsg, ex.Message); 
       break; 
      case UnauthorizedClient: 
       this.LogWarning(ex, Strings.AdalUnauthorizedClientErrorMsg, ex.Message); 
       break; 
      case InvalidRequestSecret: 
       this.LogWarning(ex, Strings.AdalInvalidRequestErrorMsg, ex.Message); 
       break; 
      default: 
       this.LogWarning(ex, Strings.AdalGenericErrorMsg, ex.Message); 
       break; 
     } 

     throw new PluginException(string.Format(Strings.AuthenticationToOneDriveWasUnsuccessful, ex.Message), ex.InnerException); 
    } 
    catch (Exception ex) 
    { 
     this.LogWarning(ex, Strings.OneDriveGenericException, ex.Message); 

     throw new PluginException(Strings.GenericPluginException, ex.InnerException); 
    } 

    return response; 
} 

Microsoft Graph SDKへの呼び出し:

enter image description here

答えて

1

あなたの基本的なグラフの要求:

以下
public Task<DriveItem> GetItemAndChildrenTask(string id, string username) 
{ 
    return this.GraphServiceClient.Drives[username].Items[id].Request().Expand(ExpandValue).GetAsync(); 
} 

result変数のためのスクリーンショットであります具体的に行う必要があるNextPageRequestの子がnullでないようにします。

graphServiceClient.Drives[username].Items[id].Children.Request().GetAsync(); 

あなたが何かを行う場合は、次の

graphServiceClient.Drives[username].Items[id].Request().Expand('children').GetAsync(); 

を次にNextPageRequestが取り込まれることはありません。

+1

このアプローチは有効な回避策ですが、元のコード*は機能するはずです。何らかの理由でGraphが、拡張されたコレクションの 'children @ odata.nextlink'を返さないときに、何らかの理由でGraphが返されるように見えます。 OneDrive API **はそれを返します。なぜGraphが異なる動作をしているのかを理解する必要があります。 – Brad

関連する問題