Skip to content
This repository was archived by the owner on Nov 29, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions DropNet.Tests/FileAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -36,7 +42,7 @@ public void Can_Get_List_Of_Metadata_For_Search_String()
{
Assert.IsNotNull(s);
Assert.AreEqual(1, s.Count);
},
},
Assert.IsNull);
}

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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()));
}
}
}
7 changes: 7 additions & 0 deletions DropNet.WindowsPhone/DropNet.WindowsPhone.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<SilverlightApplication>false</SilverlightApplication>
<ValidateXaml>true</ValidateXaml>
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
<SccProjectName>%24/WinBox/DropNet/DropNet.WindowsPhone</SccProjectName>
<SccLocalPath>.</SccLocalPath>
<SccAuxPath>https://prashantvc.tfspreview.com/defaultcollection</SccAuxPath>
<SccProvider>{4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -83,6 +87,9 @@
<Compile Include="..\DropNet\Models\DeltaPage.cs">
<Link>Models\DeltaPage.cs</Link>
</Compile>
<Compile Include="..\DropNet\Models\DeltaPageInternal.cs">
<Link>Models\DeltaPageInternal.cs</Link>
</Compile>
<Compile Include="..\dropnet\Models\MetaData.cs">
<Link>Models\MetaData.cs</Link>
</Compile>
Expand Down
93 changes: 66 additions & 27 deletions DropNet/Client/Files.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using DropNet.Models;
using RestSharp;
using System;
using DropNet.Authenticators;
using DropNet.Exceptions;
using RestSharp.Deserializers;

namespace DropNet
{
Expand All @@ -28,6 +28,22 @@ public void GetMetaDataAsync(string path, Action<MetaData> success, Action<Dropb
ExecuteAsync(ApiType.Base, request, success, failure);
}

/// <summary>
/// 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.
/// </summary>
/// <param name="path">The path</param>
/// <param name="success">Success callback </param>
/// <param name="failure">Failure callback </param>
public void GetMediaAsync(string path, Action<ShareResponse> success, Action<DropboxException> failure)
{
if (!path.StartsWith("/")) path = "/" + path;

var request = _requestHelper.CreateMediaRequest(path, Root);

ExecuteAsync(ApiType.Base, request, success, failure);
}

/// <summary>
/// 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
Expand Down Expand Up @@ -80,7 +96,7 @@ public void SearchAsync(string searchString, string path, Action<List<MetaData>>
/// <param name="path">The path of the file to download</param>
/// /// <param name="success">Success callback </param>
/// <param name="failure">Failure callback </param>

public void GetFileAsync(string path, Action<IRestResponse> success, Action<DropboxException> failure)
{
if (!path.StartsWith("/")) path = "/" + path;
Expand Down Expand Up @@ -221,46 +237,69 @@ public void CreateFolderAsync(string path, Action<MetaData> success, Action<Drop
/// <param name="failure">Failure callback </param>
public void GetShareAsync(string path, Action<ShareResponse> success, Action<DropboxException> failure)
{
if (!path.StartsWith("/")) path = "/" + path;
if (!path.StartsWith("/"))
{
path = "/" + path;
}

var request = _requestHelper.CreateShareRequest(path, Root);

ExecuteAsync(ApiType.Base, request, success, failure);
}

/// <summary>
/// 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
/// </summary>
/// <param name="path">The path</param>
/// <param name="success">Success callback </param>
/// <param name="failure">Failure callback </param>
public void GetMediaAsync(string path, Action<ShareResponse> success, Action<DropboxException> failure)
/// <param name="cursor">Cursor returned by prvious call</param>
/// <param name="success">Success Callback</param>
/// <param name="failure">Failure Callback</param>
public void GetDeltaAsync(string cursor, Action<DeltaPage> success, Action<DropboxException> failure)
{
if (!path.StartsWith("/")) path = "/" + path;

var request = _requestHelper.CreateMediaRequest(path, Root);
var request = _requestHelper.CreateDeltaRequest(cursor);
ExecuteAsync<DeltaPageInternal>(ApiType.Base, request,
deltaResponse =>
{
var deltaPage = new DeltaPage
{
Cursor = deltaResponse.Cursor,
Has_More = deltaResponse.Has_More,
Reset = deltaResponse.Reset,
Entries = new List<DeltaEntry>()
};

foreach (var stringList in deltaResponse.Entries)
{
deltaPage.Entries.Add(StringListToDelta(stringList));
}

success (deltaPage);
},

ExecuteAsync(ApiType.Base, request, success, failure);
failure);
}

/// <summary>
/// The beta delta function, gets updates for a given folder
/// Helper function to convert a stringlist to a DeltaEntry object
/// </summary>
/// <param name="IKnowThisIsBetaOnly"></param>
/// <param name="path"></param>
/// <param name="success"></param>
/// <param name="failure"></param>
public void GetDeltaAsync(bool IKnowThisIsBetaOnly, string path, Action<DeltaPage> success, Action<DropboxException> failure)
/// <param name="stringList"></param>
/// <returns></returns>
DeltaEntry StringListToDelta(List<string> 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<MetaData>(fakeresponse);
}
return deltaEntry;
}

ExecuteAsync<DeltaPage>(ApiType.Base, request, success, failure);
}

/// <summary>
/// Gets the thumbnail of an image given its MetaData
Expand Down
13 changes: 2 additions & 11 deletions DropNet/Client/Files.Sync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public DeltaPage GetDelta(string cursor)
/// </summary>
/// <param name="stringList"></param>
/// <returns></returns>
private DeltaEntry StringListToDeltaEntry(List<string> stringList)
DeltaEntry StringListToDeltaEntry(List<string> stringList)
{
var deltaEntry = new DeltaEntry
{
Expand All @@ -372,16 +372,7 @@ private DeltaEntry StringListToDeltaEntry(List<string> stringList)
return deltaEntry;
}

/// <summary>
/// Private class used to deal with the DropBox API returning two different types in a given list
/// </summary>
private class DeltaPageInternal
{
public string Cursor { get; set; }
public bool Has_More { get; set; }
public bool Reset { get; set; }
public List<List<string>> Entries { get; set; }
}

}
}
#endif
1 change: 1 addition & 0 deletions DropNet/DropNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<Compile Include="Helpers\RequestHelper.cs" />
<Compile Include="Models\AccountCreationResult.cs" />
<Compile Include="Models\AccountInfo.cs" />
<Compile Include="Models\DeltaPageInternal.cs" />
<Compile Include="Models\DeltaPage.cs" />
<Compile Include="Models\MetaData.cs" />
<Compile Include="Models\SharesResponse.cs" />
Expand Down
15 changes: 15 additions & 0 deletions DropNet/Models/DeltaPageInternal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;

namespace DropNet.Models
{
/// <summary>
/// Private class used to deal with the DropBox API returning two different types in a given list
/// </summary>
internal class DeltaPageInternal
{
public string Cursor { get; set; }
public bool Has_More { get; set; }
public bool Reset { get; set; }
public List<List<string>> Entries { get; set; }
}
}
25 changes: 25 additions & 0 deletions DropNet/Models/MetaData.cs
Original file line number Diff line number Diff line change
@@ -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<MetaData> Contents { get; set; }

public DateTime ModifiedDate
Expand Down