我在使用view.delta
(https://dev.onedrive.com/items/view_delta.htm)在两个不同的子文件夹上同步OneDrive的更改时遇到问题。我正在使用OneDrive API SDK(C#)。
OneDrive上的我的文件夹结构如下:
appFolder /数据/文件夹1
appFolder /数据/文件夹2
由于某些特定原因,我想分别跟踪这两个子文件夹folder1
和folder2
的更改,因此我为每个子文件夹使用两个不同的delta标记。
问题是当其他子文件夹中有更改(添加/删除文件)时,例如folder1,调用" view.delta"在该文件夹上正常工作但使用其自己的令牌在另一个子文件夹上调用view.delta
会导致OneDriveException resyncRequired
,尽管该文件夹没有任何更改。
在OneDrive(非OneDrive for Business)上跟踪多个文件夹的更改是否存在一些问题/限制?
重现问题的示例代码:
static async Task Test(IOneDriveClient client)
{
var drive = client.Drive;
// get app folder
var appFolder = await drive.Special.AppRoot.Request().GetAsync();
// create data folder under the app folder
var dataFolder = await drive.Items[appFolder.Id].Children.Request().AddAsync(new Item { Name = "data", Folder = new Folder() });
// create two subfolders folder1 and folder2 under the data folder
var folder1 = await drive.Items[dataFolder.Id].Children.Request().AddAsync(new Item { Name = "folder1", Folder = new Folder() });
var folder2 = await drive.Items[dataFolder.Id].Children.Request().AddAsync(new Item { Name = "folder2", Folder = new Folder() });
// get initial token for the folder1
string token1 = null;
var changedItems1 = await drive.Items[folder1.Id].Delta(token1).Request().GetAsync();
token1 = changedItems1.Token;
// upload some test files under the folder1
var testFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///TestData/Document.txt"));
await UploadFileAsync(client, folder1, testFile, "file1");
await UploadFileAsync(client, folder1, testFile, "file2");
// get updated token for the folder1
changedItems1 = await drive.Items[folder1.Id].Delta(token1).Request().GetAsync();
token1 = changedItems1.Token;
// get initial token for the folder2
string token2 = null;
var changedItems2 = await drive.Items[folder2.Id].Delta(token2).Request().GetAsync();
token2 = changedItems2.Token;
// now make some change under the folder1 (upload, delete)
await UploadFileAsync(client, folder1, testFile, "file3");
// get updated token for the folder1, this works ok
changedItems1 = await drive.Items[folder1.Id].Delta(token1).Request().GetAsync();
token1 = changedItems1.Token;
try
{
// try to get changes for the folder2, this throws OneDriveException
changedItems2 = await drive.Items[folder2.Id].Delta(token2).Request().GetAsync();
token2 = changedItems2.Token;
}
catch (Exception ex)
{
// Exception is thrown with the following message:
// "Resync required. Upload any local items that the service did not return, and upload any files that differ from the server's version (keeping both copies if you're not sure which one is more up-to-date)."
}
}
static async Task UploadFileAsync(IOneDriveClient client, Item destinationFolder, IStorageFile file, string fileName)
{
using (var stream = await file.OpenStreamForReadAsync())
{
var item = await client.Drive.Items[destinationFolder.Id].ItemWithPath(fileName).Content.Request().PutAsync<Item>(stream);
}
}