public void DeleteFolder(object folderId) { var dropboxFolder = GetDropboxFolder(folderId); var id = MakeId(dropboxFolder); 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 (!(dropboxFolder is ErrorFolder)) { DropboxProviderInfo.Storage.DeleteItem(dropboxFolder); } DropboxProviderInfo.CacheReset(MakeDropboxPath(dropboxFolder), true); var parentFolderPath = GetParentFolderPath(dropboxFolder); if (parentFolderPath != null) { DropboxProviderInfo.CacheReset(parentFolderPath); } }
public object RenameFolder(Folder folder, string newTitle) { var dropboxFolder = GetDropboxFolder(folder.ID); var parentFolderPath = GetParentFolderPath(dropboxFolder); if (IsRoot(dropboxFolder)) { //It's root folder DropboxDaoSelector.RenameProvider(DropboxProviderInfo, newTitle); //rename provider customer title } else { newTitle = GetAvailableTitle(newTitle, parentFolderPath, IsExist); //rename folder dropboxFolder = DropboxProviderInfo.Storage.MoveFolder(MakeDropboxPath(dropboxFolder), parentFolderPath, newTitle); } DropboxProviderInfo.CacheReset(dropboxFolder); if (parentFolderPath != null) { DropboxProviderInfo.CacheReset(parentFolderPath); } return(MakeId(dropboxFolder)); }
public File FinalizeUploadSession(ChunkedUploadSession uploadSession) { if (uploadSession.Items.ContainsKey("DropboxSession")) { var dropboxSession = uploadSession.GetItemOrDefault <string>("DropboxSession"); Metadata dropboxFile; var file = uploadSession.File; if (file.ID != null) { var dropboxFilePath = MakeDropboxPath(file.ID); dropboxFile = DropboxProviderInfo.Storage.FinishResumableSession(dropboxSession, dropboxFilePath, uploadSession.BytesUploaded); } else { var folderPath = MakeDropboxPath(file.FolderID); var title = GetAvailableTitle(file.Title, folderPath, IsExist); dropboxFile = DropboxProviderInfo.Storage.FinishResumableSession(dropboxSession, folderPath, title, uploadSession.BytesUploaded); } DropboxProviderInfo.CacheReset(MakeDropboxPath(dropboxFile)); DropboxProviderInfo.CacheReset(GetParentFolderPath(dropboxFile), false); return(ToFile(dropboxFile.AsFile)); } using (var fs = new FileStream(uploadSession.GetItemOrDefault <string>("TempPath"), FileMode.Open, FileAccess.Read, FileShare.None, 4096, FileOptions.DeleteOnClose)) { return(SaveFile(uploadSession.File, fs)); } }
public File SaveFile(File file, Stream fileStream) { if (file == null) { throw new ArgumentNullException("file"); } if (fileStream == null) { throw new ArgumentNullException("fileStream"); } FileMetadata newDropboxFile = null; if (file.ID != null) { newDropboxFile = DropboxProviderInfo.Storage.SaveStream(MakeDropboxPath(file.ID), fileStream); } else if (file.FolderID != null) { var folderPath = MakeDropboxPath(file.FolderID); file.Title = GetAvailableTitle(file.Title, folderPath, IsExist); newDropboxFile = DropboxProviderInfo.Storage.CreateFile(fileStream, file.Title, folderPath); } DropboxProviderInfo.CacheReset(newDropboxFile); var parentPath = GetParentFolderPath(newDropboxFile); if (parentPath != null) { DropboxProviderInfo.CacheReset(parentPath); } return(ToFile(newDropboxFile)); }
public object MoveFile(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 fromFolderPath = GetParentFolderPath(dropboxFile); dropboxFile = DropboxProviderInfo.Storage.MoveFile(MakeDropboxPath(dropboxFile), MakeDropboxPath(toDropboxFolder), dropboxFile.Name); DropboxProviderInfo.CacheReset(MakeDropboxPath(dropboxFile), true); DropboxProviderInfo.CacheReset(fromFolderPath); DropboxProviderInfo.CacheReset(MakeDropboxPath(toDropboxFolder)); return(MakeId(dropboxFile)); }
public object MoveFolder(object folderId, object toFolderId, CancellationToken?cancellationToken) { 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 fromFolderPath = GetParentFolderPath(dropboxFolder); dropboxFolder = DropboxProviderInfo.Storage.MoveFolder(MakeDropboxPath(dropboxFolder), MakeDropboxPath(toDropboxFolder), dropboxFolder.Name); DropboxProviderInfo.CacheReset(MakeDropboxPath(dropboxFolder), false); DropboxProviderInfo.CacheReset(fromFolderPath); DropboxProviderInfo.CacheReset(MakeDropboxPath(toDropboxFolder)); return(MakeId(dropboxFolder)); }
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)); if (fileStream != null) { if (fileStream.CanSeek) { file.ContentLength = fileStream.Length; // hack for google drive } if (fileStream.CanSeek && offset > 0) { fileStream.Seek(offset, SeekOrigin.Begin); } } return(fileStream); }
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 dropboxFolderPath = MakeDropboxPath(folder.ParentFolderID); folder.Title = GetAvailableTitle(folder.Title, dropboxFolderPath, IsExist); var dropboxFolder = DropboxProviderInfo.Storage.CreateFolder(folder.Title, dropboxFolderPath); DropboxProviderInfo.CacheReset(dropboxFolder); var parentFolderPath = GetParentFolderPath(dropboxFolder); if (parentFolderPath != null) { DropboxProviderInfo.CacheReset(parentFolderPath); } return(MakeId(dropboxFolder)); } return(null); }
public void RenameProvider(DropboxProviderInfo dropboxProviderInfo, string newTitle) { using (var dbDao = new CachedProviderAccountDao(CoreContext.TenantManager.GetCurrentTenant().TenantId, FileConstant.DatabaseId)) { dbDao.UpdateProviderInfo(dropboxProviderInfo.ID, newTitle, dropboxProviderInfo.RootFolderType); dropboxProviderInfo.UpdateTitle(newTitle); //This will update cached version too } }
public void InvalidateCache(object fileId) { var dropboxFilePath = MakeDropboxPath(fileId); DropboxProviderInfo.CacheReset(dropboxFilePath, true); var dropboxFile = GetDropboxFile(fileId); var parentPath = GetParentFolderPath(dropboxFile); if (parentPath != null) { DropboxProviderInfo.CacheReset(parentPath); } }
protected FileMetadata GetDropboxFile(object fileId) { var dropboxFilePath = MakeDropboxPath(fileId); try { var file = DropboxProviderInfo.GetDropboxFile(dropboxFilePath); return(file); } catch (Exception ex) { return(new ErrorFile(ex, dropboxFilePath)); } }
protected FolderMetadata GetDropboxFolder(object folderId) { var dropboxFolderPath = MakeDropboxPath(folderId); try { var folder = DropboxProviderInfo.GetDropboxFolder(dropboxFolderPath); return(folder); } catch (Exception ex) { return(new ErrorFolder(ex, dropboxFolderPath)); } }
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_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 (!(dropboxFile is ErrorFile)) { DropboxProviderInfo.Storage.DeleteItem(dropboxFile); } DropboxProviderInfo.CacheReset(MakeDropboxPath(dropboxFile), true); var parentFolderPath = GetParentFolderPath(dropboxFile); if (parentFolderPath != null) { DropboxProviderInfo.CacheReset(parentFolderPath); } }
protected List <Metadata> GetDropboxItems(object parentId, bool?folder = null) { var dropboxFolderPath = MakeDropboxPath(parentId); var items = DropboxProviderInfo.GetDropboxItems(dropboxFolderPath); if (folder.HasValue) { if (folder.Value) { return(items.Where(i => i.AsFolder != null).ToList()); } return(items.Where(i => i.AsFile != null).ToList()); } return(items); }
public object FileRename(File file, string newTitle) { var dropboxFile = GetDropboxFile(file.ID); var parentFolderPath = GetParentFolderPath(dropboxFile); newTitle = GetAvailableTitle(newTitle, parentFolderPath, IsExist); dropboxFile = DropboxProviderInfo.Storage.MoveFile(MakeDropboxPath(dropboxFile), parentFolderPath, newTitle); DropboxProviderInfo.CacheReset(dropboxFile); var parentPath = GetParentFolderPath(dropboxFile); if (parentPath != null) { DropboxProviderInfo.CacheReset(parentPath); } return(MakeId(dropboxFile)); }
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); }
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)); }
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)); }
public void Dispose() { DropboxProviderInfo.Dispose(); }