diff --git a/DropNet.Tests/FileAsyncTests.cs b/DropNet.Tests/FileAsyncTests.cs index 707224a..e1e11e9 100644 --- a/DropNet.Tests/FileAsyncTests.cs +++ b/DropNet.Tests/FileAsyncTests.cs @@ -15,8 +15,14 @@ public class FileAsyncTests public FileAsyncTests() { - _client = new DropNetClient(TestVariables.ApiKey, TestVariables.ApiSecret); - _client.UserLogin = new Models.UserLogin { Token = TestVariables.Token, Secret = TestVariables.Secret }; + _client = new DropNetClient(TestVariables.ApiKey, TestVariables.ApiSecret) + { + UserLogin = new UserLogin + { + Token = TestVariables.Token, + Secret = TestVariables.Secret + } + }; _fixture = new Fixture(); } @@ -36,7 +42,7 @@ public void Can_Get_List_Of_Metadata_For_Search_String() { Assert.IsNotNull(s); Assert.AreEqual(1, s.Count); - }, + }, Assert.IsNull); } @@ -74,7 +80,7 @@ public void Can_Upload_File_Async_Streaming() File.WriteAllText(localFile.FullName, localContent, System.Text.Encoding.UTF8); Assert.IsTrue(File.Exists(localFile.FullName)); - byte[] content = _client.GetFileContentFromFS(localFile); + _client.GetFileContentFromFS(localFile); var waitForUploadFinished = new ManualResetEvent(false); using (var fileStream = localFile.OpenRead()) @@ -162,5 +168,10 @@ private void Can_Get_Thumbnail_Async_Failure(DropboxException error) Assert.IsTrue(false); } + [TestMethod] + public void Can_Get_Delta_Async() + { + _client.GetDeltaAsync("", Assert.IsNotNull, f => Assert.Fail(f.ToString())); + } } } diff --git a/DropNet.WindowsPhone/DropNet.WindowsPhone.csproj b/DropNet.WindowsPhone/DropNet.WindowsPhone.csproj index 80615fd..3cfb7e6 100644 --- a/DropNet.WindowsPhone/DropNet.WindowsPhone.csproj +++ b/DropNet.WindowsPhone/DropNet.WindowsPhone.csproj @@ -18,6 +18,10 @@ false true true + %24/WinBox/DropNet/DropNet.WindowsPhone + . + https://prashantvc.tfspreview.com/defaultcollection + {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} true @@ -83,6 +87,9 @@ Models\DeltaPage.cs + + Models\DeltaPageInternal.cs + Models\MetaData.cs diff --git a/DropNet/Client/Files.Async.cs b/DropNet/Client/Files.Async.cs index 80a04a6..d552008 100644 --- a/DropNet/Client/Files.Async.cs +++ b/DropNet/Client/Files.Async.cs @@ -3,8 +3,8 @@ using DropNet.Models; using RestSharp; using System; -using DropNet.Authenticators; using DropNet.Exceptions; +using RestSharp.Deserializers; namespace DropNet { @@ -28,6 +28,22 @@ public void GetMetaDataAsync(string path, Action success, Action + /// Returns a link directly to a file. + /// Similar to /shares. The difference is that this bypasses the Dropbox webserver, used to provide a preview of the file, so that you can effectively stream the contents of your media. + /// + /// The path + /// Success callback + /// Failure callback + public void GetMediaAsync(string path, Action success, Action failure) + { + if (!path.StartsWith("/")) path = "/" + path; + + var request = _requestHelper.CreateMediaRequest(path, Root); + + ExecuteAsync(ApiType.Base, request, success, failure); + } + /// /// Gets MetaData for a File or Folder. For a folder this includes its contents. For a file, this includes details such as file size. /// Optional 'hash' param returns HTTP code 304 (Directory contents have not changed) if contents have not changed since the @@ -80,7 +96,7 @@ public void SearchAsync(string searchString, string path, Action> /// The path of the file to download /// /// Success callback /// Failure callback - + public void GetFileAsync(string path, Action success, Action failure) { if (!path.StartsWith("/")) path = "/" + path; @@ -221,46 +237,69 @@ public void CreateFolderAsync(string path, Action success, ActionFailure callback public void GetShareAsync(string path, Action success, Action failure) { - if (!path.StartsWith("/")) path = "/" + path; + if (!path.StartsWith("/")) + { + path = "/" + path; + } var request = _requestHelper.CreateShareRequest(path, Root); - ExecuteAsync(ApiType.Base, request, success, failure); } /// - /// Returns a link directly to a file. - /// Similar to /shares. The difference is that this bypasses the Dropbox webserver, used to provide a preview of the file, so that you can effectively stream the contents of your media. + /// The beta delta function, gets updates for a given folder /// - /// The path - /// Success callback - /// Failure callback - public void GetMediaAsync(string path, Action success, Action failure) + /// Cursor returned by prvious call + /// Success Callback + /// Failure Callback + public void GetDeltaAsync(string cursor, Action success, Action failure) { - if (!path.StartsWith("/")) path = "/" + path; - - var request = _requestHelper.CreateMediaRequest(path, Root); + var request = _requestHelper.CreateDeltaRequest(cursor); + ExecuteAsync(ApiType.Base, request, + deltaResponse => + { + var deltaPage = new DeltaPage + { + Cursor = deltaResponse.Cursor, + Has_More = deltaResponse.Has_More, + Reset = deltaResponse.Reset, + Entries = new List() + }; + + foreach (var stringList in deltaResponse.Entries) + { + deltaPage.Entries.Add(StringListToDelta(stringList)); + } + + success (deltaPage); + }, - ExecuteAsync(ApiType.Base, request, success, failure); + failure); } /// - /// The beta delta function, gets updates for a given folder + /// Helper function to convert a stringlist to a DeltaEntry object /// - /// - /// - /// - /// - public void GetDeltaAsync(bool IKnowThisIsBetaOnly, string path, Action success, Action failure) + /// + /// + DeltaEntry StringListToDelta(List stringList) { - if (!IKnowThisIsBetaOnly) return; - - if (!path.StartsWith("/")) path = "/" + path; - - var request = _requestHelper.CreateDeltaRequest(path); + var deltaEntry = new DeltaEntry + { + Path = stringList[0] + }; + if (!String.IsNullOrEmpty(stringList[1])) + { + var jsonDeserializer = new JsonDeserializer(); + var fakeresponse = new RestResponse + { + Content = stringList[1] + }; + deltaEntry.MetaData = jsonDeserializer.Deserialize(fakeresponse); + } + return deltaEntry; + } - ExecuteAsync(ApiType.Base, request, success, failure); - } /// /// Gets the thumbnail of an image given its MetaData diff --git a/DropNet/Client/Files.Sync.cs b/DropNet/Client/Files.Sync.cs index e74d3c4..2f74e51 100644 --- a/DropNet/Client/Files.Sync.cs +++ b/DropNet/Client/Files.Sync.cs @@ -354,7 +354,7 @@ public DeltaPage GetDelta(string cursor) /// /// /// - private DeltaEntry StringListToDeltaEntry(List stringList) + DeltaEntry StringListToDeltaEntry(List stringList) { var deltaEntry = new DeltaEntry { @@ -372,16 +372,7 @@ private DeltaEntry StringListToDeltaEntry(List stringList) return deltaEntry; } - /// - /// Private class used to deal with the DropBox API returning two different types in a given list - /// - private class DeltaPageInternal - { - public string Cursor { get; set; } - public bool Has_More { get; set; } - public bool Reset { get; set; } - public List> Entries { get; set; } - } + } } #endif \ No newline at end of file diff --git a/DropNet/DropNet.csproj b/DropNet/DropNet.csproj index 9d72d09..415796e 100644 --- a/DropNet/DropNet.csproj +++ b/DropNet/DropNet.csproj @@ -80,6 +80,7 @@ + diff --git a/DropNet/Models/DeltaPageInternal.cs b/DropNet/Models/DeltaPageInternal.cs new file mode 100644 index 0000000..f39b685 --- /dev/null +++ b/DropNet/Models/DeltaPageInternal.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; + +namespace DropNet.Models +{ + /// + /// Private class used to deal with the DropBox API returning two different types in a given list + /// + internal class DeltaPageInternal + { + public string Cursor { get; set; } + public bool Has_More { get; set; } + public bool Reset { get; set; } + public List> Entries { get; set; } + } +} \ No newline at end of file diff --git a/DropNet/Models/MetaData.cs b/DropNet/Models/MetaData.cs index b237dd5..4396f68 100644 --- a/DropNet/Models/MetaData.cs +++ b/DropNet/Models/MetaData.cs @@ -1,21 +1,46 @@ using System; using System.Collections.Generic; +using System.Runtime.Serialization; namespace DropNet.Models { + [DataContract] public class MetaData { + [DataMember] public string Hash { get; set; } + + [DataMember] public bool Thumb_Exists { get; set; } + + [DataMember] public long Bytes { get; set; } + + [DataMember] public string Modified { get; set; } + + [DataMember] public string Path { get; set; } + + [DataMember] public bool Is_Dir { get; set; } + + [DataMember] public bool Is_Deleted { get; set; } + + [DataMember] public string Size { get; set; } + + [DataMember] public string Root { get; set; } + + [DataMember] public string Icon { get; set; } + + [DataMember] public int Revision { get; set; } + + [DataMember] public List Contents { get; set; } public DateTime ModifiedDate