private MoveOperation InitiateCopy(IFileInfo source, string destination) { MoveOperation copy = _helper.Move(source, destination, true); _copies.TryAdd(copy.Id, copy); var continuation = copy.Task.ContinueWith(t => _copies.TryRemove(copy.Id, out copy)); return(copy); }
private MoveOperation MoveFile(IFileInfo source, IFileInfo destination, bool copy) { string temp = PathUtil.GetTempFilePath(destination.Path); var op = new MoveOperation(source, destination, temp, _fileService); op.Task = SafeMoveFile(source, destination, temp, copy); return(op); }
private MoveOperation InitiateMove(IFileInfo source, string destination) { MoveOperation move = _helper.Move(source, destination, false); _moves.TryAdd(move.Id, move); var continuation = move.Task.ContinueWith(t => _moves.TryRemove(move.Id, out move)); return(move); }
public object Get(string id) { MoveOperation copy = null; if (!_copies.TryGetValue(id, out copy)) { return(NotFound()); } return(_helper.ToJsonModel(copy)); }
public object Get(string id) { MoveOperation move = null; if (!_moves.TryGetValue(id, out move)) { return(NotFound()); } return(_helper.ToJsonModel(move)); }
public object ToJsonModel(MoveOperation move) { dynamic obj = new ExpandoObject(); obj.id = move.Id; obj.status = "running"; obj.created = move.Created; obj.current_size = move.CurrentSize; obj.total_size = move.TotalSize; obj.file = _filesHelper.ToJsonModelRef(move.Destination); return(Core.Environment.Hal.Apply(Defines.CopyResource.Guid, obj)); }
private MoveOperation MoveDirectory(IFileInfo source, IFileInfo destination, bool copy) { var op = new MoveOperation(source, destination, null, _fileService); if (copy) { op.Task = CopyDirectory(source, destination, (s, d) => SafeMoveFile(s, d, PathUtil.GetTempFilePath(d.Path), true).ContinueWith(t2 => { if (op != null) { op.CurrentSize += _fileService.GetFile(d.Path).Size; } })); } else { op.Task = Task.Run(() => _fileService.Move(source, destination)); } return(op); }
public object Post([FromBody] dynamic model) { string name; FileType fileType; FileId fileId, parentId; _helper.EnsurePostModelValid(model, out name, out fileId, out parentId); try { fileType = FilesHelper.GetFileType(fileId.PhysicalPath); } catch (FileNotFoundException) { throw new NotFoundException("file"); } if (!_fileService.DirectoryExists(parentId.PhysicalPath)) { throw new NotFoundException("parent"); } var src = fileType == FileType.File ? _fileService.GetFile(fileId.PhysicalPath) : _fileService.GetDirectory(fileId.PhysicalPath); string destPath = Path.Combine(parentId.PhysicalPath, name == null ? src.Name : name); if (PathUtil.IsAncestor(src.Path, destPath) || src.Path.Equals(destPath, StringComparison.OrdinalIgnoreCase)) { throw new ApiArgumentException("parent", "The destination folder is a subfolder of the source"); } if (fileType == FileType.File && _fileService.DirectoryExists(destPath) || fileType == FileType.Directory && _fileService.FileExists(destPath)) { throw new AlreadyExistsException("name"); } MoveOperation copy = InitiateCopy(src, destPath); Context.Response.StatusCode = (int)HttpStatusCode.Accepted; Context.Response.Headers.Add("Location", MoveHelper.GetLocation(copy.Id, true)); return(_helper.ToJsonModel(copy)); }
private MoveOperation MoveDirectory(IFileInfo source, string dest, bool copy) { Task t; MoveOperation op = null; if (copy) { t = CopyDirectory(source.Path, dest, (s, d) => SafeMoveFile(s, d, PathUtil.GetTempFilePath(d), true).ContinueWith(t2 => { if (op != null) { op.CurrentSize += _fileService.GetFile(d).Size; } })); } else { t = Task.Run(() => _fileService.Move(source.Path, dest)); } op = new MoveOperation(t, source, dest, null, _fileService); return(op); }
public object Post([FromBody] dynamic model) { string name; IFileInfo src; FileId fileId, parentId; _helper.EnsurePostModelValid(model, out name, out fileId, out parentId); src = new FilesHelper(_fileService).GetExistingFileInfo(fileId.PhysicalPath); if (src == null) { throw new NotFoundException("file"); } if (!_fileService.GetDirectory(parentId.PhysicalPath).Exists) { throw new NotFoundException("parent"); } string destPath = Path.Combine(parentId.PhysicalPath, name == null ? src.Name : name); if (PathUtil.IsAncestor(src.Path, destPath) || src.Path.Equals(destPath, StringComparison.OrdinalIgnoreCase)) { throw new ApiArgumentException("parent", "The destination folder is a subfolder of the source"); } if (src.Type == FileType.File && _fileService.GetDirectory(destPath).Exists || src.Type == FileType.Directory && _fileService.GetFile(destPath).Exists) { throw new AlreadyExistsException("name"); } MoveOperation move = InitiateMove(src, destPath); Context.Response.StatusCode = (int)HttpStatusCode.Accepted; Context.Response.Headers.Add("Location", MoveHelper.GetLocation(move.Id, false)); return(_helper.ToJsonModel(move)); }