public Stream Download(FapFileInfo fileInfo) { string fileRepositoryPath = GetFilePath(); string fileName = Path.Combine(fileRepositoryPath, fileInfo.FilePath); if (!System.IO.File.Exists(fileName)) { return(null); } Stream outStream = null; try { outStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); } catch (Exception ex) { _logger.LogError(ex.Message); throw new FapException(ex.Message, ex); } //Stream outStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); //FapFileInfo fileInfo = new FapFileInfo(); //fileInfo.FileStream = outStream; //return fileInfo; return(outStream); }
public bool Upload(Stream stream, FapFileInfo fileInfo, FileUploadEventHandler updateEvent) { string fileRepositoryPath = GetFilePath(); if (fileInfo == null || stream == null) { return(false); } //文件存储策略 FileDirectoryStrategy strategy = new FileDirectoryStrategy(); string lv = _configService.GetSysParamValue("file.directory.level"); if (lv.IsPresent()) { strategy.Level = lv.ToInt(); } else { strategy.Level = 3; } string fileName = ""; string directoryPath = strategy.GetFullPath("" + fileInfo.FileId, out fileName); string fullpathToSave = Path.Combine(fileRepositoryPath, directoryPath); try { if (!Directory.Exists(fullpathToSave)) { Directory.CreateDirectory(fullpathToSave); } string fileToSave = Path.Combine(fullpathToSave, fileName + fileInfo.FileSuffix); using (var outStream = new FileStream(fileToSave, FileMode.Create, FileAccess.Write)) { using (stream) { stream.CopyTo(outStream); if (updateEvent != null) { updateEvent(fileInfo, new FileUploadEventArgs() { Total = stream.Length, Uploaded = stream.Length, FileFullName = Path.Combine(directoryPath, fileName + fileInfo.FileSuffix), FileName = fileName + fileInfo.FileSuffix, FileDirectory = directoryPath }); } } } return(true); } catch (Exception ex) { _logger.LogError(ex.Message); } return(false); }
public Stream Download(FapFileInfo fileInfo) { FapAttachment attachment = _dataAccessor.Get <FapAttachment>((int)fileInfo.FileId); if (attachment != null && attachment.FileContent != null) { return(new MemoryStream(attachment.FileContent)); } return(null); }
public bool Delete(FapFileInfo fileInfo) { string fileRepositoryPath = GetFilePath(); string fileName = Path.Combine(fileRepositoryPath, fileInfo.FilePath); if (!System.IO.File.Exists(fileName)) { return(true); } System.IO.File.Delete(fileName); return(true); }
public Stream Download(FapFileInfo fileInfo) { string fileName = Path.Combine(ftpRootPath, fileInfo.FilePath); using (FtpClient conn = new FtpClient()) { conn.Host = host; conn.Credentials = new NetworkCredential(username, password); conn.Connect(); if (!conn.FileExists(fileName)) { return(null); } Stream stream = conn.OpenRead(fileName); return(stream); } }
public bool Delete(FapFileInfo fileInfo) { string fileName = Path.Combine(ftpRootPath, fileInfo.FilePath); using (FtpClient conn = new FtpClient()) { conn.Host = host; conn.Credentials = new NetworkCredential(username, password); //conn.Connect(); if (!conn.FileExists(fileName)) { return(true); } conn.DeleteFile(fileName); } return(true); }
public bool Upload(Stream stream, FapFileInfo fileInfo, FileUploadEventHandler updateEvent) { FapAttachment attachment = _dataAccessor.Get <FapAttachment>((int)fileInfo.FileId); if (attachment != null) { using (var inStream = stream) { byte[] bytes = new byte[inStream.Length]; inStream.Read(bytes, 0, bytes.Length); attachment.FileContent = bytes; } _dataAccessor.Update <FapAttachment>(attachment); } return(true); }
public bool Upload(Stream stream, FapFileInfo fileInfo, FileUploadEventHandler updateEvent) { if (fileInfo == null || stream == null) { return(false); } FtpStrategy strategy = new FtpStrategy(); string lv = _configService.GetSysParamValue("ftp.directory.level"); if (lv.IsPresent()) { strategy.Level = lv.ToInt(); } else { strategy.Level = 3; } string fileName = ""; string directoryPath = strategy.GetFullPath("" + fileInfo.FileId, out fileName); string destPath_to_save = Path.Combine(ftpRootPath, directoryPath); string filePath_to_save = Path.Combine(destPath_to_save, fileName + fileInfo.FileSuffix); try { using (FtpClient conn = new FtpClient()) { conn.Host = host; conn.Credentials = new NetworkCredential(username, password); conn.Connect(); if (!conn.DirectoryExists(destPath_to_save)) { conn.CreateDirectory(destPath_to_save); } using (Stream outStream = conn.OpenWrite(filePath_to_save)) { using (var inStream = stream) { stream.CopyTo(outStream); if (updateEvent != null) { updateEvent(fileInfo, new FileUploadEventArgs() { Total = inStream.Length, Uploaded = inStream.Length, FileFullName = Path.Combine(directoryPath, fileName + fileInfo.FileSuffix), FileName = fileName + fileInfo.FileSuffix, FileDirectory = directoryPath }); } } } } return(true); } catch (Exception ex) { _logger.LogError(ex.Message); } return(false); }
public bool Delete(FapFileInfo fileInfo) { return(true); }