diff --git a/doc/reference/src/api.xml b/doc/reference/src/api.xml index 2aad8ab..90856f6 100644 --- a/doc/reference/src/api.xml +++ b/doc/reference/src/api.xml @@ -80,6 +80,10 @@ IDropbox dropboxApi = serviceProvider.GetApi(accessToken.Value, accessToken.Secr DropboxFile DownloadFile(string path, string revision); + DropboxFile DownloadPartialFile(string path, long startOffset, long length); + + DropboxFile DownloadPartialFile(string path, long startOffset, long length, string revision); + DeltaPage Delta(string cursor); Entry GetMetadata(string path); diff --git a/doc/reference/src/index.xml b/doc/reference/src/index.xml index 966c867..1c7a0f9 100644 --- a/doc/reference/src/index.xml +++ b/doc/reference/src/index.xml @@ -13,7 +13,7 @@ Copyright 2012 SpringSource - Last Updated 11/3/2012 + Last Updated 11/9/2012 Bruno diff --git a/src/Spring.Social.Dropbox/Social/Dropbox/Api/IDropbox.cs b/src/Spring.Social.Dropbox/Social/Dropbox/Api/IDropbox.cs index cf7a540..aca57cf 100644 --- a/src/Spring.Social.Dropbox/Social/Dropbox/Api/IDropbox.cs +++ b/src/Spring.Social.Dropbox/Social/Dropbox/Api/IDropbox.cs @@ -212,6 +212,40 @@ public interface IDropbox : IApiBinding /// If there is an error while communicating with Dropbox. Task DownloadFileAsync(string path, string revision, CancellationToken cancellationToken); + /// + /// Asynchronously downloads part of a file and its metadata. + /// + /// The Dropbox path to the file you want to retrieve, relative to root. + /// The zero-based starting position of the part file. + /// The number of bytes of the part file. + /// + /// A 'Task' that represents the asynchronous operation that can return + /// a object containing the part of file's content and metadata. + /// + /// If there is an error while communicating with Dropbox. + Task DownloadPartialFileAsync(string path, long startOffset, long length); + + /// + /// Asynchronously downloads part of a file and its metadata. + /// + /// The Dropbox path to the file you want to retrieve, relative to root. + /// The zero-based starting position of the part file. + /// The number of bytes of the part file. + /// + /// The revision of the file to retrieve, or for the latest version. + /// + /// + /// The that will be assigned to the task. + /// + /// Use for an empty value. + /// + /// + /// A 'Task' that represents the asynchronous operation that can return + /// a object containing the part of file's content and metadata. + /// + /// If there is an error while communicating with Dropbox. + Task DownloadPartialFileAsync(string path, long startOffset, long length, string revision, CancellationToken cancellationToken); + /// /// Asynchronously keeps up with changes to files and folders in a user's Dropbox. /// @@ -501,6 +535,33 @@ public interface IDropbox : IApiBinding /// If there is an error while communicating with Dropbox. DropboxFile DownloadFile(string path, string revision); + /// + /// Downloads part of a file and its metadata. + /// + /// The Dropbox path to the file you want to retrieve, relative to root. + /// The zero-based starting position of the part file. + /// The number of bytes of the part file. + /// + /// A object containing the part of file's content and metadata. + /// + /// If there is an error while communicating with Dropbox. + DropboxFile DownloadPartialFile(string path, long startOffset, long length); + + /// + /// Downloads part of a file and its metadata. + /// + /// The Dropbox path to the file you want to retrieve, relative to root. + /// The zero-based starting position of the part file. + /// The number of bytes of the part file. + /// + /// The revision of the file to retrieve, or for the latest version. + /// + /// + /// A object containing the part of file's content and metadata. + /// + /// If there is an error while communicating with Dropbox. + DropboxFile DownloadPartialFile(string path, long startOffset, long length, string revision); + /// /// Keeps up with changes to files and folders in a user's Dropbox. /// @@ -829,6 +890,41 @@ public interface IDropbox : IApiBinding /// If there is an error while communicating with Dropbox. RestOperationCanceler DownloadFileAsync(string path, string revision, Action> operationCompleted); + /// + /// Asynchronously downloads part of a file and its metadata. + /// + /// The Dropbox path to the file you want to retrieve, relative to root. + /// The zero-based starting position of the part file. + /// The number of bytes of the part file. + /// + /// The 'Action<>' to perform when the asynchronous request completes. + /// Provides object containing the part of file's content and metadata. + /// + /// + /// A instance that allows to cancel the asynchronous operation. + /// + /// If there is an error while communicating with Dropbox. + RestOperationCanceler DownloadPartialFileAsync(string path, long startOffset, long length, Action> operationCompleted); + + /// + /// Asynchronously downloads part of a file and its metadata. + /// + /// The Dropbox path to the file you want to retrieve, relative to root. + /// The zero-based starting position of the part file. + /// The number of bytes of the part file. + /// + /// The revision of the file to retrieve, or for the latest version. + /// + /// + /// The 'Action<>' to perform when the asynchronous request completes. + /// Provides object containing the part of file's content and metadata. + /// + /// + /// A instance that allows to cancel the asynchronous operation. + /// + /// If there is an error while communicating with Dropbox. + RestOperationCanceler DownloadPartialFileAsync(string path, long startOffset, long length, string revision, Action> operationCompleted); + /// /// Asynchronously keeps up with changes to files and folders in a user's Dropbox. /// diff --git a/src/Spring.Social.Dropbox/Social/Dropbox/Api/Impl/DropboxTemplate.cs b/src/Spring.Social.Dropbox/Social/Dropbox/Api/Impl/DropboxTemplate.cs index 63a492f..bdd995b 100644 --- a/src/Spring.Social.Dropbox/Social/Dropbox/Api/Impl/DropboxTemplate.cs +++ b/src/Spring.Social.Dropbox/Social/Dropbox/Api/Impl/DropboxTemplate.cs @@ -325,6 +325,53 @@ public Task DownloadFileAsync(string path, string revision, Cancell return this.RestTemplate.ExecuteAsync(this.BuildDownloadUrl(path, revision), HttpMethod.GET, requestCallback, responseExtractor, cancellationToken); } + /// + /// Asynchronously downloads part of a file and its metadata. + /// + /// The Dropbox path to the file you want to retrieve, relative to root. + /// The zero-based starting position of the part file. + /// The number of bytes of the part file. + /// + /// A 'Task' that represents the asynchronous operation that can return + /// a object containing the part of file's content and metadata. + /// + /// If there is an error while communicating with Dropbox. + public Task DownloadPartialFileAsync(string path, long startOffset, long length) + { + return this.DownloadPartialFileAsync(path, startOffset, length, null, CancellationToken.None); + } + + /// + /// Asynchronously downloads part of a file and its metadata. + /// + /// The Dropbox path to the file you want to retrieve, relative to root. + /// The zero-based starting position of the part file. + /// The number of bytes of the part file. + /// + /// The revision of the file to retrieve, or for the latest version. + /// + /// + /// The that will be assigned to the task. + /// + /// Use for an empty value. + /// + /// + /// A 'Task' that represents the asynchronous operation that can return + /// a object containing the part of file's content and metadata. + /// + /// If there is an error while communicating with Dropbox. + public Task DownloadPartialFileAsync(string path, long startOffset, long length, string revision, CancellationToken cancellationToken) + { + HttpEntity requestEntity = new HttpEntity(); + requestEntity.Headers.Add("Range", String.Format("bytes={0}-{1}", startOffset, startOffset + length - 1)); + return this.RestTemplate.ExchangeAsync( + this.BuildDownloadUrl(path, revision), HttpMethod.GET, requestEntity, cancellationToken) + .ContinueWith(task => + { + return task.Result.Body; + }); + } + /// /// Asynchronously keeps up with changes to files and folders in a user's Dropbox. /// @@ -728,6 +775,42 @@ public DropboxFile DownloadFile(string path, string revision) return this.RestTemplate.Execute(this.BuildDownloadUrl(path, revision), HttpMethod.GET, requestCallback, responseExtractor); } + /// + /// Downloads part of a file and its metadata. + /// + /// The Dropbox path to the file you want to retrieve, relative to root. + /// The zero-based starting position of the part file. + /// The number of bytes of the part file. + /// + /// A object containing the part of file's content and metadata. + /// + /// If there is an error while communicating with Dropbox. + public DropboxFile DownloadPartialFile(string path, long startOffset, long length) + { + return this.DownloadPartialFile(path, startOffset, length, null); + } + + /// + /// Downloads part of a file and its metadata. + /// + /// The Dropbox path to the file you want to retrieve, relative to root. + /// The zero-based starting position of the part file. + /// The number of bytes of the part file. + /// + /// The revision of the file to retrieve, or for the latest version. + /// + /// + /// A object containing the part of file's content and metadata. + /// + /// If there is an error while communicating with Dropbox. + public DropboxFile DownloadPartialFile(string path, long startOffset, long length, string revision) + { + HttpEntity requestEntity = new HttpEntity(); + requestEntity.Headers.Add("Range", String.Format("bytes={0}-{1}", startOffset, startOffset + length - 1)); + return this.RestTemplate.Exchange( + this.BuildDownloadUrl(path, revision), HttpMethod.GET, requestEntity).Body; + } + /// /// Keeps up with changes to files and folders in a user's Dropbox. /// @@ -1175,6 +1258,55 @@ public RestOperationCanceler DownloadFileAsync(string path, string revision, Act return this.RestTemplate.ExecuteAsync(this.BuildDownloadUrl(path, revision), HttpMethod.GET, requestCallback, responseExtractor, operationCompleted); } + /// + /// Asynchronously downloads part of a file and its metadata. + /// + /// The Dropbox path to the file you want to retrieve, relative to root. + /// The zero-based starting position of the part file. + /// The number of bytes of the part file. + /// + /// The 'Action<>' to perform when the asynchronous request completes. + /// Provides object containing the part of file's content and metadata. + /// + /// + /// A instance that allows to cancel the asynchronous operation. + /// + /// If there is an error while communicating with Dropbox. + public RestOperationCanceler DownloadPartialFileAsync(string path, long startOffset, long length, Action> operationCompleted) + { + return this.DownloadPartialFileAsync(path, startOffset, length, null, operationCompleted); + } + + /// + /// Asynchronously downloads part of a file and its metadata. + /// + /// The Dropbox path to the file you want to retrieve, relative to root. + /// The zero-based starting position of the part file. + /// The number of bytes of the part file. + /// + /// The revision of the file to retrieve, or for the latest version. + /// + /// + /// The 'Action<>' to perform when the asynchronous request completes. + /// Provides object containing the part of file's content and metadata. + /// + /// + /// A instance that allows to cancel the asynchronous operation. + /// + /// If there is an error while communicating with Dropbox. + public RestOperationCanceler DownloadPartialFileAsync(string path, long startOffset, long length, string revision, Action> operationCompleted) + { + HttpEntity requestEntity = new HttpEntity(); + requestEntity.Headers.Add("Range", String.Format("bytes={0}-{1}", startOffset, startOffset + length - 1)); + return this.RestTemplate.ExchangeAsync( + this.BuildDownloadUrl(path, revision), HttpMethod.GET, requestEntity, + r => + { + operationCompleted(new RestOperationCompletedEventArgs( + r.Error == null ? r.Response.Body : null, r.Error, r.Cancelled, r.UserState)); + }); + } + /// /// Asynchronously keeps up with changes to files and folders in a user's Dropbox. /// diff --git a/test/Spring.Social.Dropbox.Tests/Social/Dropbox/Api/Impl/DropboxTemplateTests.cs b/test/Spring.Social.Dropbox.Tests/Social/Dropbox/Api/Impl/DropboxTemplateTests.cs index 194886f..ff777d8 100644 --- a/test/Spring.Social.Dropbox.Tests/Social/Dropbox/Api/Impl/DropboxTemplateTests.cs +++ b/test/Spring.Social.Dropbox.Tests/Social/Dropbox/Api/Impl/DropboxTemplateTests.cs @@ -321,6 +321,45 @@ public void DownloadFile() Assert.IsNull(file.Metadata.Contents); } + [Test] + public void DownloadPartialFile() + { + responseHeaders["x-dropbox-metadata"] = "{ \"size\": \"225.4KB\", \"rev\": \"35e97029684fe\", \"thumb_exists\": false, \"bytes\": 230783, \"modified\": \"Tue, 19 Jul 2011 21:55:38 +0000\", \"path\": \"/Getting_Started.pdf\", \"is_dir\": false, \"icon\": \"page_white_acrobat\", \"root\": \"dropbox\", \"mime_type\": \"application/pdf\", \"revision\": 220823 }"; + responseHeaders.ContentType = MediaType.TEXT_PLAIN; + mockServer.ExpectNewRequest() + .AndExpectUri("https://api-content.dropbox.com/1/files/dropbox/Dir/File.txt?rev=a123z") + .AndExpectMethod(HttpMethod.GET) + .AndExpectHeader("Range", "bytes=0-1023") + .AndRespondWith(EmbeddedResource("File.txt"), responseHeaders); + +#if NET_4_0 || SILVERLIGHT_5 + DropboxFile file = dropbox.DownloadPartialFileAsync("Dir/File.txt", 0, 1024, "a123z", CancellationToken.None).Result; +#else + DropboxFile file = dropbox.DownloadPartialFile("Dir/File.txt", 0, 1024, "a123z"); +#endif + Assert.IsNotNull(file); + + // Content + Assert.IsNotNull(file.Content); + Assert.IsNotEmpty(file.Content); + + // Metadata + Assert.AreEqual(230783, file.Metadata.Bytes); + Assert.IsNull(file.Metadata.Hash); + Assert.AreEqual("page_white_acrobat", file.Metadata.Icon); + Assert.AreEqual(false, file.Metadata.IsDeleted); + Assert.AreEqual(false, file.Metadata.IsDirectory); + Assert.AreEqual("application/pdf", file.Metadata.MimeType); + Assert.IsNotNull(file.Metadata.ModifiedDate); + Assert.AreEqual("19/07/2011 21:55:38", file.Metadata.ModifiedDate.Value.ToUniversalTime().ToString("dd'/'MM'/'yyyy HH:mm:ss")); + Assert.AreEqual("/Getting_Started.pdf", file.Metadata.Path); + Assert.AreEqual("35e97029684fe", file.Metadata.Revision); + Assert.AreEqual("dropbox", file.Metadata.Root); + Assert.AreEqual("225.4KB", file.Metadata.Size); + Assert.IsFalse(file.Metadata.ThumbExists); + Assert.IsNull(file.Metadata.Contents); + } + [Test] public void Delta() {