public Stream GetFileStream(File file, long offset)
        {
            var dropboxFilePath = MakeDropboxPath(file.ID);

            DropboxProviderInfo.CacheReset(dropboxFilePath, true);

            var dropboxFile = GetDropboxFile(file.ID);

            if (dropboxFile == null)
            {
                throw new ArgumentNullException("file", Web.Files.Resources.FilesCommonResource.ErrorMassage_FileNotFound);
            }
            if (dropboxFile is ErrorFile)
            {
                throw new Exception(((ErrorFile)dropboxFile).Error);
            }

            var fileStream = DropboxProviderInfo.Storage.DownloadStream(MakeDropboxPath(dropboxFile), (int)offset);

            return(fileStream);
        }
Beispiel #2
0
        public void DeleteFile(object fileId)
        {
            var dropboxFile = GetDropboxFile(fileId);

            if (dropboxFile == null)
            {
                return;
            }
            var id = MakeId(dropboxFile);

            using (var db = GetDb())
                using (var tx = db.BeginTransaction())
                {
                    var hashIDs = db.ExecuteList(Query("files_thirdparty_id_mapping")
                                                 .Select("hash_id")
                                                 .Where(Exp.Like("id", id, SqlLike.StartWith)))
                                  .ConvertAll(x => x[0]);

                    db.ExecuteNonQuery(Delete("files_tag_link").Where(Exp.In("entry_id", hashIDs)));
                    db.ExecuteNonQuery(Delete("files_tag").Where(Exp.EqColumns("0", Query("files_tag_link l").SelectCount().Where(Exp.EqColumns("tag_id", "id")))));
                    db.ExecuteNonQuery(Delete("files_security").Where(Exp.In("entry_id", hashIDs)));
                    db.ExecuteNonQuery(Delete("files_thirdparty_id_mapping").Where(Exp.In("hash_id", hashIDs)));

                    tx.Commit();
                }

            if (!(dropboxFile is ErrorFile))
            {
                DropboxProviderInfo.Storage.DeleteItem(dropboxFile);
            }

            DropboxProviderInfo.CacheReset(MakeDropboxPath(dropboxFile), true);
            var parentFolderPath = GetParentFolderPath(dropboxFile);

            if (parentFolderPath != null)
            {
                DropboxProviderInfo.CacheReset(parentFolderPath);
            }
        }
Beispiel #3
0
        public File CopyFile(object fileId, object toFolderId)
        {
            var dropboxFile = GetDropboxFile(fileId);

            if (dropboxFile is ErrorFile)
            {
                throw new Exception(((ErrorFile)dropboxFile).Error);
            }

            var toDropboxFolder = GetDropboxFolder(toFolderId);

            if (toDropboxFolder is ErrorFolder)
            {
                throw new Exception(((ErrorFolder)toDropboxFolder).Error);
            }

            var newDropboxFile = DropboxProviderInfo.Storage.CopyFile(MakeDropboxPath(dropboxFile), MakeDropboxPath(toDropboxFolder), dropboxFile.Name);

            DropboxProviderInfo.CacheReset(newDropboxFile);
            DropboxProviderInfo.CacheReset(MakeDropboxPath(toDropboxFolder));

            return(ToFile(newDropboxFile));
        }
Beispiel #4
0
        public Folder CopyFolder(object folderId, object toFolderId)
        {
            var dropboxFolder = GetDropboxFolder(folderId);

            if (dropboxFolder is ErrorFolder)
            {
                throw new Exception(((ErrorFolder)dropboxFolder).Error);
            }

            var toDropboxFolder = GetDropboxFolder(toFolderId);

            if (toDropboxFolder is ErrorFolder)
            {
                throw new Exception(((ErrorFolder)toDropboxFolder).Error);
            }

            var newDropboxFolder = DropboxProviderInfo.Storage.CopyFolder(MakeDropboxPath(dropboxFolder), MakeDropboxPath(toDropboxFolder), dropboxFolder.Name);

            DropboxProviderInfo.CacheReset(newDropboxFolder);
            DropboxProviderInfo.CacheReset(MakeDropboxPath(newDropboxFolder), false);

            return(ToFolder(newDropboxFolder));
        }