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(); }
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); }
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(); }
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(); }
FileItem GetFileItem(FileItemPathInfo pathInfo) { return(FileManagementDbContext.FileItems.FirstOrDefault(i => i.Id == pathInfo.GetFileItemKey <int>())); }