private async Task <Stream> ToStream(DropboxAttribute attribute, ValueBindingContext arg2) { var client = this.GetClient(attribute); if (attribute.Access == FileAccess.Read) { try { var response = await client.Files.DownloadAsync(attribute.Path); var res = await response.GetContentAsStreamAsync(); return(res); } catch (DropboxException e) { if (IsFileNotFoundException(e)) { return(null); } throw e; } } else if (attribute.Access == FileAccess.Write) { Stream stream = new ChunkUploadStream(client, attribute.Path); stream = new BufferedStream(stream); return(stream); } throw new InvalidOperationException("Cannot bind using FileAccess.ReadWrite: must be either read or write."); }
public DropboxClient GetClient(DropboxAttribute attribute) { var cx = attribute.Connection ?? this.Connection; return(new DropboxClient(cx)); }