private bool MoveOrRenameOrCopyItem(DropBoxStorageProviderSession session, BaseFileEntry orgEntry, String toPath, bool copy)
        {
            // build the path for resource
            var resourcePath = DropBoxResourceIDHelpers.GetResourcePath(orgEntry);

            // request the json object via oauth
            var parameters = new Dictionary <string, string>
            {
                { "from_path", resourcePath },
                { "root", GetRootToken(session) },
                { "to_path", toPath }
            };

            try
            {
                // move or rename the entry
                int code;
                var res = DropBoxRequestParser.RequestResourceByUrl(GetUrlString(copy ? DropBoxCopyItem : DropBoxMoveItem, session.ServiceConfiguration), parameters, this, session, out code);

                // update the entry
                DropBoxRequestParser.UpdateObjectFromJsonString(res, orgEntry, this, session);
            }
            catch (Exception)
            {
                return(false);
            }

            orgEntry.Id = toPath;
            return(true);
        }
Exemplo n.º 2
0
        public override void RefreshResource(IStorageProviderSession session, ICloudFileSystemEntry resource)
        {
            // build url
            String uriString = GetResourceUrlInternal(session, resource);

            // request the data from url
            int code;
            var res = DropBoxRequestParser.RequestResourceByUrl(uriString, this, session, out code);

            // check error
            if (res.Length == 0)
            {
                throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotRetrieveDirectoryList);
            }

            // build the entry and subchilds
            DropBoxRequestParser.UpdateObjectFromJsonString(res, resource as BaseFileEntry, this, session);
        }
        public override void RefreshResource(IStorageProviderSession session, ICloudFileSystemEntry resource)
        {
            var path = GetResourceUrlInternal(session, DropBoxResourceIDHelpers.GetResourcePath(resource));

            int code;
            var res = DropBoxRequestParser.RequestResourceByUrl(path, this, session, out code);

            if (res.Length == 0)
            {
                throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotRetrieveDirectoryList);
            }

            // build the entry and subchilds
            DropBoxRequestParser.UpdateObjectFromJsonString(res, resource as BaseFileEntry, this, session);

            var hash = resource.GetPropertyValue("hash");

            if (!string.IsNullOrEmpty(hash))
            {
                DropBoxRequestParser.Addhash(path, hash, res, session);
            }
        }
Exemplo n.º 4
0
        public override ICloudFileSystemEntry CreateResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent)
        {
            // get the parent
            BaseDirectoryEntry parentDir = parent as BaseDirectoryEntry;

            // build new folder object
            var newFolder = new BaseDirectoryEntry(Name, 0, DateTime.Now, this, session);

            parentDir.AddChild(newFolder);

            // build the path for resource
            String resourcePath = GenericHelper.GetResourcePath(newFolder);

            // build the json parameters
            var parameters = new Dictionary <string, string>
            {
                { "path", resourcePath },
                { "root", GetRootToken(session as DropBoxStorageProviderSession) }
            };

            // request the json object via oauth
            int code;
            var res = DropBoxRequestParser.RequestResourceByUrl(GetUrlString(DropBoxCreateFolder, session.ServiceConfiguration), parameters, this, session, out code);

            if (res.Length == 0)
            {
                parentDir.RemoveChild(newFolder);
                return(null);
            }
            else
            {
                // update the folder object
                DropBoxRequestParser.UpdateObjectFromJsonString(res, newFolder, this, session);
            }

            // go ahead
            return(newFolder);
        }