Exemplo n.º 1
0
        public object MoveFolder(object folderId, object toFolderId, CancellationToken?cancellationToken)
        {
            var driveFolder = GetDriveEntry(folderId);

            if (driveFolder is ErrorDriveEntry)
            {
                throw new Exception(((ErrorDriveEntry)driveFolder).Error);
            }

            var toDriveFolder = GetDriveEntry(toFolderId);

            if (toDriveFolder is ErrorDriveEntry)
            {
                throw new Exception(((ErrorDriveEntry)toDriveFolder).Error);
            }

            var fromFolderDriveId = GetParentDriveId(driveFolder);

            driveFolder = GoogleDriveProviderInfo.Storage.InsertEntryIntoFolder(driveFolder, toDriveFolder.Id);
            if (fromFolderDriveId != null)
            {
                GoogleDriveProviderInfo.Storage.RemoveEntryFromFolder(driveFolder, fromFolderDriveId);
            }

            GoogleDriveProviderInfo.CacheReset(driveFolder.Id);
            GoogleDriveProviderInfo.CacheReset(fromFolderDriveId, true);
            GoogleDriveProviderInfo.CacheReset(toDriveFolder.Id, true);

            return(MakeId(driveFolder.Id));
        }
Exemplo n.º 2
0
        public object RenameFolder(Folder folder, string newTitle)
        {
            var driveFolder = GetDriveEntry(folder.ID);

            if (IsRoot(driveFolder))
            {
                //It's root folder
                GoogleDriveDaoSelector.RenameProvider(GoogleDriveProviderInfo, newTitle);
                //rename provider customer title
            }
            else
            {
                //rename folder
                driveFolder.Name = newTitle;
                driveFolder      = GoogleDriveProviderInfo.Storage.RenameEntry(driveFolder.Id, driveFolder.Name);
            }

            GoogleDriveProviderInfo.CacheReset(driveFolder);
            var parentDriveId = GetParentDriveId(driveFolder);

            if (parentDriveId != null)
            {
                GoogleDriveProviderInfo.CacheReset(parentDriveId, true);
            }

            return(MakeId(driveFolder.Id));
        }
Exemplo 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 driveFolderId = MakeDriveId(folder.ParentFolderID);

                var driveFolder = GoogleDriveProviderInfo.Storage.InsertEntry(null, folder.Title, driveFolderId, true);

                GoogleDriveProviderInfo.CacheReset(driveFolder);
                var parentDriveId = GetParentDriveId(driveFolder);
                if (parentDriveId != null)
                {
                    GoogleDriveProviderInfo.CacheReset(parentDriveId, true);
                }

                return(MakeId(driveFolder));
            }
            return(null);
        }
Exemplo n.º 4
0
        public void DeleteFolder(object folderId)
        {
            var driveFolder = GetDriveEntry(folderId);
            var id          = MakeId(driveFolder);

            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 (!(driveFolder is ErrorDriveEntry))
            {
                GoogleDriveProviderInfo.Storage.DeleteEntry(driveFolder.Id);
            }

            GoogleDriveProviderInfo.CacheReset(driveFolder.Id);
            var parentDriveId = GetParentDriveId(driveFolder);

            if (parentDriveId != null)
            {
                GoogleDriveProviderInfo.CacheReset(parentDriveId, true);
            }
        }
        public object MoveFile(object fileId, object toFolderId)
        {
            var driveFile = GetDriveEntry(fileId);

            if (driveFile is ErrorDriveEntry)
            {
                throw new Exception(((ErrorDriveEntry)driveFile).Error);
            }

            var toDriveFolder = GetDriveEntry(toFolderId);

            if (toDriveFolder is ErrorDriveEntry)
            {
                throw new Exception(((ErrorDriveEntry)toDriveFolder).Error);
            }

            var fromFolderDriveId = GetParentDriveId(driveFile);

            GoogleDriveProviderInfo.Storage.InsertEntryIntoFolder(driveFile, toDriveFolder.Id);
            if (fromFolderDriveId != null)
            {
                GoogleDriveProviderInfo.Storage.RemoveEntryFromFolder(driveFile, fromFolderDriveId);
            }

            GoogleDriveProviderInfo.CacheReset(driveFile.Id);
            GoogleDriveProviderInfo.CacheReset(fromFolderDriveId, false);
            GoogleDriveProviderInfo.CacheReset(toDriveFolder.Id, false);

            return(MakeId(driveFile.Id));
        }
        public File SaveFile(File file, Stream fileStream)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }
            if (fileStream == null)
            {
                throw new ArgumentNullException("fileStream");
            }

            DriveFile newDriveFile = null;

            if (file.ID != null)
            {
                newDriveFile = GoogleDriveProviderInfo.Storage.SaveStream(MakeDriveId(file.ID), fileStream, file.Title);
            }
            else if (file.FolderID != null)
            {
                newDriveFile = GoogleDriveProviderInfo.Storage.InsertEntry(fileStream, file.Title, MakeDriveId(file.FolderID));
            }

            GoogleDriveProviderInfo.CacheReset(newDriveFile);
            var parentDriveId = GetParentDriveId(newDriveFile);

            if (parentDriveId != null)
            {
                GoogleDriveProviderInfo.CacheReset(parentDriveId, false);
            }

            return(ToFile(newDriveFile));
        }
        public Stream GetFileStream(File file, long offset)
        {
            var driveId = MakeDriveId(file.ID);

            GoogleDriveProviderInfo.CacheReset(driveId, true);
            var driveFile = GetDriveEntry(file.ID);

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

            var fileStream = GoogleDriveProviderInfo.Storage.DownloadStream(driveFile);

            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 void InvalidateCache(object fileId)
        {
            var driveId = MakeDriveId(fileId);

            GoogleDriveProviderInfo.CacheReset(driveId, true);

            var driveFile     = GetDriveEntry(fileId);
            var parentDriveId = GetParentDriveId(driveFile);

            if (parentDriveId != null)
            {
                GoogleDriveProviderInfo.CacheReset(parentDriveId);
            }
        }
        public void DeleteFile(object fileId)
        {
            var driveFile = GetDriveEntry(fileId);

            if (driveFile == null)
            {
                return;
            }
            var id = MakeId(driveFile.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 (!(driveFile is ErrorDriveEntry))
            {
                GoogleDriveProviderInfo.Storage.DeleteEntry(driveFile.Id);
            }

            GoogleDriveProviderInfo.CacheReset(driveFile.Id);
            var parentDriveId = GetParentDriveId(driveFile);

            if (parentDriveId != null)
            {
                GoogleDriveProviderInfo.CacheReset(parentDriveId, false);
            }
        }
        public object FileRename(File file, string newTitle)
        {
            var driveFile = GetDriveEntry(file.ID);

            driveFile.Name = newTitle;

            driveFile = GoogleDriveProviderInfo.Storage.RenameEntry(driveFile.Id, driveFile.Name);

            GoogleDriveProviderInfo.CacheReset(driveFile);
            var parentDriveId = GetParentDriveId(driveFile);

            if (parentDriveId != null)
            {
                GoogleDriveProviderInfo.CacheReset(parentDriveId, false);
            }

            return(MakeId(driveFile.Id));
        }
        public File FinalizeUploadSession(ChunkedUploadSession uploadSession)
        {
            if (uploadSession.Items.ContainsKey("GoogleDriveSession"))
            {
                var googleDriveSession = uploadSession.GetItemOrDefault <ResumableUploadSession>("GoogleDriveSession");

                GoogleDriveProviderInfo.CacheReset(googleDriveSession.FileId);
                var parentDriveId = googleDriveSession.FolderId;
                if (parentDriveId != null)
                {
                    GoogleDriveProviderInfo.CacheReset(parentDriveId, false);
                }

                return(ToFile(GetDriveEntry(googleDriveSession.FileId)));
            }

            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 CopyFile(object fileId, object toFolderId)
        {
            var driveFile = GetDriveEntry(fileId);

            if (driveFile is ErrorDriveEntry)
            {
                throw new Exception(((ErrorDriveEntry)driveFile).Error);
            }

            var toDriveFolder = GetDriveEntry(toFolderId);

            if (toDriveFolder is ErrorDriveEntry)
            {
                throw new Exception(((ErrorDriveEntry)toDriveFolder).Error);
            }

            var newDriveFile = GoogleDriveProviderInfo.Storage.CopyEntry(toDriveFolder.Id, driveFile.Id);

            GoogleDriveProviderInfo.CacheReset(newDriveFile);
            GoogleDriveProviderInfo.CacheReset(toDriveFolder.Id, false);

            return(ToFile(newDriveFile));
        }
        public Folder CopyFolder(object folderId, object toFolderId)
        {
            var driveFolder = GetDriveEntry(folderId);

            if (driveFolder is ErrorDriveEntry)
            {
                throw new Exception(((ErrorDriveEntry)driveFolder).Error);
            }

            var toDriveFolder = GetDriveEntry(toFolderId);

            if (toDriveFolder is ErrorDriveEntry)
            {
                throw new Exception(((ErrorDriveEntry)toDriveFolder).Error);
            }

            var newDriveFolder = GoogleDriveProviderInfo.Storage.InsertEntry(null, driveFolder.Name, toDriveFolder.Id, true);

            GoogleDriveProviderInfo.CacheReset(newDriveFolder);
            GoogleDriveProviderInfo.CacheReset(toDriveFolder.Id, true);

            return(ToFolder(newDriveFolder));
        }