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 IList <IClientFileSystemItem> GetDirectoryContents(FileItemPathInfo pathInfo)
        {
            var fileItems             = GetDirectoryContents(pathInfo.GetFileItemKey <int>());
            var hasSubDirectoriesInfo = GetHasSubDirectoriesInfo(fileItems);

            var clientItemList = new List <IClientFileSystemItem>();

            foreach (var item in fileItems)
            {
                var clientItem = new ClientFileSystemItem {
                    Key          = item.Id,
                    Name         = item.Name,
                    IsDirectory  = item.IsDirectory,
                    DateModified = item.Modified
                };

                if (item.IsDirectory)
                {
                    clientItem.HasSubDirectories = hasSubDirectoriesInfo.ContainsKey(item.Id) && hasSubDirectoriesInfo[item.Id];
                }

                clientItem.CustomFields["modifiedBy"] = item.ModifiedBy.FullName;
                clientItem.CustomFields["created"]    = item.Created;
                clientItemList.Add(clientItem);
            }
            return(clientItemList);
        }
Exemplo n.º 3
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.º 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();
        }
Exemplo n.º 5
0
 FileItem GetFileItem(FileItemPathInfo pathInfo)
 {
     return(FileManagementDbContext.FileItems.FirstOrDefault(i => i.Id == pathInfo.GetFileItemKey <int>()));
 }