public async Task InitializeDownload(Form OwnerForm, string path, List <AbstractFile> DownloadList) { int count = DownloadList.Count, enumerator = 0; CopyProgress window = new CopyProgress("0", count.ToString()); window.Owner = OwnerForm; window.Show(); string ResultPath = String.Empty; foreach (ConcreteFile file in DownloadList) { /*if (DownloadList.Count < 2) * { * ResultPath = path; * } * else * { * ResultPath = path + @"\" + file.FileName; * }*/ ResultPath = (DownloadList.Count < 2) ? path : path + @"\" + file.FileName; using (FileStream fstream = new FileStream(ResultPath, FileMode.CreateNew)) { IDownloadResponse <FileMetadata> GetFile = await client.Files.DownloadAsync(file.FilePath); byte[] FileAsBytes = await GetFile.GetContentAsByteArrayAsync(); await fstream.WriteAsync(FileAsBytes, 0, FileAsBytes.Length); enumerator++; window.RefreshData(enumerator, count); } } }
protected override async Task PerformIO() { IDownloadResponse <FileMetadata> data = await _client.Files.GetThumbnailAsync(ODFileUtils.CombinePaths(Folder, FileName, '/') , size : ThumbnailSize.W128h128.Instance); FileContent = await data.GetContentAsByteArrayAsync(); }
public async Task Download(string folder, string file) { using (var client = new DropboxClient(AccessToken)) { using (IDownloadResponse <FileMetadata> response = await client.Files.DownloadAsync(folder + "/" + file)) { LastDownloadedFile = await response.GetContentAsByteArrayAsync(); } } }
//All units used here has been unit tested seperately protected override List <string> PerformExecution(Dictionary <string, string> evaluatedValues) { string localToPath; evaluatedValues.TryGetValue("ToPath", out localToPath); string localFromPath; evaluatedValues.TryGetValue("FromPath", out localFromPath); IDropboxSingleExecutor <IDropboxResult> dropBoxDownLoad = new DropBoxDownLoad(localToPath); var dropboxSingleExecutor = GetDropboxSingleExecutor(dropBoxDownLoad); _dropboxClientWrapper = _dropboxClientWrapper ?? new DropboxClientWrapper(GetClient()); var dropboxExecutionResult = dropboxSingleExecutor.ExecuteTask(_dropboxClientWrapper); var dropboxSuccessResult = dropboxExecutionResult as DropboxDownloadSuccessResult; if (dropboxSuccessResult != null) { Response = dropboxSuccessResult.GetDownloadResponse(); var bytes = Response.GetContentAsByteArrayAsync().Result; if (Response.Response.IsFile) { LocalPathManager = new LocalPathManager(localFromPath); var validFolder = LocalPathManager.GetFullFileName(); var fileExist = LocalPathManager.FileExist(); if (fileExist && !OverwriteFile) { throw new Exception(ErrorResource.DropBoxDestinationFileAlreadyExist); } DropboxFile.WriteAllBytes(validFolder, bytes); } return(new List <string> { GlobalConstants.DropBoxSuccess }); } var dropboxFailureResult = dropboxExecutionResult as DropboxFailureResult; if (dropboxFailureResult != null) { Exception = dropboxFailureResult.GetException(); } var executionError = Exception.InnerException?.Message ?? Exception.Message; if (executionError.Contains("not_file")) { executionError = ErrorResource.DropBoxFilePathMissing; } throw new Exception(executionError); }
public override async Task <CloudProviderResponse <byte[]> > GetFileInMemory(string path) { try { Logger.Log(LoggerMessageType.Information | LoggerMessageType.VerboseHigh, "DropboxStorageProvider PutFile '{0}'.", path); //we should really download to a temporary location IDownloadResponse <FileMetadata> downloadResponse = await _client.Files.DownloadAsync(path); byte[] data = await downloadResponse.GetContentAsByteArrayAsync(); return(new CloudProviderResponse <byte[]>(data)); } catch (AuthException ae) { Logger.Log(LoggerMessageType.Information | LoggerMessageType.VerboseHigh, "An authorisation error occurred whilst attempting to get file '{0}' from DropboxStorageProvider. {1}", path, ae.Message); return(new CloudProviderResponse <byte[]>(CloudProviderResponse <byte[]> .Response.AuthenticationError, ae)); } catch (DropboxException de) { Logger.Log(LoggerMessageType.Information | LoggerMessageType.VerboseHigh, "An error occurred whilst attempting to get file '{0}' from DropboxStorageProvider. {1}", path, de.Message); if (de.Message.ToLower().Contains("not_found")) { return(new CloudProviderResponse <byte[]>(CloudProviderResponse <byte[]> .Response.NotFound, de)); } else { return(new CloudProviderResponse <byte[]>(CloudProviderResponse <byte[]> .Response.UnknownError, de)); } } catch (Exception ex) { Logger.Log(LoggerMessageType.Information | LoggerMessageType.VerboseHigh, "An unknown error occurred whilst attempting to get file '{0}' from DropboxStorageProvider. {1}", path, ex.Message); return(new CloudProviderResponse <byte[]>(CloudProviderResponse <byte[]> .Response.UnknownError, ex)); } }
/// <summary> /// Reads content of the underlying file as a byte array. /// </summary> /// <returns>Content of the underlying file as a byte array.</returns> /// <exception cref="AccessDeniedException"></exception> /// <exception cref="DirectoryNotFoundException"></exception> /// <exception cref="FileNotFoundException"></exception> /// <exception cref="PathTooLongException"></exception> /// <exception cref="FileStorageException"></exception> public async Task <byte[]> ReadBytesAsync() { try { using (DropboxClient dropboxClient = new DropboxClient(this.accessToken)) using (IDownloadResponse <FileMetadata> response = await dropboxClient.Files.DownloadAsync(this.filepath)) return(await response.GetContentAsByteArrayAsync()); } catch (ApiException <DownloadError> e) { if (e.ErrorResponse.IsPath) { throw new DirectoryNotFoundException($"Directory not found: \"{this.filepath}\". See inner exception for details.", e); } throw new FileStorageException($"Generic file storage exception: \"{this.filepath}\". See inner exception for details.", e); } catch (Exception e) { throw new FileStorageException($"Generic file storage exception: \"{this.filepath}\". See inner exception for details.", e); } }