/// <summary>
        /// Creates folder using path specified
        /// </summary>
        /// <param name="dropboxFolderPath">Path of folder to create</param>
        /// <param name="onResult">Result callback that contains metadata of the created folder</param>
        public void CreateFolder(string dropboxFolderPath, Action <DropboxRequestResult <DBXFolder> > onResult)
        {
            var path = DropboxSyncUtils.NormalizePath(dropboxFolderPath);

            var prms = new DropboxCreateFolderRequestParams();

            prms.path = path;

            MakeDropboxRequest(CREATE_FOLDER_ENDPOINT, prms, (jsonStr) => {
                DBXFolder folderMetadata = null;

                try {
                    var root       = JSON.FromJson <Dictionary <string, object> >(jsonStr);
                    folderMetadata = DBXFolder.FromDropboxDictionary(root["metadata"] as Dictionary <string, object>);
                }catch (Exception ex) {
                    _mainThreadQueueRunner.QueueOnMainThread(() => {
                        onResult(DropboxRequestResult <DBXFolder> .Error(new DBXError(ex.Message, DBXErrorType.ParsingError)));
                    });
                    return;
                }

                _mainThreadQueueRunner.QueueOnMainThread(() => {
                    onResult(new DropboxRequestResult <DBXFolder>(folderMetadata));
                });
            }, onProgress: (progress) => {}, onWebError: (error) => {
                if (error.ErrorDescription.Contains("path/conflict/folder"))
                {
                    error.ErrorType = DBXErrorType.RemotePathAlreadyExists;
                }
                _mainThreadQueueRunner.QueueOnMainThread(() => {
                    onResult(DropboxRequestResult <DBXFolder> .Error(error));
                });
            });
        }
Пример #2
0
        /// <summary>
        /// Unsubscribe specific callback from changes on specified Dropbox path
        /// </summary>
        /// <param name="dropboxPath">Path from which to unsubscribe</param>
        /// <param name="onChange">Callback reference</param>
        public void UnsubscribeFromChangesOnPath(string dropboxPath, Action <List <DBXFileChange> > onChange)
        {
            dropboxPath = DropboxSyncUtils.NormalizePath(dropboxPath);

            var item = OnChangeCallbacksDict.Where(p => p.Key.path == dropboxPath).Select(p => p.Key).FirstOrDefault();

            if (item != null)
            {
                OnChangeCallbacksDict[item].Remove(onChange);
            }
        }
Пример #3
0
        /// <summary>
        /// Unsubscribes all subscribers from changes on specified Dropbox path
        /// </summary>
        /// <param name="dropboxPath">Path from which to unsubscribe</param>
        public void UnsubscribeAllFromChangesOnPath(string dropboxPath)
        {
            dropboxPath = DropboxSyncUtils.NormalizePath(dropboxPath);

            var removeKeys = OnChangeCallbacksDict.Where(p => p.Key.path == dropboxPath).Select(p => p.Key).ToList();

            foreach (var k in removeKeys)
            {
                OnChangeCallbacksDict.Remove(k);
            }
        }
        /// <summary>
        /// Retrieves structure of dropbox folders and files inside specified folder.
        /// </summary>
        /// <param name="dropboxFolderPath">Dropbox folder path</param>
        /// <param name="onResult">Callback function that receives result containing DBXFolder with all child nodes inside.</param>
        /// <param name="onProgress">Callback fnction that receives float from 0 to 1 intdicating the progress.</param>
        public void GetFolderStructure(string dropboxFolderPath, Action <DropboxRequestResult <DBXFolder> > onResult,
                                       Action <float> onProgress = null)
        {
            var path = DropboxSyncUtils.NormalizePath(dropboxFolderPath);

            _GetFolderItemsFlat(path, onResult: (items) => {
                DBXFolder rootFolder = null;

                // get root folder
                if (path == "/")
                {
                    rootFolder = new DBXFolder {
                        id = "", path = "/", name = "", items = new List <DBXItem>()
                    };
                }
                else
                {
                    rootFolder = items.Where(x => x.path == path).First() as DBXFolder;
                }
                // squash flat results
                rootFolder = BuildStructureFromFlat(rootFolder, items);

                _mainThreadQueueRunner.QueueOnMainThread(() => {
                    onResult(new DropboxRequestResult <DBXFolder>(rootFolder));
                });
            },
                                onProgress: (progress) => {
                if (onProgress != null)
                {
                    _mainThreadQueueRunner.QueueOnMainThread(() => {
                        onProgress(progress);
                    });
                }
            },
                                onError: (errorStr) => {
                _mainThreadQueueRunner.QueueOnMainThread(() => {
                    onResult(DropboxRequestResult <DBXFolder> .Error(errorStr));
                });
            }, recursive: true);
        }
Пример #5
0
 public DBXFolder(string p)
 {
     type = DBXItemType.Folder;
     path = DropboxSyncUtils.NormalizePath(p);
 }
Пример #6
0
 public DBXFile(string p)
 {
     type = DBXItemType.File;
     path = DropboxSyncUtils.NormalizePath(p);
 }
        void _GetFolderItemsFlat(string folderPath, Action <List <DBXItem> > onResult, Action <float> onProgress,
                                 Action <DBXError> onError, bool recursive = false, string requestCursor = null, List <DBXItem> currentResults = null)
        {
            folderPath = DropboxSyncUtils.NormalizePath(folderPath);

            if (folderPath == "/")
            {
                folderPath = "";                 // dropbox error fix
            }

            string url;
            DropboxRequestParams prms;

            if (requestCursor == null)
            {
                // first request
                currentResults = new List <DBXItem>();
                url            = LIST_FOLDER_ENDPOINT;
                prms           = new DropboxListFolderRequestParams {
                    path = folderPath, recursive = recursive
                };
            }
            else
            {
                // have cursor to continue list
                url  = LIST_FOLDER_CONTINUE_ENDPOINT;
                prms = new DropboxContinueWithCursorRequestParams(requestCursor);
            }

            MakeDropboxRequest(url, prms, onResponse: (jsonStr) => {
                //Log("Got reponse: "+jsonStr);

                Dictionary <string, object> root = null;
                try {
                    root = JSON.FromJson <Dictionary <string, object> >(jsonStr);
                }catch (Exception ex) {
                    onError(new DBXError(ex.Message, DBXErrorType.ParsingError));
                    return;
                }

                var entries = root["entries"] as List <object>;
                foreach (Dictionary <string, object> entry in entries)
                {
                    if (entry[".tag"].ToString() == "file")
                    {
                        currentResults.Add(DBXFile.FromDropboxDictionary(entry));
                    }
                    else if (entry[".tag"].ToString() == "folder")
                    {
                        currentResults.Add(DBXFolder.FromDropboxDictionary(entry));
                    }
                    else
                    {
                        onError(new DBXError("Unknown entry tag " + entry[".tag".ToString()], DBXErrorType.Unknown));
                        return;
                    }
                }

                if ((bool)root["has_more"])
                {
                    // recursion
                    _GetFolderItemsFlat(folderPath, onResult, onProgress, onError, recursive: recursive,
                                        requestCursor: root["cursor"].ToString(),
                                        currentResults: currentResults);
                }
                else
                {
                    // done
                    onResult(currentResults);
                }
            }, onProgress: onProgress,
                               onWebError: (webErrorStr) => {
                //LogError("Got web err: "+webErrorStr);
                onError(webErrorStr);
            });
        }