Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
        public void CreateDirectory(string rootKey, string name)
        {
            CheckThatDirOrFileNameIsNotEmpty(name, "name");
            ValidateFileItemNameSymbols(name);
            string path = Path.Combine(GetFullDirPathWithCheckOnExistence(rootKey), name);

            if (FileSystemService.DirectoryExists(path))
            {
                FileManagementExceptionExecutor.ThrowDirectoryExists(Path.Combine(PreparePath(rootKey), name));
            }
            FileSystemService.CreateDirectory(path);
        }
Exemplo n.º 3
0
        public void Rename(FileItemPathInfo pathInfo, string newName)
        {
            if (!IsFileItemExists(pathInfo))
            {
                FileManagementExceptionExecutor.ThrowDirectoryExists(pathInfo.GetPath());
            }

            var fileItem = GetFileItem(pathInfo);

            fileItem.Name         = newName;
            fileItem.ModifiedById = GuestPersonId;
            fileItem.Modified     = DateTime.Now;
            FileManagementDbContext.SaveChanges();
        }
Exemplo n.º 4
0
        public void Remove(FileItemPathInfo pathInfo)
        {
            if (!IsFileItemExists(pathInfo))
            {
                FileManagementExceptionExecutor.ThrowDirectoryExists(pathInfo.GetPath());
            }

            var fileItem = GetFileItem(pathInfo);

            FileManagementDbContext.FileItems.Remove(fileItem);

            if (fileItem.IsDirectory)
            {
                RemoveDirectoryContentRecursive(fileItem.Id);
            }

            FileManagementDbContext.SaveChanges();
        }
Exemplo n.º 5
0
        public void CreateDirectory(FileItemPathInfo pathInfo, string name)
        {
            if (!IsFileItemExists(pathInfo))
            {
                FileManagementExceptionExecutor.ThrowDirectoryExists(pathInfo.GetPath());
            }

            var directory = new FileItem {
                Name         = name,
                Modified     = DateTime.Now,
                Created      = DateTime.Now,
                IsDirectory  = true,
                ParentId     = pathInfo.GetFileItemKey <int>(),
                ModifiedById = GuestPersonId
            };

            FileManagementDbContext.FileItems.Add(directory);
            FileManagementDbContext.SaveChanges();
        }
Exemplo n.º 6
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();
        }