アプリケーションの大量収集をテスト中にMicrosoft Graph CSharp SDK
に対してコーディングしています。私は自分のコードにページングの問題があることに気づいた。 OneDriveのテスト用のアカウントに1000個の1Kバイトのファイルを追加しました。コードを実行してすべてのファイルにアクセスできるかどうかを確認しました。残念ながら、私は1つのフォルダ内の200個のファイルしか見ることができませんでした。全部で1000個ではありませんでした。Microsoft Graph CSharp SDK - DriveItems-ページングが機能していないため、1000個のアイテムのうち200個のアイテムを取り出すことができません。
私はオンラインでこのGitHubを見つけました(現在は閉じています)bug。
NextPageRequest
はnull
と表示されています。私はちょうどこれにバグがないことを確認し、私が正しく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
への呼び出し:
このアプローチは有効な回避策ですが、元のコード*は機能するはずです。何らかの理由でGraphが、拡張されたコレクションの 'children @ odata.nextlink'を返さないときに、何らかの理由でGraphが返されるように見えます。 OneDrive API **はそれを返します。なぜGraphが異なる動作をしているのかを理解する必要があります。 – Brad