private async Task <bool> EnumerateFilesAndFolders( string curPath, List <CloudStorageProviderFileBase> files, HttpResponseMessage response) { string responseString = await response.Content.ReadAsStringAsync(); JObject responseJSON = JObject.Parse(await response.Content.ReadAsStringAsync()); JArray items = responseJSON["value"].Value <JArray>(); foreach (JObject curItem in items) { string id = curItem["id"].Value <string>(); string name = curItem["name"].Value <string>(); string curItemPath = String.Format("{0}{1}", curPath, name); OneDriveStorageProviderFile curFile = null; try { curFile = OneDriveStorageProviderFile.FromJSON( curItem, curItemPath); } catch (InvalidOperationException ioex) { Logger.Log(LoggerMessageType.Exception, "OneDriveStorageProvider experienced an issue whilst parsing file meta data from '{0}'. {1}", curItemPath, ioex.Message); } if (curFile != null) { files.Add(curFile); if (curFile.IsFolder) { string nextPath = String.Format("{0}{1}/", curPath, name); HttpRequestMessage nextRequest = new HttpRequestMessage(HttpMethod.Get, String.Format("{0}{1}{2}/children", _apiBase, "/me/drive/items/", id)); await AuthDelegate(nextRequest); HttpResponseMessage nextResponse = await _client.SendAsync(nextRequest); if (nextResponse.IsSuccessStatusCode) { if (!await EnumerateFilesAndFolders( nextPath, files, nextResponse)) { return(false); } ; } else { return(false); } } } } return(true); }
public override async Task <CloudProviderResponse <CloudStorageProviderFileBase> > GetFileInfo(string path) { try { Logger.Log(LoggerMessageType.Information | LoggerMessageType.VerboseHigh, "DropboxStorageProvider GetFileInfo '{0}'.", path); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, String.Format("{0}{1}{2}", _apiBase, "/me/drive/special/approot:", path)); await AuthDelegate(request); HttpResponseMessage response = await _client.SendAsync(request); if (response.IsSuccessStatusCode) { string fileString = await response.Content.ReadAsStringAsync(); JObject file = JObject.Parse(fileString); string id = file["id"].Value <string>(); string name = file["name"].Value <string>(); string curItemPath = String.Format("{0}{1}", path, name); try { OneDriveStorageProviderFile curFile = OneDriveStorageProviderFile.FromJSON( file, curItemPath); return(new CloudProviderResponse <CloudStorageProviderFileBase>(curFile)); } catch (InvalidOperationException ioex) { Logger.Log(LoggerMessageType.Exception, "OneDriveStorageProvider experienced an issue whilst parsing file meta data from '{0}'. {1}", curItemPath, ioex.Message); throw; } } else { return(new CloudProviderResponse <CloudStorageProviderFileBase>(CloudProviderResponse <CloudStorageProviderFileBase> .Response.NotFound, (Exception)null)); } } catch (Exception ex) { Logger.Log(LoggerMessageType.Information | LoggerMessageType.VerboseHigh, "An unknown error occurred whilst attempting to get file info for '{0}' from OneDriveStorageProvider. {1}", path, ex.Message); return(new CloudProviderResponse <CloudStorageProviderFileBase>(CloudProviderResponse <CloudStorageProviderFileBase> .Response.UnknownError, ex)); } }