コード例 #1
0
        private static string PreparePath(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(string.Empty);
            }
            List <string> list = path.Split(PossibleDirectorySeparators, StringSplitOptions.RemoveEmptyEntries).ToList();
            int           num  = 0;

            while (num < list.Count)
            {
                if (list[num] == ".." && num > 0)
                {
                    list.RemoveAt(num);
                    list.RemoveAt(num - 1);
                    num--;
                }
                else
                {
                    num++;
                }
            }
            if (list.Any() && list[0] == "..")
            {
                FileManagementExceptionExecutor.ThrowNoAccess();
            }
            return(Path.Combine(list.ToArray()));
        }
コード例 #2
0
        public void Copy(FileItemPathInfo sourcePathInfo, FileItemPathInfo destinationPathInfo)
        {
            if (!IsFileItemExists(sourcePathInfo))
            {
                FileManagementExceptionExecutor.ThrowDirectoryExists(sourcePathInfo.GetPath());
            }
            if (!IsFileItemExists(destinationPathInfo))
            {
                FileManagementExceptionExecutor.ThrowDirectoryExists(sourcePathInfo.GetPath());
            }
            if (!AllowCopyOrMove(sourcePathInfo, destinationPathInfo))
            {
                FileManagementExceptionExecutor.ThrowNoAccess();
            }

            var sourceFileItem = GetFileItem(sourcePathInfo);
            var copyFileItem   = CreateCopy(sourceFileItem);

            copyFileItem.ParentId = destinationPathInfo.GetFileItemKey <int>();
            copyFileItem.Name     = GenerateCopiedFileItemName(destinationPathInfo.GetFileItemKey <int>(), copyFileItem.Name, copyFileItem.IsDirectory);
            FileManagementDbContext.FileItems.Add(copyFileItem);

            if (copyFileItem.IsDirectory)
            {
                CopyDirectoryContentRecursive(sourceFileItem, copyFileItem);
            }
            FileManagementDbContext.SaveChanges();
        }
コード例 #3
0
        public void Rename(string key, string newName)
        {
            CheckThatDirOrFileNameIsNotEmpty(key, "key");
            CheckThatDirOrFileNameIsNotEmpty(newName, "newName");
            ValidateFileItemNameSymbols(newName);
            string text = Path.Combine(RootDirectoryPath, PreparePath(key));
            string path = Path.GetDirectoryName(text) ?? string.Empty;

            if (FileSystemService.DirectoryExists(text))
            {
                if (string.Equals(Path.GetFullPath(RootDirectoryPath), Path.GetFullPath(text), StringComparison.OrdinalIgnoreCase))
                {
                    FileManagementExceptionExecutor.ThrowNoAccess();
                }
                string destDirName = Path.Combine(path, newName);
                FileSystemService.MoveDirectory(text, destDirName);
            }
            else if (FileSystemService.FileExists(text))
            {
                string extension = Path.GetExtension(text);
                if (!newName.Contains("."))
                {
                    newName += extension;
                }
                string destFileName = Path.Combine(path, newName);
                FileSystemService.MoveFile(text, destFileName);
            }
            else
            {
                FileManagementExceptionExecutor.ThrowFileNotFound(text);
            }
        }
コード例 #4
0
        public void Move(FileItemPathInfo pathInfo, FileItemPathInfo destinationPathInfo)
        {
            if (!IsFileItemExists(pathInfo))
            {
                FileManagementExceptionExecutor.ThrowDirectoryExists(pathInfo.GetPath());
            }
            if (!IsFileItemExists(destinationPathInfo))
            {
                FileManagementExceptionExecutor.ThrowDirectoryExists(pathInfo.GetPath());
            }
            if (!AllowCopyOrMove(pathInfo, destinationPathInfo))
            {
                FileManagementExceptionExecutor.ThrowNoAccess();
            }

            var fileItem = GetFileItem(pathInfo);

            fileItem.ParentId     = destinationPathInfo.GetFileItemKey <int>();
            fileItem.Modified     = DateTime.Now;
            fileItem.ModifiedById = GuestPersonId;
            FileManagementDbContext.SaveChanges();
        }
コード例 #5
0
        private object ExecuteUnsafe(FileSystemCommand command, IDictionary <string, object> arguments)
        {
            switch (command)
            {
            case FileSystemCommand.GetDirContents:
                return(ExecuteGetDirContentCommand(arguments));

            case FileSystemCommand.CreateDir:
                if (!FileSystemConfiguration.AllowCreate)
                {
                    FileManagementExceptionExecutor.ThrowNoAccess();
                }
                return(ExecuteCreateDirCommand(arguments));

            case FileSystemCommand.Rename:
                if (!FileSystemConfiguration.AllowRename)
                {
                    FileManagementExceptionExecutor.ThrowNoAccess();
                }
                return(ExecuteRenameCommand(arguments));

            case FileSystemCommand.Move:
                if (!FileSystemConfiguration.AllowMove)
                {
                    FileManagementExceptionExecutor.ThrowNoAccess();
                }
                return(ExecuteMoveCommand(arguments));

            case FileSystemCommand.Copy:
                if (!FileSystemConfiguration.AllowCopy)
                {
                    FileManagementExceptionExecutor.ThrowNoAccess();
                }
                return(ExecuteCopyCommand(arguments));

            case FileSystemCommand.Remove:
                if (!FileSystemConfiguration.AllowRemove)
                {
                    FileManagementExceptionExecutor.ThrowNoAccess();
                }
                return(ExecuteRemoveCommand(arguments));

            case FileSystemCommand.UploadChunk:
                if (!FileSystemConfiguration.AllowUpload)
                {
                    FileManagementExceptionExecutor.ThrowNoAccess();
                }
                return(ExecuteUploadChunkCommand(arguments));

            case FileSystemCommand.AbortUpload:
                if (!FileSystemConfiguration.AllowUpload)
                {
                    FileManagementExceptionExecutor.ThrowNoAccess();
                }
                return(ExecuteAbortUploadCommand(arguments));

            case FileSystemCommand.Download:
                if (!FileSystemConfiguration.AllowDownload)
                {
                    FileManagementExceptionExecutor.ThrowNoAccess();
                }
                return(ExecuteDownloadCommand(arguments));

            default:
                throw new NotSupportedException();
            }
        }