Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
[DropboxSync] Better Names, updated sample
Browse files Browse the repository at this point in the history
  • Loading branch information
dalexsoto committed Apr 4, 2013
1 parent aefa150 commit 078c734
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 101 deletions.
4 changes: 2 additions & 2 deletions binding/ApiDefinition.cs
Expand Up @@ -162,10 +162,10 @@ interface DBFilesystem {
DBFilesystem SharedFilesystem { get; set; }

[Export ("listFolder:error:")]
DBFileInfo [] ListFolder (DBPath path, out DBError error);
DBFileInfo [] GetFolder (DBPath path, out DBError error);

[Export ("fileInfoForPath:error:")]
DBFileInfo FileInfoForPath (DBPath path, out DBError error);
DBFileInfo GetFiles (DBPath path, out DBError error);

[Export ("openFile:error:")]
DBFile OpenFile (DBPath path, out DBError error);
Expand Down
83 changes: 83 additions & 0 deletions binding/DBException.cs
@@ -0,0 +1,83 @@
using System;

namespace DropBoxSync.iOS
{
public class DBException : Exception
{
public DBError NativeError { get; private set; }

public DBException (DBError err)
{
NativeError = err;
}

public override string Message {
get {
switch (NativeError.Code) {
case DBErrorCode.CoreSystem:
return "System error";

case DBErrorCode.Params:
return "An error due to data passed into the SDK";

case DBErrorCode.ParamsInvalid:
return "A parameter is invalid, maybe was null?";

case DBErrorCode.ParamsNotFound:
return "A file corresponding to a provided path was not found";

case DBErrorCode.ParamsExists:
return "File already exists and was opened exclusively";

case DBErrorCode.ParamsAlreadyOpen:
return "File was already open";

case DBErrorCode.ParamsParent:
return "Parent does not exist or is not a folder";

case DBErrorCode.ParamsNotEmpty:
return "Directory is not empty";

case DBErrorCode.ParamsNotCached:
return "File was not yet in cache";

case DBErrorCode.System:
return "An error in the Dropbox library occurred";

case DBErrorCode.SystemDiskSpace:
return "An error happened due to insufficient disk space";

case DBErrorCode.Network:
return "An error occurred making a network request";

case DBErrorCode.NetworkTimeout:
return "A connection timed out";

case DBErrorCode.NetworkNoConnection:
return "No network connection available";

case DBErrorCode.NetworkSSL:
return "Unable to verify the server's SSL certificate. Often caused by an out-of-date clock";

case DBErrorCode.NetworkServer:
return "Unexpected server error";

case DBErrorCode.Auth:
return "An authentication related problem occurred";

case DBErrorCode.AuthUnlinked:
return "The user is no longer linked";

case DBErrorCode.AuthInvalidApp:
return "An invalid app key or secret was provided";

case DBErrorCode.Unknown:
default:
return "Unknown Error";

}
}
}
}
}

1 change: 1 addition & 0 deletions binding/DropBoxSync.iOS.csproj 100755 → 100644
Expand Up @@ -50,6 +50,7 @@
<DependentUpon>Dropbox.a</DependentUpon>
</Compile>
<Compile Include="Extras.cs" />
<Compile Include="DBException.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down
86 changes: 4 additions & 82 deletions binding/Extras.cs
Expand Up @@ -6,22 +6,22 @@ namespace DropBoxSync.iOS
{
public partial class DBFilesystem : NSObject
{
public Task<DBFileInfo []> ListFolderAsync (DBPath path)
public Task<DBFileInfo []> GetFolderAsync (DBPath path)
{
return Task.Factory.StartNew (p => {
DBError err;
var results = ListFolder ((DBPath)p, out err);
var results = GetFolder ((DBPath)p, out err);
if (err != null)
throw new DBException (err);
return results;
}, path);
}

public Task<DBFileInfo> FileInfoForPathAsync (DBPath path)
public Task<DBFileInfo> GetFilesAsync (DBPath path)
{
return Task.Factory.StartNew (p => {
DBError err;
var results = FileInfoForPath ((DBPath)p, out err);
var results = GetFiles ((DBPath)p, out err);
if (err != null)
throw new DBException (err);
return results;
Expand Down Expand Up @@ -163,83 +163,5 @@ public Task<bool> UpdateAsync ()
});
}
}

public class DBException : Exception
{
public DBError NativeError { get; private set; }

public DBException (DBError err)
{
NativeError = err;
}

public override string Message {
get {
switch (NativeError.Code) {
case DBErrorCode.CoreSystem:
return "System error";

case DBErrorCode.Params:
return "An error due to data passed into the SDK";

case DBErrorCode.ParamsInvalid:
return "A parameter is invalid, maybe was null?";

case DBErrorCode.ParamsNotFound:
return "A file corresponding to a provided path was not found";

case DBErrorCode.ParamsExists:
return "File already exists and was opened exclusively";

case DBErrorCode.ParamsAlreadyOpen:
return "File was already open";

case DBErrorCode.ParamsParent:
return "Parent does not exist or is not a folder";

case DBErrorCode.ParamsNotEmpty:
return "Directory is not empty";

case DBErrorCode.ParamsNotCached:
return "File was not yet in cache";

case DBErrorCode.System:
return "An error in the Dropbox library occurred";

case DBErrorCode.SystemDiskSpace:
return "An error happened due to insufficient disk space";

case DBErrorCode.Network:
return "An error occurred making a network request";

case DBErrorCode.NetworkTimeout:
return "A connection timed out";

case DBErrorCode.NetworkNoConnection:
return "No network connection available";

case DBErrorCode.NetworkSSL:
return "Unable to verify the server's SSL certificate. Often caused by an out-of-date clock";

case DBErrorCode.NetworkServer:
return "Unexpected server error";

case DBErrorCode.Auth:
return "An authentication related problem occurred";

case DBErrorCode.AuthUnlinked:
return "The user is no longer linked";

case DBErrorCode.AuthInvalidApp:
return "An invalid app key or secret was provided";

case DBErrorCode.Unknown:
default:
return "Unknown Error";

}
}
}
}
}

38 changes: 21 additions & 17 deletions samples/DropBoxSyncSampleMTD/DVCFiles.cs
Expand Up @@ -70,33 +70,37 @@ void HandleCreateSheetClicked (object sender, UIButtonEventArgs e)

public void CreateAt (string input)
{
DBError error;
if (!creatingFolder) {
string noteFilename = string.Format ("{0}.txt", input);
var newPath = path.ChildPath (noteFilename);
var file = DBFilesystem.SharedFilesystem.CreateFile (newPath, out error);

if (file == null)
new UIAlertView ("Unable to create note", "An error has occurred: " + error.Description, null, "Ok", null).Show ();
else {
var controller = new NoteController (file);
NavigationController.PushViewController (controller, true);
}
DBFilesystem.SharedFilesystem.CreateFileAsync (newPath).ContinueWith (t => {
InvokeOnMainThread (()=> {
if (t.Result == null)
new UIAlertView ("Unable to create note", "An error has occurred", null, "Ok", null).Show ();
else {
var controller = new NoteController (t.Result);
NavigationController.PushViewController (controller, true);
}
});
});
} else {
var newPath = path.ChildPath (input);
bool success = DBFilesystem.SharedFilesystem.CreateFolder (newPath, out error);
if (!success)
new UIAlertView ("Unable to create folder", "An error has occurred: " + error.Description, null, "Ok", null).Show ();
else {
var controller = new DVCFiles (newPath);
NavigationController.PushViewController (controller, true);
}
DBFilesystem.SharedFilesystem.CreateFolderAsync (newPath).ContinueWith (t => {
InvokeOnMainThread (() => {
if (!t.Result)
new UIAlertView ("Unable to create folder", "An error has occurred", null, "Ok", null).Show ();
else {
var controller = new DVCFiles (newPath);
NavigationController.PushViewController (controller, true);
}
});
});
}
}

void LoadFiles ()
{
DBFilesystem.SharedFilesystem.ListFolderAsync (path).ContinueWith (t => {
DBFilesystem.SharedFilesystem.GetFolderAsync (path).ContinueWith (t => {
if(t.Result != null)
{
InvokeOnMainThread (()=> {
Expand Down

0 comments on commit 078c734

Please sign in to comment.