public void AddFile(FileInfoDto dto) { var user = UserActionControl(dto.UserId); var directory = _context.WorkingDirs.FirstOrDefault(e=> e.Id==dto.ProjectId); if (directory == null) { throw new Exception("File"); } var dirPath = Path.GetDirectoryName(directory.Path+dto.Path); if (dirPath == null) { throw new DataExceptions("not dir"); } if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } using (var t = System.IO.File.Create(directory.Path + dto.Path)) { } var nf = new File(); nf.Name = dto.Path; nf.WorkingDir = directory; nf.Id = dto.Id; _fileProvider.Create(nf); }
public ServerResponseDto CreateFile(FileInfoDto file) { try { _service.AddFile(file); } catch (Exception e) { return new ServerResponseDto() { Message = "error", ResponseType = ServerResponseType.Error }; } return new ServerResponseDto() { Message = "Ok", ResponseType = ServerResponseType.Ok }; }
public ServerResponseDto RemoveFile(FileInfoDto info) { try { _service.DeleteFile(info); } catch (Exception e) { return new ServerResponseDto() { Message = "error", ResponseType = ServerResponseType.Error }; } return new ServerResponseDto() { Message = "Ok", ResponseType = ServerResponseType.Ok }; }
public ServerResponseDto RenameFile(FileInfoDto info) { try { _service.RenameFile(info); return new ServerResponseDto { Message = "Ok", ResponseType = ServerResponseType.Ok }; } catch (Exception e) { return new ServerResponseDto { Message = "Error", ResponseType = ServerResponseType.Error }; } }
public void DeleteFile(FileInfoDto dto) { var user = UserActionControl(dto.UserId); var directory = _context.WorkingDirs.FirstOrDefault(e => e.Id == dto.ProjectId && e.Owner.Id == user.Id); if (directory == null) { throw new ArgumentException("Delete.WorkDirs"); } var file = _context.Files.FirstOrDefault(e => e.WorkingDirId == dto.ProjectId && e.Id == dto.Id); if (file == null) { throw new ArgumentException("Delete.File"); } var path = directory.Path + file.Name; _fileProvider.Delete(file); try { System.IO.File.Delete(path); } catch (Exception e) { Console.WriteLine(e); throw; } }
public void RenameFile(FileInfoDto dto) { var user = UserActionControl(dto.UserId); var directory = _context.WorkingDirs.FirstOrDefault(e => e.Id == dto.ProjectId); if (directory == null) { throw new Exception("File"); } var file = _context.Files.FirstOrDefault(e => e.Id == dto.Id && e.WorkingDirId == dto.ProjectId); if (file == null) { throw new Exception("file"); } var oldPath = directory.Path + file.Name; System.IO.File.Copy(oldPath,directory.Path+dto.Path); System.IO.File.Delete(oldPath); file.Name = dto.Path; _fileProvider.Update(file); }