public override async Task<DirectoryEntry[]> GetDirectories(CancellationToken cancellation) {
await Prepare(cancellation);
if (_authToken == null) {
throw new Exception(ToolsStrings.Uploader_AuthenticationTokenIsMissing);
}
const string query = "mimeType='application/vnd.google-apps.folder' and trashed = false and 'me' in writers";
const string fields = "items(id,parents(id,isRoot),title)";
var data = await Request.Get<SearchResult>(
@"https://www.googleapis.com/drive/v2/files?maxResults=1000&orderBy=title&" +
$"q={HttpUtility.UrlEncode(query)}&fields={HttpUtility.UrlEncode(fields)}",
_authToken.AccessToken, cancellation);
if (data == null) {
throw new Exception(ToolsStrings.Uploader_RequestFailed);
}
var directories = data.Items.Select(x => new DirectoryEntry {
Id = x.Id,
DisplayName = x.Title
}).ToList();
foreach (var directory in directories) {
directory.Children = data.Items.Where(x => x.Parents.Any(y => !y.IsRoot && y.Id == directory.Id))
.Select(x => directories.GetById(x.Id)).ToArray();
}
return new [] {
new DirectoryEntry {
Id = null,
DisplayName = ToolsStrings.Uploader_RootDirectory,
Children = data.Items.Where(x => x.Parents.All(y => y.IsRoot)).Select(x => directories.GetById(x.Id)).ToArray()
}
};
}