Esempio n. 1
0
        public object MoveFile(object fileId, object toFolderId)
        {
            var boxFile = GetBoxFile(fileId);

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

            var toBoxFolder = GetBoxFolder(toFolderId);

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

            var fromFolderId = GetParentFolderId(boxFile);

            var newTitle = GetAvailableTitle(boxFile.Name, toBoxFolder.Id, IsExist);

            boxFile = BoxProviderInfo.Storage.MoveFile(boxFile.Id, newTitle, toBoxFolder.Id);

            BoxProviderInfo.CacheReset(boxFile.Id, true);
            BoxProviderInfo.CacheReset(fromFolderId);
            BoxProviderInfo.CacheReset(toBoxFolder.Id);

            return(MakeId(boxFile.Id));
        }
Esempio n. 2
0
        public void DeleteFolder(object folderId)
        {
            var boxFolder = GetBoxFolder(folderId);
            var id        = MakeId(boxFolder);

            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 (!(boxFolder is ErrorFolder))
            {
                BoxProviderInfo.Storage.DeleteItem(boxFolder);
            }

            BoxProviderInfo.CacheReset(boxFolder.Id, true);
            var parentFolderId = GetParentFolderId(boxFolder);

            if (parentFolderId != null)
            {
                BoxProviderInfo.CacheReset(parentFolderId);
            }
        }
Esempio n. 3
0
        public object SaveFolder(Folder folder)
        {
            if (folder == null)
            {
                throw new ArgumentNullException("folder");
            }
            if (folder.ID != null)
            {
                return(RenameFolder(folder, folder.Title));
            }

            if (folder.ParentFolderID != null)
            {
                var boxFolderId = MakeBoxId(folder.ParentFolderID);

                folder.Title = GetAvailableTitle(folder.Title, boxFolderId, IsExist);

                var boxFolder = BoxProviderInfo.Storage.CreateFolder(folder.Title, boxFolderId);

                BoxProviderInfo.CacheReset(boxFolder);
                var parentFolderId = GetParentFolderId(boxFolder);
                if (parentFolderId != null)
                {
                    BoxProviderInfo.CacheReset(parentFolderId);
                }

                return(MakeId(boxFolder));
            }
            return(null);
        }
        public object MoveFolder(object folderId, object toFolderId)
        {
            var boxFolder = GetBoxFolder(folderId);

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

            var toBoxFolder = GetBoxFolder(toFolderId);

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

            var fromFolderId = GetParentFolderId(boxFolder);

            boxFolder = BoxProviderInfo.Storage.MoveFolder(boxFolder.Id, toBoxFolder.Id);

            BoxProviderInfo.CacheReset(boxFolder.Id, false);
            BoxProviderInfo.CacheReset(fromFolderId);
            BoxProviderInfo.CacheReset(toBoxFolder.Id);

            return(MakeId(boxFolder.Id));
        }
Esempio n. 5
0
        public object MoveFolder(object folderId, object toFolderId, CancellationToken?cancellationToken)
        {
            var boxFolder = GetBoxFolder(folderId);

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

            var toBoxFolder = GetBoxFolder(toFolderId);

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

            var fromFolderId = GetParentFolderId(boxFolder);

            var newTitle = GetAvailableTitle(boxFolder.Name, toBoxFolder.Id, IsExist);

            boxFolder = BoxProviderInfo.Storage.MoveFolder(boxFolder.Id, newTitle, toBoxFolder.Id);

            BoxProviderInfo.CacheReset(boxFolder.Id, false);
            BoxProviderInfo.CacheReset(fromFolderId);
            BoxProviderInfo.CacheReset(toBoxFolder.Id);

            return(MakeId(boxFolder.Id));
        }
Esempio n. 6
0
        public Folder CopyFolder(object folderId, object toFolderId, CancellationToken?cancellationToken)
        {
            var boxFolder = GetBoxFolder(folderId);

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

            var toBoxFolder = GetBoxFolder(toFolderId);

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

            var newTitle     = GetAvailableTitle(boxFolder.Name, toBoxFolder.Id, IsExist);
            var newBoxFolder = BoxProviderInfo.Storage.CopyFolder(boxFolder.Id, newTitle, toBoxFolder.Id);

            BoxProviderInfo.CacheReset(newBoxFolder);
            BoxProviderInfo.CacheReset(newBoxFolder.Id, false);
            BoxProviderInfo.CacheReset(toBoxFolder.Id);

            return(ToFolder(newBoxFolder));
        }
Esempio n. 7
0
        public File SaveFile(File file, Stream fileStream)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }
            if (fileStream == null)
            {
                throw new ArgumentNullException("fileStream");
            }

            BoxFile newBoxFile = null;

            if (file.ID != null)
            {
                newBoxFile = BoxProviderInfo.Storage.SaveStream(MakeBoxId(file.ID), fileStream, file.Title);
            }
            else if (file.FolderID != null)
            {
                var folderId = MakeBoxId(file.FolderID);
                file.Title = GetAvailableTitle(file.Title, folderId, IsExist);
                newBoxFile = BoxProviderInfo.Storage.CreateFile(fileStream, file.Title, folderId);
            }

            BoxProviderInfo.CacheReset(newBoxFile);
            var parentId = GetParentFolderId(newBoxFile);

            if (parentId != null)
            {
                BoxProviderInfo.CacheReset(parentId);
            }

            return(ToFile(newBoxFile));
        }
Esempio n. 8
0
        public object RenameFolder(Folder folder, string newTitle)
        {
            var boxFolder      = GetBoxFolder(folder.ID);
            var parentFolderId = GetParentFolderId(boxFolder);

            if (IsRoot(boxFolder))
            {
                //It's root folder
                BoxDaoSelector.RenameProvider(BoxProviderInfo, newTitle);
                //rename provider customer title
            }
            else
            {
                newTitle = GetAvailableTitle(newTitle, parentFolderId, IsExist);

                //rename folder
                boxFolder = BoxProviderInfo.Storage.RenameFolder(boxFolder.Id, newTitle);
            }

            BoxProviderInfo.CacheReset(boxFolder);
            if (parentFolderId != null)
            {
                BoxProviderInfo.CacheReset(parentFolderId);
            }

            return(MakeId(boxFolder.Id));
        }
Esempio n. 9
0
 public void RenameProvider(BoxProviderInfo boxProviderInfo, string newTitle)
 {
     using (var dbDao = new CachedProviderAccountDao(CoreContext.TenantManager.GetCurrentTenant().TenantId, FileConstant.DatabaseId))
     {
         dbDao.UpdateProviderInfo(boxProviderInfo.ID, newTitle, null, boxProviderInfo.RootFolderType);
         boxProviderInfo.UpdateTitle(newTitle); //This will update cached version too
     }
 }
Esempio n. 10
0
        public void InvalidateCache(object fileId)
        {
            var boxFileId = MakeBoxId(fileId);

            BoxProviderInfo.CacheReset(boxFileId, true);

            var boxFile    = GetBoxFile(fileId);
            var parentPath = GetParentFolderId(boxFile);

            if (parentPath != null)
            {
                BoxProviderInfo.CacheReset(parentPath);
            }
        }
Esempio n. 11
0
        protected BoxFile GetBoxFile(object fileId)
        {
            var boxFileId = MakeBoxId(fileId);

            try
            {
                var file = BoxProviderInfo.GetBoxFile(boxFileId);
                return(file);
            }
            catch (Exception ex)
            {
                return(new ErrorFile(ex, boxFileId));
            }
        }
Esempio n. 12
0
        protected BoxFolder GetBoxFolder(object folderId)
        {
            var boxFolderId = MakeBoxId(folderId);

            try
            {
                var folder = BoxProviderInfo.GetBoxFolder(boxFolderId);
                return(folder);
            }
            catch (Exception ex)
            {
                return(new ErrorFolder(ex, boxFolderId));
            }
        }
Esempio n. 13
0
        public void DeleteFile(object fileId)
        {
            var boxFile = GetBoxFile(fileId);

            if (boxFile == null)
            {
                return;
            }
            var id = MakeId(boxFile.Id);

            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_security").Where(Exp.In("entry_id", hashIDs)));
                    db.ExecuteNonQuery(Delete("files_thirdparty_id_mapping").Where(Exp.In("hash_id", hashIDs)));

                    var tagsToRemove = db.ExecuteList(
                        Query("files_tag tbl_ft ")
                        .Select("tbl_ft.id")
                        .LeftOuterJoin("files_tag_link tbl_ftl", Exp.EqColumns("tbl_ft.tenant_id", "tbl_ftl.tenant_id") &
                                       Exp.EqColumns("tbl_ft.id", "tbl_ftl.tag_id"))
                        .Where("tbl_ftl.tag_id is null"))
                                       .ConvertAll(r => Convert.ToInt32(r[0]));

                    db.ExecuteNonQuery(Delete("files_tag").Where(Exp.In("id", tagsToRemove)));

                    tx.Commit();
                }

            if (!(boxFile is ErrorFile))
            {
                BoxProviderInfo.Storage.DeleteItem(boxFile);
            }

            BoxProviderInfo.CacheReset(boxFile.Id, true);
            var parentFolderId = GetParentFolderId(boxFile);

            if (parentFolderId != null)
            {
                BoxProviderInfo.CacheReset(parentFolderId);
            }
        }
Esempio n. 14
0
        protected List <BoxItem> GetBoxItems(object parentId, bool?folder = null)
        {
            var boxFolderId = MakeBoxId(parentId);
            var items       = BoxProviderInfo.GetBoxItems(boxFolderId);

            if (folder.HasValue)
            {
                if (folder.Value)
                {
                    return(items.Where(i => i is BoxFolder).ToList());
                }

                return(items.Where(i => i is BoxFile).ToList());
            }

            return(items);
        }
Esempio n. 15
0
        public object FileRename(File file, string newTitle)
        {
            var boxFile = GetBoxFile(file.ID);

            newTitle = GetAvailableTitle(newTitle, GetParentFolderId(boxFile), IsExist);

            boxFile = BoxProviderInfo.Storage.RenameFile(boxFile.Id, newTitle);

            BoxProviderInfo.CacheReset(boxFile);
            var parentId = GetParentFolderId(boxFile);

            if (parentId != null)
            {
                BoxProviderInfo.CacheReset(parentId);
            }

            return(MakeId(boxFile.Id));
        }
Esempio n. 16
0
        public File SaveFile(File file, Stream fileStream)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }
            if (fileStream == null)
            {
                throw new ArgumentNullException("fileStream");
            }

            BoxFile newBoxFile = null;

            if (file.ID != null)
            {
                var fileId = MakeBoxId(file.ID);
                newBoxFile = BoxProviderInfo.Storage.SaveStream(fileId, fileStream, file.Title);

                //https://github.com/box/box-windows-sdk-v2/issues/496
                if (!newBoxFile.Name.Equals(file.Title))
                {
                    var folderId = GetParentFolderId(GetBoxFile(fileId));
                    file.Title = GetAvailableTitle(file.Title, folderId, IsExist);
                    newBoxFile = BoxProviderInfo.Storage.RenameFile(fileId, file.Title);
                }
            }
            else if (file.FolderID != null)
            {
                var folderId = MakeBoxId(file.FolderID);
                file.Title = GetAvailableTitle(file.Title, folderId, IsExist);
                newBoxFile = BoxProviderInfo.Storage.CreateFile(fileStream, file.Title, folderId);
            }

            BoxProviderInfo.CacheReset(newBoxFile);
            var parentId = GetParentFolderId(newBoxFile);

            if (parentId != null)
            {
                BoxProviderInfo.CacheReset(parentId);
            }

            return(ToFile(newBoxFile));
        }
Esempio n. 17
0
        public Stream GetFileStream(File file, long offset)
        {
            var boxFileId = MakeBoxId(file.ID);

            BoxProviderInfo.CacheReset(boxFileId, true);

            var boxFile = GetBoxFile(file.ID);

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

            var fileStream = BoxProviderInfo.Storage.DownloadStream(boxFile, (int)offset);

            return(fileStream);
        }
Esempio n. 18
0
        public File CopyFile(object fileId, object toFolderId)
        {
            var boxFile = GetBoxFile(fileId);

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

            var toBoxFolder = GetBoxFolder(toFolderId);

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

            var newBoxFile = BoxProviderInfo.Storage.CopyFile(boxFile, toBoxFolder.Id);

            BoxProviderInfo.CacheReset(newBoxFile);
            BoxProviderInfo.CacheReset(toBoxFolder.Id);

            return(ToFile(newBoxFile));
        }
        public Folder CopyFolder(object folderId, object toFolderId)
        {
            var boxFolder = GetBoxFolder(folderId);

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

            var toBoxFolder = GetBoxFolder(toFolderId);

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

            var newBoxFolder = BoxProviderInfo.Storage.CopyFolder(boxFolder, toBoxFolder.Id);

            BoxProviderInfo.CacheReset(newBoxFolder);
            BoxProviderInfo.CacheReset(newBoxFolder.Id, false);

            return(ToFolder(newBoxFolder));
        }
Esempio n. 20
0
 public void Dispose()
 {
     BoxProviderInfo.Dispose();
 }