コード例 #1
0
        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);
        }
コード例 #2
0
        public override ICloudFileSystemEntry CreateResource(IStorageProviderSession session, string name, ICloudDirectoryEntry parent)
        {
            String path = DropBoxResourceIDHelpers.GetResourcePath(parent, name);

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

            int code;
            var res = DropBoxRequestParser.RequestResourceByUrl(GetUrlString(DropBoxCreateFolder, session.ServiceConfiguration), parameters, this, session, out code);

            if (res.Length != 0)
            {
                var entry = DropBoxRequestParser.CreateObjectsFromJsonString(res, this, session);
                if (parent != null && parent is BaseDirectoryEntry && parent.Id.Equals(entry.ParentID))
                {
                    (parent as BaseDirectoryEntry).AddChild(entry);
                }
                return(entry);
            }

            return(null);
        }
コード例 #3
0
        public override string GetResourceUrl(IStorageProviderSession session, ICloudFileSystemEntry fileSystemEntry, String additionalPath)
        {
            var path     = DropBoxResourceIDHelpers.GetResourcePath(fileSystemEntry, additionalPath);
            var basicUrl = session.ServiceConfiguration.ServiceLocator.ToString().TrimEnd('/');

            return(!String.IsNullOrEmpty(path) ? basicUrl + "/" + path : basicUrl);
        }
コード例 #4
0
        public override bool DeleteResource(IStorageProviderSession session, ICloudFileSystemEntry entry)
        {
            var resourcePath = DropBoxResourceIDHelpers.GetResourcePath(entry);

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

            try
            {
                int code;
                DropBoxRequestParser.RequestResourceByUrl(GetUrlString(DropBoxDeleteItem, session.ServiceConfiguration), parameters, this, session, out code);

                var parent = entry.Parent as BaseDirectoryEntry;
                if (parent != null)
                {
                    parent.RemoveChildById(entry.Id);
                }
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
コード例 #5
0
        private static Boolean BuildFileEntry(BaseFileEntry fileEntry, JsonHelper jh)
        {
            /*
             *  "revision": 29251,
             *  "thumb_exists": false,
             *  "bytes": 37941660,
             *  "modified": "Tue, 01 Jun 2010 14:45:09 +0000",
             *  "path": "/Public/2010_06_01 15_53_48_336.nvl",
             *  "is_dir": false,
             *  "icon": "page_white",
             *  "mime_type": "application/octet-stream",
             *  "size": "36.2MB"
             * */

            // set the size
            fileEntry.Length = Convert.ToInt64(jh.GetProperty("bytes"));

            // set the modified time
            fileEntry.Modified = jh.GetDateTimeProperty("modified");

            // build the displayname
            var DropBoxPath = jh.GetProperty("path");
            var arr         = DropBoxPath.Split('/');

            fileEntry.Name = arr.Length > 0 ? arr[arr.Length - 1] : DropBoxPath;

            if (DropBoxPath.Equals("/"))
            {
                fileEntry.Id       = "/";
                fileEntry.ParentID = null;
            }
            else
            {
                fileEntry.Id       = DropBoxPath.Trim('/');
                fileEntry.ParentID = DropBoxResourceIDHelpers.GetParentID(DropBoxPath);
            }


            // set the hash property if possible
            var hashValue = jh.GetProperty("hash");

            if (hashValue.Length > 0)
            {
                fileEntry.SetPropertyValue("hash", hashValue);
            }

            // set the path property
            fileEntry.SetPropertyValue("path", DropBoxPath.Equals("/") ? "" : DropBoxPath);

            // set the revision value if possible
            var revValue = jh.GetProperty("rev");

            if (revValue.Length > 0)
            {
                fileEntry.SetPropertyValue("rev", revValue);
            }

            // go ahead
            return(true);
        }
コード例 #6
0
        public override string GetResourceUrl(IStorageProviderSession session, ICloudFileSystemEntry fileSystemEntry, String additionalPath)
        {
            var dbSession = session as DropBoxStorageProviderSession;

            String path = DropBoxResourceIDHelpers.GetResourcePath(fileSystemEntry, additionalPath);
            String url  = GetResourceUrlInternal(session, path);

            // generate the oauth url
            var svc = new OAuthService();

            return(svc.GetProtectedResourceUrl(url, dbSession.Context, dbSession.SessionToken as DropBoxToken, null, WebRequestMethodsEx.Http.Get));
        }
コード例 #7
0
        public static string GetCommitUploadSessionUrl(IStorageProviderSession session, IResumableUploadSession uploadSession)
        {
            var rUploadSession = uploadSession as ResumableUploadSession;

            if (rUploadSession == null)
            {
                throw new ArgumentNullException("uploadSession");
            }

            return(GetUrlString(DropBoxCommitChunkedUpload, session.ServiceConfiguration)
                   + "/" + GetRootToken((DropBoxStorageProviderSession)session)
                   + "/" + HttpUtilityEx.UrlEncodeUTF8(DropBoxResourceIDHelpers.GetResourcePath(null, rUploadSession.FileName, rUploadSession.ParentId)));
        }
コード例 #8
0
        public override bool CopyResource(IStorageProviderSession session, ICloudFileSystemEntry fsentry, ICloudDirectoryEntry newParent)
        {
            var path = DropBoxResourceIDHelpers.GetResourcePath(newParent, fsentry.Name);

            // Move
            if (CopyItem(session as DropBoxStorageProviderSession, fsentry as BaseFileEntry, path))
            {
                // set the new parent
                if (newParent != null && newParent is BaseDirectoryEntry)
                {
                    (newParent as BaseDirectoryEntry).AddChild(fsentry as BaseFileEntry);
                }

                return(true);
            }

            return(false);
        }
コード例 #9
0
        public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, string name, ICloudDirectoryEntry parent)
        {
            var path      = DropBoxResourceIDHelpers.GetResourcePath(parent, name);
            var uriString = GetResourceUrlInternal(session, path);

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

            if (res.Length == 0)
            {
                if (code != (int)HttpStatusCode.OK)
                {
                    throw new SharpBoxException(
                              code == (int)HttpStatusCode.NotFound
                            ? SharpBoxErrorCodes.ErrorFileNotFound
                            : SharpBoxErrorCodes.ErrorCouldNotRetrieveDirectoryList,
                              new HttpException(Convert.ToInt32(code), "HTTP Error"));
                }
                throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotRetrieveDirectoryList);
            }

            // build the entry and subchilds
            var entry = DropBoxRequestParser.CreateObjectsFromJsonString(res, this, session);

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

            if (!string.IsNullOrEmpty(hash))
            {
                DropBoxRequestParser.Addhash(uriString, hash, res, session);
            }
            // check if it was a deleted file
            if (entry.IsDeleted)
            {
                return(null);
            }

            // set the parent
            if (parent is BaseDirectoryEntry && parent.Id.Equals(entry.ParentID))
            {
                (parent as BaseDirectoryEntry).AddChild(entry);
            }

            return(entry);
        }
コード例 #10
0
        public static String GetDownloadFileUrlInternal(IStorageProviderSession session, ICloudFileSystemEntry entry)
        {
            // cast varibales
            var dropBoxSession = session as DropBoxStorageProviderSession;

            // gather information
            var rootToken   = GetRootToken(dropBoxSession);
            var dropboxPath = DropBoxResourceIDHelpers.GetResourcePath(entry);

            // add all information to url;
            var url = GetUrlString(DropBoxUploadDownloadFile, session.ServiceConfiguration) + "/" + rootToken;

            if (dropboxPath.Length > 0 && dropboxPath[0] != '/')
            {
                url += "/";
            }

            url += HttpUtilityEx.UrlEncodeUTF8(dropboxPath);

            return(url);
        }
コード例 #11
0
        public override bool MoveResource(IStorageProviderSession session, ICloudFileSystemEntry fsentry, ICloudDirectoryEntry newParent)
        {
            var oldPath = DropBoxResourceIDHelpers.GetResourcePath(fsentry);
            var path    = DropBoxResourceIDHelpers.GetResourcePath(newParent, fsentry.Name);

            if (MoveOrRenameItem(session as DropBoxStorageProviderSession, fsentry as BaseFileEntry, path))
            {
                // set the new parent
                if (fsentry.Parent != null && fsentry.Parent is BaseDirectoryEntry)
                {
                    (fsentry.Parent as BaseDirectoryEntry).RemoveChildById(oldPath);
                }
                if (newParent != null && newParent is BaseDirectoryEntry)
                {
                    (newParent as BaseDirectoryEntry).AddChild(fsentry as BaseFileEntry);
                }

                return(true);
            }

            return(false);
        }
コード例 #12
0
        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);
            }
        }
コード例 #13
0
 public static String GetCommitUploadSessionUrl(IStorageProviderSession session, IResumableUploadSession uploadSession)
 {
     return(GetUrlString(DropBoxCommitChunkedUpload, session.ServiceConfiguration)
            + "/" + GetRootToken((DropBoxStorageProviderSession)session)
            + "/" + HttpUtilityEx.UrlEncodeUTF8(DropBoxResourceIDHelpers.GetResourcePath(uploadSession.File.Parent, uploadSession.File.Name)));
 }
コード例 #14
0
        public override bool RenameResource(IStorageProviderSession session, ICloudFileSystemEntry fsentry, string newName)
        {
            var path = DropBoxResourceIDHelpers.GetResourcePath(fsentry).ReplaceLast(fsentry.Name, newName);

            return(MoveOrRenameItem(session as DropBoxStorageProviderSession, fsentry as BaseFileEntry, path));
        }