コード例 #1
0
        private void DeleteFiles(List <object> fileIds)
        {
            if (fileIds.Count == 0)
            {
                return;
            }

            foreach (var fileId in fileIds)
            {
                if (Canceled)
                {
                    return;
                }

                var file = FileDao.GetFile(fileId);
                if (file == null)
                {
                    Error = FilesCommonResource.ErrorMassage_FileNotFound;
                }
                else if (!ignoreException && EntryManager.FileLockedForMe(file.ID))
                {
                    Error = FilesCommonResource.ErrorMassage_LockedFile;
                }
                else if (!ignoreException && FileTracker.IsEditing(file.ID))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFile;
                }
                else if (!ignoreException && !FilesSecurity.CanDelete(file))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile;
                }
                else
                {
                    FileMarker.RemoveMarkAsNewForAll(file);
                    if (FileDao.UseTrashForRemove(file))
                    {
                        FileDao.MoveFile(file.ID, _trashId);

                        FilesMessageService.Send(file, httpRequestHeaders, MessageAction.FileMovedToTrash, file.Title);
                        ResultedFile(fileId);
                    }
                    else
                    {
                        try
                        {
                            FileDao.DeleteFile(file.ID);
                            FileDao.DeleteFolder(file.ID);
                        }
                        catch (Exception ex)
                        {
                            Error = ex.Message;

                            Logger.Error(Error, ex);
                        }
                    }
                    ProcessedFile(fileId);
                }
                ProgressStep();
            }
        }
コード例 #2
0
        private bool WithError(IServiceScope scope, IEnumerable <File> files, bool folder, out string error)
        {
            var entryManager = scope.ServiceProvider.GetService <EntryManager>();

            error = null;
            foreach (var file in files)
            {
                if (!FilesSecurity.CanDelete(file))
                {
                    error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile;
                    return(true);
                }
                if (entryManager.FileLockedForMe(file.ID))
                {
                    error = FilesCommonResource.ErrorMassage_LockedFile;
                    return(true);
                }
                if (FileTracker.IsEditing(file.ID))
                {
                    error = folder ? FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFolder : FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFile;
                    return(true);
                }
            }
            return(false);
        }
コード例 #3
0
        private NameValueCollection GetFiles()
        {
            var result = new NameValueCollection();

            if (0 < Files.Count)
            {
                var files = FilesSecurity.FilterRead(FileDao.GetFiles(Files.ToArray())).ToList();
                files.ForEach(f => result.Add(f.Title, f.ID.ToString()));
                TagDao.RemoveTags(files.Select(f => Tag.New(SecurityContext.CurrentAccount.ID, f)).ToArray());
            }
            if (0 < Folders.Count)
            {
                Folders.ForEach(f => TagDao.RemoveTags(TagDao.GetTags(f, FileEntryType.Folder, TagType.New)
                                                       .Where(t => t.Owner == SecurityContext.CurrentAccount.ID)
                                                       .ToArray()));

                var filesInFolder = GetFilesInFolders(Folders, string.Empty);
                if (filesInFolder == null)
                {
                    return(null);
                }
                result.Add(filesInFolder);
            }
            return(result);
        }
コード例 #4
0
        private ItemNameValueCollection GetFilesInFolders(IEnumerable <object> folderIds, string path)
        {
            CancellationToken.ThrowIfCancellationRequested();

            var entriesPathId = new ItemNameValueCollection();

            foreach (var folderId in folderIds)
            {
                var folder = FolderDao.GetFolder(folderId);
                if (folder == null || !FilesSecurity.CanRead(folder))
                {
                    continue;
                }
                var folderPath = path + folder.Title + "/";

                var files = FileDao.GetFiles(folder.ID, null, FilterType.None, Guid.Empty, string.Empty);
                files = FilesSecurity.FilterRead(files).ToList();
                files.ForEach(file => entriesPathId.Add(ExecPathFromFile(file, folderPath)));

                FileMarker.RemoveMarkAsNew(folder);

                var nestedFolders = FolderDao.GetFolders(folder.ID);
                nestedFolders = FilesSecurity.FilterRead(nestedFolders).ToList();
                if (files.Count == 0 && nestedFolders.Count == 0)
                {
                    entriesPathId.Add(folderPath, String.Empty);
                }

                var filesInFolder = GetFilesInFolders(nestedFolders.ConvertAll(f => f.ID), folderPath);
                entriesPathId.Add(filesInFolder);
            }
            return(entriesPathId);
        }
コード例 #5
0
        private void DeleteFiles(List <object> fileIds)
        {
            if (fileIds.Count == 0)
            {
                return;
            }

            foreach (var fileId in fileIds)
            {
                if (Canceled)
                {
                    return;
                }

                var file = FileDao.GetFile(fileId);
                if (file == null)
                {
                    Error = FilesCommonResource.ErrorMassage_FileNotFound;
                }
                else if (!ignoreException && (file.FileStatus & FileStatus.IsEditing) == FileStatus.IsEditing)
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFile;
                }
                else if (!ignoreException && !FilesSecurity.CanDelete(file))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile;
                }
                else
                {
                    FileMarker.RemoveMarkAsNewForAll(file);
                    if (FileDao.UseTrashForRemove(file))
                    {
                        FileDao.MoveFile(file.ID, _trashId);
                    }
                    else
                    {
                        try
                        {
                            FileDao.DeleteFile(file.ID);
                            FileDao.DeleteFolder(file.ID);
                        }
                        catch (Exception ex)
                        {
                            Error = ex.Message;

                            Logger.Error(Error, ex);
                        }
                    }
                    ProcessedFile(fileId);
                }
                ProgressStep();
            }
        }
コード例 #6
0
        protected override void Do(IServiceScope scope)
        {
            var fileMarker = scope.ServiceProvider.GetService <FileMarker>();

            Status += string.Format("folder_{0}{1}", _toFolderId, FileOperation.SPLIT_CHAR);

            //TODO: check on each iteration?
            var toFolder = FolderDao.GetFolder(_toFolderId);

            if (toFolder == null)
            {
                return;
            }
            if (!FilesSecurity.CanCreate(toFolder))
            {
                throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create);
            }

            if (FolderDao.GetParentFolders(toFolder.ID).Any(parent => Folders.Contains(parent.ID.ToString())))
            {
                Error = FilesCommonResource.ErrorMassage_FolderCopyError;
                return;
            }

            if (_copy)
            {
                Folder rootFrom = null;
                if (0 < Folders.Count)
                {
                    rootFrom = FolderDao.GetRootFolder(Folders[0]);
                }
                if (0 < Files.Count)
                {
                    rootFrom = FolderDao.GetRootFolderByFile(Files[0]);
                }
                if (rootFrom != null && rootFrom.FolderType == FolderType.TRASH)
                {
                    throw new InvalidOperationException("Can not copy from Trash.");
                }
                if (toFolder.RootFolderType == FolderType.TRASH)
                {
                    throw new InvalidOperationException("Can not copy to Trash.");
                }
            }

            MoveOrCopyFolders(scope, Folders, toFolder, _copy);
            MoveOrCopyFiles(scope, Files, toFolder, _copy);

            _needToMark.Distinct().ToList().ForEach(x => fileMarker.MarkAsNew(x));
        }
コード例 #7
0
        private void DeleteFiles(List <object> fileIds)
        {
            foreach (var fileId in fileIds)
            {
                CancellationToken.ThrowIfCancellationRequested();

                var file = FileDao.GetFile(fileId);
                if (file == null)
                {
                    Error = FilesCommonResource.ErrorMassage_FileNotFound;
                }
                else if (!ignoreException && EntryManager.FileLockedForMe(file.ID))
                {
                    Error = FilesCommonResource.ErrorMassage_LockedFile;
                }
                else if (!ignoreException && FileTracker.IsEditing(file.ID))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFile;
                }
                else if (!ignoreException && !FilesSecurity.CanDelete(file))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile;
                }
                else
                {
                    FileMarker.RemoveMarkAsNewForAll(file);
                    if (FileDao.UseTrashForRemove(file))
                    {
                        FileDao.MoveFile(file.ID, trashId);
                        FilesMessageService.Send(file, headers, MessageAction.FileMovedToTrash, file.Title);
                    }
                    else
                    {
                        try
                        {
                            FileDao.DeleteFile(file.ID);
                            FileDao.DeleteFolder(file.ID);
                        }
                        catch (Exception ex)
                        {
                            Error = ex.Message;
                            Logger.Error(Error, ex);
                        }
                    }
                    ProcessedFile(fileId);
                }
                ProgressStep(fileId: FolderDao.CanCalculateSubitems(fileId) ? null : fileId);
            }
        }
コード例 #8
0
        private void DeleteFiles(List <object> fileIds)
        {
            if (fileIds.Count == 0)
            {
                return;
            }

            foreach (var fileId in fileIds)
            {
                if (Canceled)
                {
                    return;
                }

                var file = FileDao.GetFile(fileId);
                if (file == null)
                {
                    Error = FilesCommonResource.ErrorMassage_FileNotFound;
                }
                else if ((file.FileStatus & FileStatus.IsEditing) == FileStatus.IsEditing)
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFile;
                }
                else if (!FilesSecurity.CanDelete(file))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile;
                }
                else
                {
                    if (FileDao.UseTrashForRemove(file))
                    {
                        FileDao.MoveFile(file.ID, _trashId);
                        NoticeDelete(file);
                    }
                    else
                    {
                        FileDao.DeleteFile(file.ID);
                        FileDao.DeleteFolder(file.ID);
                    }
                    ProcessedFile(fileId);
                }
                ProgressStep();
            }
        }
コード例 #9
0
        protected override void Do()
        {
            Status += string.Format("folder_{0}{1}", _toFolderId, SplitCharacter);

            //TODO: check on each iteration?
            var toFolder = FolderDao.GetFolder(_toFolderId);

            if (toFolder == null)
            {
                return;
            }
            if (!FilesSecurity.CanCreate(toFolder))
            {
                throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create);
            }

            if (_copy)
            {
                Folder rootFrom = null;
                if (0 < Folders.Count)
                {
                    rootFrom = FolderDao.GetRootFolder(Folders[0]);
                }
                if (0 < Files.Count)
                {
                    rootFrom = FolderDao.GetRootFolderByFile(Files[0]);
                }
                if (rootFrom != null && rootFrom.FolderType == FolderType.TRASH)
                {
                    throw new InvalidOperationException("Can not copy from Trash.");
                }
                if (toFolder.RootFolderType == FolderType.TRASH)
                {
                    throw new InvalidOperationException("Can not copy to Trash.");
                }
            }

            MoveOrCopyFolders(Folders, toFolder, _copy);
            MoveOrCopyFiles(Files, toFolder, _copy, _resolveType);

            _needToMarkAsNew.Distinct().ToList().ForEach(x => FileMarker.MarkAsNew(x, _markAsNewRecipientIDs));
        }
コード例 #10
0
        private ItemNameValueCollection GetEntriesPathId()
        {
            var entriesPathId = new ItemNameValueCollection();

            if (0 < Files.Count)
            {
                var files = FileDao.GetFiles(Files.ToArray());
                files = FilesSecurity.FilterRead(files).ToList();
                files.ForEach(file => entriesPathId.Add(ExecPathFromFile(file, string.Empty)));
            }
            if (0 < Folders.Count)
            {
                FilesSecurity.FilterRead(FolderDao.GetFolders(Files.ToArray())).ToList().Cast <FileEntry>().ToList()
                .ForEach(folder => FileMarker.RemoveMarkAsNew(folder));

                var filesInFolder = GetFilesInFolders(Folders, string.Empty);
                entriesPathId.Add(filesInFolder);
            }
            return(entriesPathId);
        }
コード例 #11
0
        protected override void Do()
        {
            Status += string.Format("folder_{0}{1}", _toFolder, splitCharacter);

            //TODO: check on each iteration?
            var to = FolderDao.GetFolder(_toFolder);

            if (to == null)
            {
                return;
            }
            if (!FilesSecurity.CanCreate(to))
            {
                throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create);
            }

            if (_copy)
            {
                Folder rootFrom = null;
                if (0 < Folders.Count)
                {
                    rootFrom = FolderDao.GetRootFolder(Folders[0]);
                }
                if (0 < Files.Count)
                {
                    rootFrom = FolderDao.GetRootFolderByFile(Files[0]);
                }
                if (rootFrom != null && rootFrom.FolderType == FolderType.TRASH)
                {
                    throw new InvalidOperationException("Can not copy from Trash.");
                }
                if (to.RootFolderType == FolderType.TRASH)
                {
                    throw new InvalidOperationException("Can not copy to Trash.");
                }
            }

            MoveOrCopyFolders(Folders, _toFolder, _copy);
            MoveOrCopyFiles(Files, _toFolder, _copy, _resolveType);
        }
コード例 #12
0
 private bool WithError(IEnumerable <File> files, out string error)
 {
     error = null;
     foreach (var file in files)
     {
         if (!FilesSecurity.CanDelete(file))
         {
             error = FilesCommonResource.ErrorMassage_SecurityException_MoveFile;
             return(true);
         }
         if (EntryManager.FileLockedForMe(file.ID))
         {
             error = FilesCommonResource.ErrorMassage_LockedFile;
             return(true);
         }
         if (FileTracker.IsEditing(file.ID))
         {
             error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile;
             return(true);
         }
     }
     return(false);
 }
コード例 #13
0
        private NameValueCollection GetFilesInFolders(IList <object> folderIds, string path)
        {
            if (Canceled)
            {
                return(null);
            }

            var result = new NameValueCollection();

            foreach (var folderId in folderIds)
            {
                var folder = FolderDao.GetFolder(folderId);
                if (folder == null || !FilesSecurity.CanRead(folder))
                {
                    continue;
                }
                var folderPath = path + folder.Title + "/";

                var files = FilesSecurity.FilterRead(FolderDao.GetFiles(folder.ID, null, FilterType.None, Guid.Empty, string.Empty)).ToList();
                files.ForEach(f => result.Add(folderPath + f.Title, f.ID.ToString()));
                TagDao.RemoveTags(files.Select(f => Tag.New(SecurityContext.CurrentAccount.ID, f)).ToArray());

                var nestedFolders = FilesSecurity.FilterRead(FolderDao.GetFolders(folder.ID)).ToList();
                if (files.Count == 0 && nestedFolders.Count == 0)
                {
                    result.Add(folderPath, String.Empty);
                }

                var filesInFolder = GetFilesInFolders(nestedFolders.ConvertAll(f => f.ID), folderPath);
                if (filesInFolder == null)
                {
                    return(null);
                }
                result.Add(filesInFolder);
            }
            return(result);
        }
コード例 #14
0
        private ItemNameValueCollection GetEntriesPathId(out List <File> filesForSend, out List <Folder> folderForSend)
        {
            filesForSend  = new List <File>();
            folderForSend = new List <Folder>();

            var entriesPathId = new ItemNameValueCollection();

            if (0 < Files.Count)
            {
                filesForSend = FilesSecurity.FilterDownload(FileDao.GetFiles(Files));
                filesForSend.ForEach(file => entriesPathId.Add(ExecPathFromFile(file, string.Empty)));
            }
            if (0 < Folders.Count)
            {
                folderForSend = FolderDao.GetFolders(Folders);
                folderForSend = FilesSecurity.FilterDownload(folderForSend);
                folderForSend.ForEach(folder => FileMarker.RemoveMarkAsNew(folder));

                var filesInFolder = GetFilesInFolders(folderForSend.Select(x => x.ID), string.Empty);
                entriesPathId.Add(filesInFolder);
            }

            if (Folders.Count == 1 && Files.Count == 0)
            {
                var entriesPathIdWithoutRoot = new ItemNameValueCollection();

                foreach (var path in entriesPathId.AllKeys)
                {
                    entriesPathIdWithoutRoot.Add(path.Remove(0, path.IndexOf('/') + 1), entriesPathId[path]);
                }

                return(entriesPathIdWithoutRoot);
            }

            return(entriesPathId);
        }
コード例 #15
0
        private void DeleteFolders(List <object> folderIds)
        {
            foreach (var folderId in folderIds)
            {
                CancellationToken.ThrowIfCancellationRequested();

                var    folder       = FolderDao.GetFolder(folderId);
                object canCalculate = null;
                if (folder == null)
                {
                    Error = FilesCommonResource.ErrorMassage_FolderNotFound;
                }
                else if (folder.FolderType != FolderType.DEFAULT && folder.FolderType != FolderType.BUNCH)
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder;
                }
                else if (!ignoreException && !FilesSecurity.CanDelete(folder))
                {
                    canCalculate = FolderDao.CanCalculateSubitems(folderId) ? null : folderId;

                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder;
                }
                else
                {
                    canCalculate = FolderDao.CanCalculateSubitems(folderId) ? null : folderId;

                    FileMarker.RemoveMarkAsNewForAll(folder);
                    if (folder.ProviderEntry && folder.ID.Equals(folder.RootFolderId))
                    {
                        if (ProviderDao != null)
                        {
                            ProviderDao.RemoveProviderInfo(folder.ProviderId);
                            FilesMessageService.Send(folder, headers, MessageAction.ThirdPartyDeleted, folder.ID.ToString(), folder.ProviderKey);
                        }

                        ProcessedFolder(folderId);
                    }
                    else
                    {
                        if (FolderDao.UseTrashForRemove(folder))
                        {
                            var files = FileDao.GetFiles(folder.ID);
                            if (!ignoreException && files.Exists(FileTracker.IsEditing))
                            {
                                Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFolder;
                            }
                            else
                            {
                                FolderDao.MoveFolder(folder.ID, trashId);
                                FilesMessageService.Send(folder, headers, MessageAction.FolderMovedToTrash, folder.Title);

                                ProcessedFolder(folderId);
                            }
                        }
                        else
                        {
                            if (FolderDao.UseRecursiveOperation(folder.ID, null))
                            {
                                DeleteFiles(FileDao.GetFiles(folder.ID));
                                DeleteFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList());

                                if (FolderDao.IsEmpty(folder.ID))
                                {
                                    FolderDao.DeleteFolder(folder.ID);
                                    ProcessedFolder(folderId);
                                }
                            }
                            else
                            {
                                FolderDao.DeleteFolder(folder.ID);
                                ProcessedFolder(folderId);
                            }
                        }
                    }
                }
                ProgressStep(canCalculate);
            }
        }
コード例 #16
0
        private void MoveOrCopyFolders(ICollection folderIds, Folder toFolder, bool copy)
        {
            if (folderIds.Count == 0)
            {
                return;
            }

            var toFolderId = toFolder.ID;
            var isToFolder = Equals(toFolderId.ToString(), _toFolderId);

            foreach (var folderId in folderIds)
            {
                CancellationToken.ThrowIfCancellationRequested();

                var folder = FolderDao.GetFolder(folderId);
                if (folder == null)
                {
                    Error = FilesCommonResource.ErrorMassage_FolderNotFound;
                }
                else if (!FilesSecurity.CanRead(folder))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFolder;
                }
                else if (!FilesSecurity.CanDownload(folder))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException;
                }
                else if (folder.RootFolderType == FolderType.Privacy &&
                         (copy || toFolder.RootFolderType != FolderType.Privacy))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_MoveFolder;
                }
                else if (!Equals((folder.ParentFolderID ?? string.Empty).ToString(), toFolderId.ToString()) || _resolveType == FileConflictResolveType.Duplicate)
                {
                    try
                    {
                        //if destination folder contains folder with same name then merge folders
                        var conflictFolder = folder.RootFolderType == FolderType.Privacy
                            ? null
                            : FolderDao.GetFolder(folder.Title, toFolderId);
                        Folder newFolder;

                        if (copy || conflictFolder != null)
                        {
                            if (conflictFolder != null)
                            {
                                newFolder = conflictFolder;

                                if (isToFolder)
                                {
                                    _needToMark.Add(conflictFolder);
                                }
                            }
                            else
                            {
                                newFolder = FolderDao.CopyFolder(folder.ID, toFolderId, CancellationToken);
                                FilesMessageService.Send(newFolder, toFolder, _headers, MessageAction.FolderCopied, newFolder.Title, toFolder.Title);

                                if (isToFolder)
                                {
                                    _needToMark.Add(newFolder);
                                }

                                if (ProcessedFolder(folderId))
                                {
                                    Status += string.Format("folder_{0}{1}", newFolder.ID, SPLIT_CHAR);
                                }
                            }

                            if (toFolder.ProviderId == folder.ProviderId && // crossDao operation is always recursive
                                FolderDao.UseRecursiveOperation(folder.ID, toFolderId))
                            {
                                MoveOrCopyFiles(FileDao.GetFiles(folder.ID), newFolder, copy);
                                MoveOrCopyFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList(), newFolder, copy);

                                if (!copy)
                                {
                                    if (!FilesSecurity.CanDelete(folder))
                                    {
                                        Error = FilesCommonResource.ErrorMassage_SecurityException_MoveFolder;
                                    }
                                    else if (FolderDao.IsEmpty(folder.ID))
                                    {
                                        FolderDao.DeleteFolder(folder.ID);
                                        if (ProcessedFolder(folderId))
                                        {
                                            Status += string.Format("folder_{0}{1}", newFolder.ID, SPLIT_CHAR);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (conflictFolder != null)
                                {
                                    string tmpError;
                                    object newFolderId;
                                    if (copy)
                                    {
                                        newFolder   = FolderDao.CopyFolder(folder.ID, toFolderId, CancellationToken);
                                        newFolderId = newFolder.ID;
                                        FilesMessageService.Send(newFolder, toFolder, _headers, MessageAction.FolderCopiedWithOverwriting, newFolder.Title, toFolder.Title);

                                        if (isToFolder)
                                        {
                                            _needToMark.Add(newFolder);
                                        }

                                        if (ProcessedFolder(folderId))
                                        {
                                            Status += string.Format("folder_{0}{1}", newFolderId, SPLIT_CHAR);
                                        }
                                    }
                                    else if (!FilesSecurity.CanDelete(folder))
                                    {
                                        Error = FilesCommonResource.ErrorMassage_SecurityException_MoveFolder;
                                    }
                                    else if (WithError(FileDao.GetFiles(folder.ID, new OrderBy(SortedByType.AZ, true), FilterType.FilesOnly, false, Guid.Empty, string.Empty, false, true), out tmpError))
                                    {
                                        Error = tmpError;
                                    }
                                    else
                                    {
                                        FileMarker.RemoveMarkAsNewForAll(folder);

                                        newFolderId = FolderDao.MoveFolder(folder.ID, toFolderId, CancellationToken);
                                        newFolder   = FolderDao.GetFolder(newFolderId);
                                        FilesMessageService.Send(folder, toFolder, _headers, MessageAction.FolderMovedWithOverwriting, folder.Title, toFolder.Title);

                                        if (isToFolder)
                                        {
                                            _needToMark.Add(newFolder);
                                        }

                                        if (ProcessedFolder(folderId))
                                        {
                                            Status += string.Format("folder_{0}{1}", newFolderId, SPLIT_CHAR);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            string tmpError;
                            if (!FilesSecurity.CanDelete(folder))
                            {
                                Error = FilesCommonResource.ErrorMassage_SecurityException_MoveFolder;
                            }
                            else if (WithError(FileDao.GetFiles(folder.ID, new OrderBy(SortedByType.AZ, true), FilterType.FilesOnly, false, Guid.Empty, string.Empty, false, true), out tmpError))
                            {
                                Error = tmpError;
                            }
                            else
                            {
                                FileMarker.RemoveMarkAsNewForAll(folder);
                                var parentFolder = FolderDao.GetFolder(folder.RootFolderId);

                                var newFolderId = FolderDao.MoveFolder(folder.ID, toFolderId, CancellationToken);
                                newFolder = FolderDao.GetFolder(newFolderId);
                                FilesMessageService.Send(folder, toFolder, _headers, MessageAction.FolderMovedFrom, folder.Title, parentFolder.Title, toFolder.Title);

                                if (isToFolder)
                                {
                                    _needToMark.Add(newFolder);
                                }

                                if (ProcessedFolder(folderId))
                                {
                                    Status += string.Format("folder_{0}{1}", newFolderId, SPLIT_CHAR);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Error = ex.Message;

                        Logger.Error(Error, ex);
                    }
                }
                ProgressStep(FolderDao.CanCalculateSubitems(folderId) ? null : folderId);
            }
        }
コード例 #17
0
        private void DeleteFolders(List <object> folderIds)
        {
            foreach (var folderId in folderIds)
            {
                CancellationToken.ThrowIfCancellationRequested();

                var folder = FolderDao.GetFolder(folderId);
                if (folder == null)
                {
                    Error = FilesCommonResource.ErrorMassage_FolderNotFound;
                }
                else if (!ignoreException && !FilesSecurity.CanDelete(folder))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder;
                }
                else
                {
                    FileMarker.RemoveMarkAsNewForAll(folder);
                    if (FolderDao.UseTrashForRemove(folder))
                    {
                        var files = FileDao.GetFiles(folder.ID, true);
                        if (!ignoreException && files.Exists(FileTracker.IsEditing))
                        {
                            Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFolder;
                        }
                        else
                        {
                            FolderDao.MoveFolder(folder.ID, trashId);
                            FilesMessageService.Send(folder, headers, MessageAction.FolderMovedToTrash, folder.Title);

                            ProcessedFolder(folderId);
                        }
                    }
                    else
                    {
                        if (FolderDao.UseRecursiveOperation(folder.ID, null))
                        {
                            DeleteFiles(FileDao.GetFiles(folder.ID, false));
                            DeleteFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList());

                            if (FolderDao.GetItemsCount(folder.ID, true) == 0)
                            {
                                FolderDao.DeleteFolder(folder.ID);
                                ProcessedFolder(folderId);
                            }
                        }
                        else
                        {
                            if (folder.ProviderEntry && folder.ID.Equals(folder.RootFolderId))
                            {
                                ProviderDao.RemoveProviderInfo(folder.ProviderId);
                            }
                            else
                            {
                                FolderDao.DeleteFolder(folder.ID);
                            }
                            ProcessedFolder(folderId);
                        }
                    }
                }
                ProgressStep();
            }
        }
コード例 #18
0
        private void MoveOrCopyFiles(ICollection fileIds, Folder toFolder, bool copy, FileConflictResolveType resolveType)
        {
            if (fileIds.Count == 0)
            {
                return;
            }

            var toFolderId = toFolder.ID;

            foreach (var fileId in fileIds)
            {
                if (Canceled)
                {
                    return;
                }

                var file = FileDao.GetFile(fileId);
                if (file == null)
                {
                    Error = FilesCommonResource.ErrorMassage_FileNotFound;
                }
                else if (!FilesSecurity.CanRead(file))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFile;
                }
                else if (Global.EnableUploadFilter &&
                         !Studio.Utility.FileUtility.ExtsUploadable.Contains(Studio.Utility.FileUtility.GetFileExtension(file.Title)))
                {
                    Error = FilesCommonResource.ErrorMassage_NotSupportedFormat;
                }
                else if (!Equals(file.FolderID.ToString(), toFolderId))
                {
                    try
                    {
                        var conflict = FileDao.GetFile(toFolderId, file.Title);
                        if (conflict != null && !FilesSecurity.CanEdit(conflict))
                        {
                            Error = FilesCommonResource.ErrorMassage_SecurityException;
                        }
                        else if (conflict == null)
                        {
                            if (copy)
                            {
                                File newFile = null;
                                try
                                {
                                    newFile = FileDao.CopyFile(file.ID, toFolderId); //Stream copy will occur inside dao

                                    if (Equals(newFile.FolderID.ToString(), _toFolderId))
                                    {
                                        _needToMarkAsNew.Add(newFile);
                                    }

                                    ProcessedFile(fileId);
                                }
                                catch
                                {
                                    if (newFile != null)
                                    {
                                        FileDao.DeleteFile(newFile.ID);
                                    }
                                    throw;
                                }
                            }
                            else
                            {
                                if ((file.FileStatus & FileStatus.IsEditing) == FileStatus.IsEditing)
                                {
                                    Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile;
                                }
                                else if (FilesSecurity.CanDelete(file))
                                {
                                    FileMarker.RemoveMarkAsNewForAll(file);

                                    var newFileId = FileDao.MoveFile(file.ID, toFolderId);

                                    if (Equals(toFolderId.ToString(), _toFolderId))
                                    {
                                        _needToMarkAsNew.Add(FileDao.GetFile(newFileId));
                                    }

                                    ProcessedFile(fileId);
                                }
                                else
                                {
                                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile;
                                }
                            }
                        }
                        else
                        {
                            if (resolveType == FileConflictResolveType.Overwrite)
                            {
                                conflict.Version++;
                                using (var stream = FileDao.GetFileStream(file))
                                {
                                    conflict.ContentLength = stream.Length;
                                    conflict = FileDao.SaveFile(conflict, stream);

                                    _needToMarkAsNew.Add(conflict);
                                }

                                if (copy)
                                {
                                    ProcessedFile(fileId);
                                }
                                else
                                {
                                    if ((file.FileStatus & FileStatus.IsEditing) == FileStatus.IsEditing)
                                    {
                                        Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile;
                                    }
                                    else if (FilesSecurity.CanDelete(file))
                                    {
                                        FileDao.DeleteFile(file.ID);
                                        FileDao.DeleteFolder(file.ID);
                                        ProcessedFile(fileId);
                                    }
                                    else
                                    {
                                        Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile;
                                    }
                                }
                            }
                            else if (resolveType == FileConflictResolveType.Skip)
                            {
                                //nothing
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Error = ex.Message;
                        Logger.Error(Error, ex);
                    }
                }
                ProgressStep();
            }
        }
コード例 #19
0
        private void MoveOrCopyFiles(List <object> fileIds, object to, bool copy, FileConflictResolveType resolveType)
        {
            if (fileIds.Count == 0)
            {
                return;
            }

            foreach (var fileId in fileIds)
            {
                if (Canceled)
                {
                    return;
                }

                var file = FileDao.GetFile(fileId);
                if (file == null)
                {
                    Error = FilesCommonResource.ErrorMassage_FileNotFound;
                }
                else if (!FilesSecurity.CanRead(file))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFile;
                }
                else if (!Equals(file.FolderID.ToString(), to))
                {
                    var conflict = FileDao.GetFile(to, file.Title);
                    if (conflict != null && !FilesSecurity.CanEdit(conflict))
                    {
                        Error = FilesCommonResource.ErrorMassage_SecurityException;
                    }
                    else if (conflict == null)
                    {
                        if (copy)
                        {
                            File newFile = null;
                            try
                            {
                                newFile = FileDao.CopyFile(file.ID, to); //Stream copy will occur inside dao
                                ProcessedFile(fileId);
                            }
                            catch
                            {
                                if (newFile != null)
                                {
                                    FileDao.DeleteFile(newFile.ID);
                                }
                                throw;
                            }
                        }
                        else
                        {
                            if ((file.FileStatus & FileStatus.IsEditing) == FileStatus.IsEditing)
                            {
                                Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile;
                            }
                            else if (FilesSecurity.CanDelete(file))
                            {
                                FileDao.MoveFile(file.ID, to);
                                ProcessedFile(fileId);
                            }
                            else
                            {
                                Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile;
                            }
                        }
                    }
                    else
                    {
                        if (resolveType == FileConflictResolveType.Overwrite)
                        {
                            conflict.Version++;
                            using (var stream = FileDao.GetFileStream(file))
                            {
                                conflict = FileDao.SaveFile(conflict, stream);
                            }

                            Global.PublishUpdateDocument(conflict.ID);

                            if (copy)
                            {
                                ProcessedFile(fileId);
                            }
                            else
                            {
                                if ((file.FileStatus & FileStatus.IsEditing) == FileStatus.IsEditing)
                                {
                                    Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile;
                                }
                                else if (FilesSecurity.CanDelete(file))
                                {
                                    NotifySource.Instance.GetSubscriptionProvider()
                                    .GetRecipients(NotifyConstants.Event_UpdateDocument, file.UniqID)
                                    .ToList()
                                    .ForEach(r => NotifySource.Instance.GetSubscriptionProvider().Subscribe(NotifyConstants.Event_UpdateDocument, conflict.UniqID, r));

                                    NotifySource.Instance.GetSubscriptionProvider().UnSubscribe(NotifyConstants.Event_UpdateDocument, file.UniqID);

                                    FileDao.DeleteFile(file.ID);
                                    FileDao.DeleteFolder(file.ID);
                                    ProcessedFile(fileId);
                                }
                                else
                                {
                                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile;
                                }
                            }
                        }
                        else if (resolveType == FileConflictResolveType.Skip)
                        {
                            //nothing
                        }
                    }
                }
                ProgressStep();
            }
        }
コード例 #20
0
        protected override void Do()
        {
            if (_files.Count == 0)
            {
                return;
            }

            var parent = FolderDao.GetFolder(_parentId);

            if (parent == null)
            {
                throw new DirectoryNotFoundException(FilesCommonResource.ErrorMassage_FolderNotFound);
            }
            if (!FilesSecurity.CanCreate(parent))
            {
                throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create);
            }
            if (parent.RootFolderType == FolderType.TRASH)
            {
                throw new Exception(FilesCommonResource.ErrorMassage_ImportToTrash);
            }
            if (parent.ProviderEntry)
            {
                throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create);
            }

            var to =
                FolderDao.GetFolder(_folderName, _parentId)
                ?? FolderDao.SaveFolder(
                    new Folder
            {
                FolderType     = FolderType.DEFAULT,
                ParentFolderID = _parentId,
                Title          = _folderName
            });

            foreach (var f in _files)
            {
                if (Canceled)
                {
                    return;
                }
                try
                {
                    long size;
                    using (var stream = _docProvider.GetDocumentStream(f.ContentLink, out size))
                    {
                        if (stream == null)
                        {
                            throw new Exception("Can not import document " + f.ContentLink + ". Empty stream.");
                        }

                        if (SetupInfo.MaxUploadSize < size)
                        {
                            throw FileSizeComment.FileSizeException;
                        }

                        var folderId = to.ID;
                        var pos      = f.Title.LastIndexOf('/');
                        if (0 < pos)
                        {
                            folderId = GetOrCreateHierarchy(f.Title.Substring(0, pos), to);
                            f.Title  = f.Title.Substring(pos + 1);
                        }

                        f.Title = Global.ReplaceInvalidCharsAndTruncate(f.Title);
                        var file = new File
                        {
                            Title         = f.Title,
                            FolderID      = folderId,
                            ContentLength = size,
                        };

                        var conflict = FileDao.GetFile(file.FolderID, file.Title);
                        if (conflict != null)
                        {
                            if (_overwrite)
                            {
                                if (!FilesSecurity.CanEdit(conflict))
                                {
                                    throw new Exception(FilesCommonResource.ErrorMassage_SecurityException);
                                }
                                if ((conflict.FileStatus & FileStatus.IsEditing) == FileStatus.IsEditing)
                                {
                                    throw new Exception(FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile);
                                }
                                if (EntryManager.FileLockedForMe(conflict))
                                {
                                    throw new Exception(FilesCommonResource.ErrorMassage_LockedFile);
                                }

                                file.ID      = conflict.ID;
                                file.Version = conflict.Version + 1;
                            }
                            else
                            {
                                continue;
                            }
                        }

                        if (size <= 0L)
                        {
                            using (var buffered = stream.GetBuffered())
                            {
                                size = buffered.Length;

                                if (SetupInfo.MaxUploadSize < size)
                                {
                                    throw FileSizeComment.FileSizeException;
                                }

                                file.ContentLength = size;
                                try
                                {
                                    file = FileDao.SaveFile(file, buffered);
                                }
                                catch (Exception error)
                                {
                                    FileDao.DeleteFile(file.ID);
                                    throw error;
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                file = FileDao.SaveFile(file, stream);
                                FilesMessageService.Send(file, httpRequestHeaders, MessageAction.FileImported, parent.Title, file.Title, _docProvider.Name);
                            }
                            catch (Exception error)
                            {
                                FileDao.DeleteFile(file.ID);
                                throw error;
                            }
                        }

                        FileMarker.MarkAsNew(file, _markAsNewRecipientIDs);
                    }
                }
                catch (Exception ex)
                {
                    Error = ex.Message;
                    Logger.Error(Error, ex);
                }
                finally
                {
                    ProgressStep();
                }
            }
        }
コード例 #21
0
        private void MoveOrCopyFolders(List <object> folderIds, object to, bool copy)
        {
            if (folderIds.Count == 0)
            {
                return;
            }

            foreach (var folderId in folderIds)
            {
                if (Canceled)
                {
                    return;
                }

                var folder = FolderDao.GetFolder(folderId);
                if (folder == null)
                {
                    Error = FilesCommonResource.ErrorMassage_FolderNotFound;
                }
                else if (!FilesSecurity.CanRead(folder))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFolder;
                }
                else if (!Equals((folder.ParentFolderID ?? string.Empty).ToString(), to))
                {
                    //if destination folder contains folder with same name then merge folders
                    var conflictFolder = FolderDao.GetFolder(folder.Title, to);

                    if (copy || conflictFolder != null)
                    {
                        object newFolder;
                        if (conflictFolder != null)
                        {
                            newFolder = conflictFolder.ID;
                        }
                        else
                        {
                            newFolder = FolderDao.CopyFolder(folder.ID, to);
                            ProcessedFolder(folderId);
                        }

                        if (FolderDao.UseRecursiveOperation(folder, to))
                        {
                            MoveOrCopyFiles(FolderDao.GetFiles(folder.ID, false), newFolder, copy, _resolveType);
                            MoveOrCopyFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList(), newFolder, copy);

                            if (!copy && conflictFolder != null)
                            {
                                if (FolderDao.GetItemsCount(folder.ID, true) == 0 && FilesSecurity.CanDelete(folder))
                                {
                                    FolderDao.DeleteFolder(folder.ID);
                                    ProcessedFolder(folderId);
                                }
                            }
                        }
                        else
                        {
                            if (conflictFolder != null)
                            {
                                if (copy)
                                {
                                    FolderDao.CopyFolder(folder.ID, to);
                                }
                                else
                                {
                                    FolderDao.MoveFolder(folder.ID, to);
                                }
                                ProcessedFolder(folderId);
                            }
                        }
                    }
                    else
                    {
                        if (FilesSecurity.CanDelete(folder))
                        {
                            FolderDao.MoveFolder(folder.ID, to);
                            ProcessedFolder(folderId);
                        }
                        else
                        {
                            Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder;
                        }
                    }
                }
                ProgressStep();
            }
        }
コード例 #22
0
        private void MoveOrCopyFolders(ICollection folderIds, Folder toFolder, bool copy)
        {
            if (folderIds.Count == 0)
            {
                return;
            }

            var toFolderId = toFolder.ID;
            var isToFolder = Equals(toFolderId.ToString(), this.toFolderId);

            foreach (var folderId in folderIds)
            {
                CancellationToken.ThrowIfCancellationRequested();

                var folder = FolderDao.GetFolder(folderId);
                if (folder == null)
                {
                    Error = FilesCommonResource.ErrorMassage_FolderNotFound;
                }
                else if (!FilesSecurity.CanRead(folder))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFolder;
                }
                else if (!Equals((folder.ParentFolderID ?? string.Empty).ToString(), toFolderId.ToString()) || resolveType == FileConflictResolveType.Duplicate)
                {
                    try
                    {
                        //if destination folder contains folder with same name then merge folders
                        var conflictFolder = FolderDao.GetFolder(folder.Title, toFolderId);

                        if (copy || conflictFolder != null)
                        {
                            Folder newFolder;
                            if (conflictFolder != null)
                            {
                                newFolder = conflictFolder;

                                if (isToFolder)
                                {
                                    needToMark.Add(conflictFolder);
                                }
                            }
                            else
                            {
                                newFolder = FolderDao.CopyFolder(folder.ID, toFolderId);
                                FilesMessageService.Send(folder, toFolder, headers, MessageAction.FolderCopied, folder.Title, toFolder.Title);

                                if (isToFolder)
                                {
                                    needToMark.Add(newFolder);
                                }

                                if (ProcessedFolder(folderId))
                                {
                                    Status += string.Format("folder_{0}{1}", newFolder.ID, SPLIT_CHAR);
                                }
                            }

                            if (FolderDao.UseRecursiveOperation(folder.ID, toFolderId))
                            {
                                MoveOrCopyFiles(FileDao.GetFiles(folder.ID), newFolder, copy);
                                MoveOrCopyFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList(), newFolder, copy);

                                if (!copy)
                                {
                                    if (FolderDao.IsEmpty(folder.ID) && FilesSecurity.CanDelete(folder))
                                    {
                                        FolderDao.DeleteFolder(folder.ID);
                                        if (ProcessedFolder(folderId))
                                        {
                                            Status += string.Format("folder_{0}{1}", newFolder.ID, SPLIT_CHAR);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (conflictFolder != null)
                                {
                                    object newFolderId;
                                    if (copy)
                                    {
                                        newFolder   = FolderDao.CopyFolder(folder.ID, toFolderId);
                                        newFolderId = newFolder.ID;
                                        FilesMessageService.Send(folder, toFolder, headers, MessageAction.FolderCopiedWithOverwriting, folder.Title, toFolder.Title);

                                        if (isToFolder)
                                        {
                                            needToMark.Add(newFolder);
                                        }
                                    }
                                    else
                                    {
                                        newFolderId = FolderDao.MoveFolder(folder.ID, toFolderId);
                                        FilesMessageService.Send(folder, toFolder, headers, MessageAction.FolderMovedWithOverwriting, folder.Title, toFolder.Title);

                                        if (isToFolder)
                                        {
                                            needToMark.Add(FolderDao.GetFolder(newFolderId));
                                        }
                                    }

                                    if (ProcessedFolder(folderId))
                                    {
                                        Status += string.Format("folder_{0}{1}", newFolderId, SPLIT_CHAR);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (FilesSecurity.CanDelete(folder))
                            {
                                FileMarker.RemoveMarkAsNewForAll(folder);

                                var newFolderId = FolderDao.MoveFolder(folder.ID, toFolderId);
                                FilesMessageService.Send(folder, toFolder, headers, MessageAction.FolderMoved, folder.Title, toFolder.Title);

                                if (isToFolder)
                                {
                                    needToMark.Add(FolderDao.GetFolder(newFolderId));
                                }

                                if (ProcessedFolder(folderId))
                                {
                                    Status += string.Format("folder_{0}{1}", newFolderId, SPLIT_CHAR);
                                }
                            }
                            else
                            {
                                Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Error = ex.Message;

                        Logger.Error(Error, ex);
                    }
                }
                ProgressStep(FolderDao.CanCalculateSubitems(folderId) ? null : folderId);
            }
        }
コード例 #23
0
        private void DeleteFolders(IEnumerable <object> folderIds)
        {
            foreach (var folderId in folderIds)
            {
                CancellationToken.ThrowIfCancellationRequested();

                var    folder       = FolderDao.GetFolder(folderId);
                object canCalculate = null;
                if (folder == null)
                {
                    Error = FilesCommonResource.ErrorMassage_FolderNotFound;
                }
                else if (folder.FolderType != FolderType.DEFAULT && folder.FolderType != FolderType.BUNCH)
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder;
                }
                else if (!_ignoreException && !FilesSecurity.CanDelete(folder))
                {
                    canCalculate = FolderDao.CanCalculateSubitems(folderId) ? null : folderId;

                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder;
                }
                else
                {
                    canCalculate = FolderDao.CanCalculateSubitems(folderId) ? null : folderId;

                    FileMarker.RemoveMarkAsNewForAll(folder);
                    if (folder.ProviderEntry && folder.ID.Equals(folder.RootFolderId))
                    {
                        if (ProviderDao != null)
                        {
                            ProviderDao.RemoveProviderInfo(folder.ProviderId);
                            FilesMessageService.Send(folder, _headers, MessageAction.ThirdPartyDeleted, folder.ID.ToString(), folder.ProviderKey);
                        }

                        ProcessedFolder(folderId);
                    }
                    else
                    {
                        var immediately = _immediately || !FolderDao.UseTrashForRemove(folder);
                        if (immediately && FolderDao.UseRecursiveOperation(folder.ID, null))
                        {
                            DeleteFiles(FileDao.GetFiles(folder.ID));
                            DeleteFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList());

                            if (FolderDao.IsEmpty(folder.ID))
                            {
                                FolderDao.DeleteFolder(folder.ID);
                                FilesMessageService.Send(folder, _headers, MessageAction.FolderDeleted, folder.Title);

                                ProcessedFolder(folderId);
                            }
                        }
                        else
                        {
                            var    files = FileDao.GetFiles(folder.ID, new OrderBy(SortedByType.AZ, true), FilterType.FilesOnly, false, Guid.Empty, string.Empty, false, true);
                            string tmpError;
                            if (!_ignoreException && WithError(files, true, out tmpError))
                            {
                                Error = tmpError;
                            }
                            else
                            {
                                if (immediately)
                                {
                                    FolderDao.DeleteFolder(folder.ID);
                                    FilesMessageService.Send(folder, _headers, MessageAction.FolderDeleted, folder.Title);
                                }
                                else
                                {
                                    FolderDao.MoveFolder(folder.ID, _trashId, CancellationToken);
                                    FilesMessageService.Send(folder, _headers, MessageAction.FolderMovedToTrash, folder.Title);
                                }

                                ProcessedFolder(folderId);
                            }
                        }
                    }
                }
                ProgressStep(canCalculate);
            }
        }
コード例 #24
0
        private void MoveOrCopyFiles(ICollection fileIds, Folder toFolder, bool copy)
        {
            if (fileIds.Count == 0)
            {
                return;
            }

            var toFolderId = toFolder.ID;

            foreach (var fileId in fileIds)
            {
                CancellationToken.ThrowIfCancellationRequested();

                var file = FileDao.GetFile(fileId);
                if (file == null)
                {
                    Error = FilesCommonResource.ErrorMassage_FileNotFound;
                }
                else if (!FilesSecurity.CanRead(file))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFile;
                }
                else if (file.RootFolderType == FolderType.Privacy &&
                         (copy || toFolder.RootFolderType != FolderType.Privacy))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_MoveFile;
                }
                else if (Global.EnableUploadFilter &&
                         !FileUtility.ExtsUploadable.Contains(FileUtility.GetFileExtension(file.Title)))
                {
                    Error = FilesCommonResource.ErrorMassage_NotSupportedFormat;
                }
                else
                {
                    var parentFolder = FolderDao.GetFolder(file.FolderID);
                    try
                    {
                        var conflict = _resolveType == FileConflictResolveType.Duplicate ||
                                       file.RootFolderType == FolderType.Privacy
                                           ? null
                                           : FileDao.GetFile(toFolderId, file.Title);
                        if (conflict == null)
                        {
                            File newFile = null;
                            if (copy)
                            {
                                try
                                {
                                    newFile = FileDao.CopyFile(file.ID, toFolderId); //Stream copy will occur inside dao
                                    FilesMessageService.Send(newFile, toFolder, _headers, MessageAction.FileCopied, newFile.Title, parentFolder.Title, toFolder.Title);

                                    if (Equals(newFile.FolderID.ToString(), _toFolderId))
                                    {
                                        _needToMark.Add(newFile);
                                    }

                                    if (ProcessedFile(fileId))
                                    {
                                        Status += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR);
                                    }
                                }
                                catch
                                {
                                    if (newFile != null)
                                    {
                                        FileDao.DeleteFile(newFile.ID);
                                    }
                                    throw;
                                }
                            }
                            else
                            {
                                string tmpError;
                                if (WithError(new[] { file }, out tmpError))
                                {
                                    Error = tmpError;
                                }
                                else
                                {
                                    FileMarker.RemoveMarkAsNewForAll(file);

                                    var newFileId = FileDao.MoveFile(file.ID, toFolderId);
                                    newFile = FileDao.GetFile(newFileId);
                                    FilesMessageService.Send(file.RootFolderType != FolderType.USER ? file : newFile, toFolder, _headers, MessageAction.FileMoved, file.Title, parentFolder.Title, toFolder.Title);

                                    if (Equals(toFolderId.ToString(), _toFolderId))
                                    {
                                        _needToMark.Add(newFile);
                                    }

                                    if (ProcessedFile(fileId))
                                    {
                                        Status += string.Format("file_{0}{1}", newFileId, SPLIT_CHAR);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (_resolveType == FileConflictResolveType.Overwrite)
                            {
                                if (!FilesSecurity.CanEdit(conflict))
                                {
                                    Error = FilesCommonResource.ErrorMassage_SecurityException;
                                }
                                else if (EntryManager.FileLockedForMe(conflict.ID))
                                {
                                    Error = FilesCommonResource.ErrorMassage_LockedFile;
                                }
                                else if (FileTracker.IsEditing(conflict.ID))
                                {
                                    Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile;
                                }
                                else
                                {
                                    var newFile = conflict;
                                    newFile.Version++;
                                    newFile.VersionGroup++;
                                    newFile.PureTitle     = file.PureTitle;
                                    newFile.ConvertedType = file.ConvertedType;
                                    newFile.Comment       = FilesCommonResource.CommentOverwrite;
                                    newFile.Encrypted     = file.Encrypted;

                                    using (var stream = FileDao.GetFileStream(file))
                                    {
                                        newFile.ContentLength = stream.CanSeek ? stream.Length : file.ContentLength;

                                        newFile = FileDao.SaveFile(newFile, stream);
                                    }

                                    _needToMark.Add(newFile);

                                    if (copy)
                                    {
                                        FilesMessageService.Send(newFile, toFolder, _headers, MessageAction.FileCopiedWithOverwriting, newFile.Title, parentFolder.Title, toFolder.Title);
                                        if (ProcessedFile(fileId))
                                        {
                                            Status += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR);
                                        }
                                    }
                                    else
                                    {
                                        if (Equals(file.FolderID.ToString(), toFolderId.ToString()))
                                        {
                                            if (ProcessedFile(fileId))
                                            {
                                                Status += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR);
                                            }
                                        }
                                        else
                                        {
                                            string tmpError;
                                            if (WithError(new[] { file }, out tmpError))
                                            {
                                                Error = tmpError;
                                            }
                                            else
                                            {
                                                FileDao.DeleteFile(file.ID);

                                                FilesMessageService.Send(file.RootFolderType != FolderType.USER ? file : newFile, toFolder, _headers, MessageAction.FileMovedWithOverwriting, file.Title, parentFolder.Title, toFolder.Title);

                                                if (ProcessedFile(fileId))
                                                {
                                                    Status += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            else if (_resolveType == FileConflictResolveType.Skip)
                            {
                                //nothing
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Error = ex.Message;
                        Logger.Error(Error, ex);
                    }
                }
                ProgressStep(fileId: FolderDao.CanCalculateSubitems(fileId) ? null : fileId);
            }
        }
コード例 #25
0
        private void MoveOrCopyFiles(ICollection fileIds, Folder toFolder, bool copy)
        {
            if (fileIds.Count == 0)
            {
                return;
            }

            var toFolderId = toFolder.ID;

            foreach (var fileId in fileIds)
            {
                if (Canceled)
                {
                    return;
                }

                var file = FileDao.GetFile(fileId);
                if (file == null)
                {
                    Error = FilesCommonResource.ErrorMassage_FileNotFound;
                }
                else if (!FilesSecurity.CanRead(file))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFile;
                }
                else if (Global.EnableUploadFilter &&
                         !FileUtility.ExtsUploadable.Contains(FileUtility.GetFileExtension(file.Title)))
                {
                    Error = FilesCommonResource.ErrorMassage_NotSupportedFormat;
                }
                else // if (!Equals(file.FolderID.ToString(), toFolderId.ToString()) || _resolveType == FileConflictResolveType.Duplicate)
                {
                    var parentFolder = FolderDao.GetFolder(file.FolderID);
                    try
                    {
                        var conflict = _resolveType == FileConflictResolveType.Duplicate
                                           ? null
                                           : FileDao.GetFile(toFolderId, file.Title);
                        if (conflict != null && !FilesSecurity.CanEdit(conflict))
                        {
                            Error = FilesCommonResource.ErrorMassage_SecurityException;
                        }
                        else if (conflict != null && EntryManager.FileLockedForMe(conflict.ID))
                        {
                            Error = FilesCommonResource.ErrorMassage_LockedFile;
                        }
                        else if (conflict == null)
                        {
                            if (copy)
                            {
                                File newFile = null;
                                try
                                {
                                    newFile = FileDao.CopyFile(file.ID, toFolderId); //Stream copy will occur inside dao
                                    FilesMessageService.Send(file, toFolder, httpRequestHeaders, MessageAction.FileCopied, file.Title, parentFolder.Title, toFolder.Title);

                                    if (Equals(newFile.FolderID.ToString(), _toFolderId))
                                    {
                                        _needToMarkAsNew.Add(newFile);
                                    }

                                    if (ProcessedFile(fileId))
                                    {
                                        Status += string.Format("file_{0}{1}", newFile.ID, SplitCharacter);
                                        ResultedFile(newFile.ID);
                                    }
                                }
                                catch
                                {
                                    if (newFile != null)
                                    {
                                        FileDao.DeleteFile(newFile.ID);
                                    }
                                    throw;
                                }
                            }
                            else
                            {
                                if (EntryManager.FileLockedForMe(file.ID))
                                {
                                    Error = FilesCommonResource.ErrorMassage_LockedFile;
                                }
                                else if (FileTracker.IsEditing(file.ID))
                                {
                                    Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile;
                                }
                                else if (FilesSecurity.CanDelete(file))
                                {
                                    FileMarker.RemoveMarkAsNewForAll(file);

                                    var newFileId = FileDao.MoveFile(file.ID, toFolderId);
                                    FilesMessageService.Send(file, toFolder, httpRequestHeaders, MessageAction.FileMoved, file.Title, parentFolder.Title, toFolder.Title);

                                    if (Equals(toFolderId.ToString(), _toFolderId))
                                    {
                                        _needToMarkAsNew.Add(FileDao.GetFile(newFileId));
                                    }

                                    if (ProcessedFile(fileId))
                                    {
                                        Status += string.Format("file_{0}{1}", newFileId, SplitCharacter);
                                        ResultedFile(newFileId);
                                    }
                                }
                                else
                                {
                                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile;
                                }
                            }
                        }
                        else
                        {
                            if (_resolveType == FileConflictResolveType.Overwrite)
                            {
                                if (EntryManager.FileLockedForMe(conflict.ID))
                                {
                                    Error = FilesCommonResource.ErrorMassage_LockedFile;
                                }
                                else if (FileTracker.IsEditing(conflict.ID))
                                {
                                    Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile;
                                }
                                else
                                {
                                    conflict.Version++;
                                    using (var stream = FileDao.GetFileStream(file))
                                    {
                                        conflict.ContentLength = stream.Length;
                                        conflict.Comment       = string.Empty;
                                        conflict = FileDao.SaveFile(conflict, stream);

                                        _needToMarkAsNew.Add(conflict);
                                    }

                                    if (copy)
                                    {
                                        FilesMessageService.Send(file, toFolder, httpRequestHeaders, MessageAction.FileCopiedWithOverwriting, file.Title, parentFolder.Title, toFolder.Title);
                                        if (ProcessedFile(fileId))
                                        {
                                            Status += string.Format("file_{0}{1}", conflict.ID, SplitCharacter);
                                            ResultedFile(conflict.ID);
                                        }
                                    }
                                    else
                                    {
                                        if (Equals(file.FolderID.ToString(), toFolderId.ToString()))
                                        {
                                            if (ProcessedFile(fileId))
                                            {
                                                Status += string.Format("file_{0}{1}", conflict.ID, SplitCharacter);
                                                ResultedFile(conflict.ID);
                                            }
                                        }
                                        else
                                        {
                                            if (EntryManager.FileLockedForMe(file.ID))
                                            {
                                                Error = FilesCommonResource.ErrorMassage_LockedFile;
                                            }
                                            else if (FileTracker.IsEditing(file.ID))
                                            {
                                                Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile;
                                            }
                                            else if (FilesSecurity.CanDelete(file))
                                            {
                                                FileDao.DeleteFile(file.ID);
                                                FileDao.DeleteFolder(file.ID);

                                                FilesMessageService.Send(file, toFolder, httpRequestHeaders, MessageAction.FileMovedWithOverwriting, file.Title, parentFolder.Title, toFolder.Title);

                                                if (ProcessedFile(fileId))
                                                {
                                                    Status += string.Format("file_{0}{1}", conflict.ID, SplitCharacter);
                                                    ResultedFile(conflict.ID);
                                                }
                                            }
                                            else
                                            {
                                                Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile;
                                            }
                                        }
                                    }
                                }
                            }
                            else if (_resolveType == FileConflictResolveType.Skip)
                            {
                                //nothing
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Error = ex.Message;
                        Logger.Error(Error, ex);
                    }
                }
                ProgressStep();
            }
        }
コード例 #26
0
        private void DeleteFolders(List <object> folderIds)
        {
            if (folderIds.Count == 0)
            {
                return;
            }

            foreach (var folderId in folderIds)
            {
                if (Canceled)
                {
                    return;
                }

                var folder = FolderDao.GetFolder(folderId);
                if (folder == null)
                {
                    Error = FilesCommonResource.ErrorMassage_FolderNotFound;
                }
                else if (!ignoreException && !FilesSecurity.CanDelete(folder))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder;
                }
                else
                {
                    FileMarker.RemoveMarkAsNewForAll(folder);
                    if (FolderDao.UseTrashForRemove(folder))
                    {
                        var files = FolderDao.GetFiles(folder.ID, true);
                        if (!ignoreException && files.Exists(fid => ((new File {
                            ID = fid, FileStatus = FileStatus.None
                        }).FileStatus & FileStatus.IsEditing) == FileStatus.IsEditing))
                        {
                            Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFolder;
                        }
                        else
                        {
                            FolderDao.MoveFolder(folder.ID, _trashId);
                            ProcessedFolder(folderId);
                        }
                    }
                    else
                    {
                        if (FolderDao.UseRecursiveOperation(folder.ID, null))
                        {
                            DeleteFiles(FolderDao.GetFiles(folder.ID, false));
                            DeleteFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList());

                            if (FolderDao.GetItemsCount(folder.ID, true) == 0)
                            {
                                FolderDao.DeleteFolder(folder.ID);
                                ProcessedFolder(folderId);
                            }
                        }
                        else
                        {
                            if (folder.ProviderEntry && folder.ID.Equals(folder.RootFolderId))
                            {
                                ProviderDao.RemoveProviderInfo(folder.ProviderId);
                            }
                            else
                            {
                                FolderDao.DeleteFolder(folder.ID);
                            }

                            ProcessedFolder(folderId);
                        }
                    }
                }
                ProgressStep();
            }
        }
コード例 #27
0
        private void MoveOrCopyFiles(ICollection fileIds, Folder toFolder, bool copy)
        {
            if (fileIds.Count == 0)
            {
                return;
            }

            var toFolderId = toFolder.ID;

            foreach (var fileId in fileIds)
            {
                CancellationToken.ThrowIfCancellationRequested();

                var file = FileDao.GetFile(fileId);
                if (file == null)
                {
                    Error = FilesCommonResource.ErrorMassage_FileNotFound;
                }
                else if (!FilesSecurity.CanRead(file))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFile;
                }
                else if (Global.EnableUploadFilter &&
                         !FileUtility.ExtsUploadable.Contains(FileUtility.GetFileExtension(file.Title)))
                {
                    Error = FilesCommonResource.ErrorMassage_NotSupportedFormat;
                }
                else if (file.ContentLength > SetupInfo.AvailableFileSize &&
                         file.ProviderId != toFolder.ProviderId)
                {
                    Error = string.Format(copy ? FilesCommonResource.ErrorMassage_FileSizeCopy : FilesCommonResource.ErrorMassage_FileSizeMove,
                                          FileSizeComment.FilesSizeToString(SetupInfo.AvailableFileSize));
                }
                else
                {
                    var parentFolder = FolderDao.GetFolder(file.FolderID);
                    try
                    {
                        var conflict = resolveType == FileConflictResolveType.Duplicate
                                           ? null
                                           : FileDao.GetFile(toFolderId, file.Title);
                        if (conflict != null && !FilesSecurity.CanEdit(conflict))
                        {
                            Error = FilesCommonResource.ErrorMassage_SecurityException;
                        }
                        else if (conflict != null && EntryManager.FileLockedForMe(conflict.ID))
                        {
                            Error = FilesCommonResource.ErrorMassage_LockedFile;
                        }
                        else if (conflict == null)
                        {
                            if (copy)
                            {
                                File newFile = null;
                                try
                                {
                                    newFile = FileDao.CopyFile(file.ID, toFolderId); //Stream copy will occur inside dao
                                    FilesMessageService.Send(file, toFolder, headers, MessageAction.FileCopied, file.Title, parentFolder.Title, toFolder.Title);

                                    if (Equals(newFile.FolderID.ToString(), this.toFolderId))
                                    {
                                        needToMark.Add(newFile);
                                    }

                                    if (ProcessedFile(fileId))
                                    {
                                        Status += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR);
                                    }
                                }
                                catch
                                {
                                    if (newFile != null)
                                    {
                                        FileDao.DeleteFile(newFile.ID);
                                    }
                                    throw;
                                }
                            }
                            else
                            {
                                if (EntryManager.FileLockedForMe(file.ID))
                                {
                                    Error = FilesCommonResource.ErrorMassage_LockedFile;
                                }
                                else if (FileTracker.IsEditing(file.ID))
                                {
                                    Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile;
                                }
                                else if (FilesSecurity.CanDelete(file))
                                {
                                    FileMarker.RemoveMarkAsNewForAll(file);

                                    var newFileId = FileDao.MoveFile(file.ID, toFolderId);
                                    FilesMessageService.Send(file, toFolder, headers, MessageAction.FileMoved, file.Title, parentFolder.Title, toFolder.Title);

                                    if (Equals(toFolderId.ToString(), this.toFolderId))
                                    {
                                        needToMark.Add(FileDao.GetFile(newFileId));
                                    }

                                    if (ProcessedFile(fileId))
                                    {
                                        Status += string.Format("file_{0}{1}", newFileId, SPLIT_CHAR);
                                    }
                                }
                                else
                                {
                                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile;
                                }
                            }
                        }
                        else
                        {
                            if (resolveType == FileConflictResolveType.Overwrite)
                            {
                                if (EntryManager.FileLockedForMe(conflict.ID))
                                {
                                    Error = FilesCommonResource.ErrorMassage_LockedFile;
                                }
                                else if (FileTracker.IsEditing(conflict.ID))
                                {
                                    Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile;
                                }
                                else
                                {
                                    var newFile = conflict;
                                    newFile.Version++;
                                    newFile.ContentLength = conflict.ContentLength;

                                    using (var stream = FileDao.GetFileStream(file))
                                    {
                                        newFile = FileDao.SaveFile(newFile, stream);
                                    }

                                    needToMark.Add(newFile);

                                    if (copy)
                                    {
                                        FilesMessageService.Send(file, toFolder, headers, MessageAction.FileCopiedWithOverwriting, file.Title, parentFolder.Title, toFolder.Title);
                                        if (ProcessedFile(fileId))
                                        {
                                            Status += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR);
                                        }
                                    }
                                    else
                                    {
                                        if (Equals(file.FolderID.ToString(), toFolderId.ToString()))
                                        {
                                            if (ProcessedFile(fileId))
                                            {
                                                Status += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR);
                                            }
                                        }
                                        else
                                        {
                                            if (EntryManager.FileLockedForMe(file.ID))
                                            {
                                                Error = FilesCommonResource.ErrorMassage_LockedFile;
                                            }
                                            else if (FileTracker.IsEditing(file.ID))
                                            {
                                                Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile;
                                            }
                                            else if (FilesSecurity.CanDelete(file))
                                            {
                                                FileDao.DeleteFile(file.ID);
                                                FileDao.DeleteFolder(file.ID);

                                                FilesMessageService.Send(file, toFolder, headers, MessageAction.FileMovedWithOverwriting, file.Title, parentFolder.Title, toFolder.Title);

                                                if (ProcessedFile(fileId))
                                                {
                                                    Status += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR);
                                                }
                                            }
                                            else
                                            {
                                                Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile;
                                            }
                                        }
                                    }
                                }
                            }
                            else if (resolveType == FileConflictResolveType.Skip)
                            {
                                //nothing
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Error = ex.Message;
                        Logger.Error(Error, ex);
                    }
                }
                ProgressStep(fileId: FolderDao.CanCalculateSubitems(fileId) ? null : fileId);
            }
        }
コード例 #28
0
        private void MoveOrCopyFolders(ICollection folderIds, Folder toFolder, bool copy)
        {
            if (folderIds.Count == 0)
            {
                return;
            }

            var toFolderId = toFolder.ID;
            var isToFolder = Equals(toFolderId.ToString(), _toFolderId);

            foreach (var folderId in folderIds)
            {
                if (Canceled)
                {
                    return;
                }

                var folder = FolderDao.GetFolder(folderId);
                if (folder == null)
                {
                    Error = FilesCommonResource.ErrorMassage_FolderNotFound;
                }
                else if (!FilesSecurity.CanRead(folder))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFolder;
                }
                else if (!Equals((folder.ParentFolderID ?? string.Empty).ToString(), toFolderId.ToString()))
                {
                    try
                    {
                        //if destination folder contains folder with same name then merge folders
                        var conflictFolder = FolderDao.GetFolder(folder.Title, toFolderId);

                        if (copy || conflictFolder != null)
                        {
                            Folder newFolder;
                            if (conflictFolder != null)
                            {
                                newFolder = conflictFolder;

                                if (isToFolder)
                                {
                                    _needToMarkAsNew.Add(conflictFolder);
                                }
                            }
                            else
                            {
                                newFolder = FolderDao.CopyFolder(folder.ID, toFolderId);

                                if (isToFolder)
                                {
                                    _needToMarkAsNew.Add(newFolder);
                                }

                                ProcessedFolder(folderId);
                            }

                            if (FolderDao.UseRecursiveOperation(folder.ID, toFolderId))
                            {
                                MoveOrCopyFiles(FolderDao.GetFiles(folder.ID, false), newFolder, copy, _resolveType);
                                MoveOrCopyFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList(), newFolder, copy);

                                if (!copy)
                                {
                                    if (FolderDao.GetItemsCount(folder.ID, true) == 0 && FilesSecurity.CanDelete(folder))
                                    {
                                        FolderDao.DeleteFolder(folder.ID);
                                        ProcessedFolder(folderId);
                                    }
                                }
                            }
                            else
                            {
                                if (conflictFolder != null)
                                {
                                    if (copy)
                                    {
                                        newFolder = FolderDao.CopyFolder(folder.ID, toFolderId);

                                        if (isToFolder)
                                        {
                                            _needToMarkAsNew.Add(newFolder);
                                        }
                                    }
                                    else
                                    {
                                        FolderDao.MoveFolder(folder.ID, toFolderId);

                                        if (isToFolder)
                                        {
                                            _needToMarkAsNew.Add(FolderDao.GetFolder(folder.ID));
                                        }
                                    }

                                    ProcessedFolder(folderId);
                                }
                            }
                        }
                        else
                        {
                            if (FilesSecurity.CanDelete(folder))
                            {
                                FileMarker.RemoveMarkAsNewForAll(folder);

                                FolderDao.MoveFolder(folder.ID, toFolderId);

                                if (isToFolder)
                                {
                                    _needToMarkAsNew.Add(FolderDao.GetFolder(folder.ID));
                                }

                                ProcessedFolder(folderId);
                            }
                            else
                            {
                                Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Error = ex.Message;

                        Logger.Error(Error, ex);
                    }
                }
                ProgressStep();
            }
        }
コード例 #29
0
        private void DeleteFolders(List <object> folderIds)
        {
            if (folderIds.Count == 0)
            {
                return;
            }

            foreach (var folderId in folderIds)
            {
                if (Canceled)
                {
                    return;
                }

                var folder = FolderDao.GetFolder(folderId);
                if (folder == null)
                {
                    Error = FilesCommonResource.ErrorMassage_FolderNotFound;
                }
                else if (!FilesSecurity.CanDelete(folder))
                {
                    Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder;
                }
                else
                {
                    if (FolderDao.UseTrashForRemove(folder))
                    {
                        var files = FolderDao.GetFiles(folder.ID, true);
                        if (files.Exists(fid => (File.GetFileStatus(fid, FileStatus.None) & FileStatus.IsEditing) == FileStatus.IsEditing))
                        {
                            Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFolder;
                        }
                        else
                        {
                            FolderDao.MoveFolder(folder.ID, _trashId);
                            files.ForEach(fid => NoticeDelete(FileDao.GetFile(fid)));
                            ProcessedFolder(folderId);
                            TagDao.RemoveTags(TagDao.GetTags(folder.ID, FileEntryType.Folder, TagType.New).ToArray());
                        }
                    }
                    else
                    {
                        if (FolderDao.UseRecursiveOperation(folder.ID, null))
                        {
                            DeleteFiles(FolderDao.GetFiles(folder.ID, false));
                            DeleteFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList());

                            if (FolderDao.GetItemsCount(folder.ID, true) == 0)
                            {
                                FolderDao.DeleteFolder(folder.ID);
                                ProcessedFolder(folderId);
                            }
                            else
                            {
                                Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFolder;
                            }
                        }
                        else
                        {
                            FolderDao.DeleteFolder(folder.ID);
                            ProcessedFolder(folderId);
                        }
                    }
                }
                ProgressStep();
            }
        }
コード例 #30
0
        protected override void Do()
        {
            if (_files.Count == 0)
            {
                return;
            }

            var parent = FolderDao.GetFolder(_parentId);

            if (parent == null)
            {
                throw new Exception(FilesCommonResource.ErrorMassage_FolderNotFound);
            }
            if (!FilesSecurity.CanCreate(parent))
            {
                throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create);
            }
            if (parent.RootFolderType == FolderType.TRASH)
            {
                throw new Exception(FilesCommonResource.ErrorMassage_ImportToTrash);
            }
            if (!string.IsNullOrEmpty(parent.ProviderName))
            {
                throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create);
            }

            var to = FolderDao.GetFolder(_folderName, _parentId);

            if (to == null)
            {
                to = new Folder
                {
                    FolderType     = FolderType.DEFAULT,
                    ParentFolderID = _parentId,
                    Title          = _folderName
                };
                to.ID = FolderDao.SaveFolder(to);
            }

            foreach (var f in _files)
            {
                if (Canceled)
                {
                    return;
                }
                try
                {
                    long size;
                    using (var stream = _docProvider.GetDocumentStream(f.ContentLink, out size))
                    {
                        if (stream == null)
                        {
                            throw new Exception("Can not import document " + f.ContentLink + ". Empty stream.");
                        }

                        if (SetupInfo.MaxUploadSize < size)
                        {
                            throw FileSizeComment.FileSizeException;
                        }

                        var folderId = to.ID;
                        var pos      = f.Title.LastIndexOf('/');
                        if (0 < pos)
                        {
                            folderId = GetOrCreateHierarchy(f.Title.Substring(0, pos), to);
                            f.Title  = f.Title.Substring(pos + 1);
                        }

                        f.Title = Global.ReplaceInvalidCharsAndTruncate(f.Title);
                        var file = new File
                        {
                            Title         = f.Title,
                            FolderID      = folderId,
                            ContentLength = size,
                            ContentType   = "application/octet-stream",
                        };

                        var conflict = FileDao.GetFile(file.FolderID, file.Title);
                        if (conflict != null)
                        {
                            if (_overwrite)
                            {
                                file.ID      = conflict.ID;
                                file.Version = conflict.Version + 1;
                            }
                            else
                            {
                                continue;
                            }
                        }

                        if (size <= 0L)
                        {
                            using (var buffered = stream.GetBuffered())
                            {
                                size = buffered.Length;

                                if (SetupInfo.MaxUploadSize < size)
                                {
                                    throw FileSizeComment.FileSizeException;
                                }

                                file.ContentLength = size;
                                try
                                {
                                    file = FileDao.SaveFile(file, buffered);
                                }
                                catch (Exception error)
                                {
                                    FileDao.DeleteFile(file.ID);
                                    throw error;
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                file = FileDao.SaveFile(file, stream);
                            }
                            catch (Exception error)
                            {
                                FileDao.DeleteFile(file.ID);
                                throw error;
                            }
                        }

                        if (conflict != null)
                        {
                            Global.PublishUpdateDocument(file.ID);
                        }
                        else
                        {
                            FilesActivityPublisher.UploadFile(FileDao.GetFile(file.ID));
                        }
                    }
                }
                catch (Exception error)
                {
                    Error = error;
                }
                finally
                {
                    ProgressStep();
                }
            }
        }