forked from ddrilling/AsbCloudServer
Merge conflicts solve
This commit is contained in:
commit
a86c2ed971
@ -27,5 +27,6 @@ namespace AsbCloudApp.Services
|
||||
string GetUrl(FileInfoDto fileInfo);
|
||||
string GetUrl(int idFile);
|
||||
string GetUrl(int idWell, int idCategory, int idFile, string dotExtention);
|
||||
Task<FileInfoDto> MoveAsync(int idWell, int? idUser, int idCategory, string destinationFileName, string srcFileFullName, CancellationToken token = default);
|
||||
}
|
||||
}
|
||||
|
@ -29,9 +29,39 @@ namespace AsbCloudInfrastructure.Services
|
||||
.ThenInclude(c => c.CompanyType);
|
||||
}
|
||||
|
||||
public async Task<FileInfoDto> SaveAsync(int idWell, int? idUser,
|
||||
int idCategory, string fileFullName, Stream fileStream,
|
||||
CancellationToken token = default)
|
||||
public async Task<FileInfoDto> MoveAsync(int idWell, int? idUser, int idCategory, string destinationFileName, string srcFilePath, CancellationToken token = default)
|
||||
{
|
||||
destinationFileName = Path.GetFileName(destinationFileName);
|
||||
srcFilePath = Path.GetFullPath(srcFilePath);
|
||||
if (!File.Exists(srcFilePath))
|
||||
throw new ArgumentException($"file {srcFilePath} doesn't exist", nameof(srcFilePath));
|
||||
|
||||
var sysFileInfo = new System.IO.FileInfo(srcFilePath);
|
||||
|
||||
//save info to db
|
||||
var fileInfo = new AsbCloudDb.Model.FileInfo()
|
||||
{
|
||||
IdWell = idWell,
|
||||
IdAuthor = idUser,
|
||||
IdCategory = idCategory,
|
||||
Name = destinationFileName,
|
||||
UploadDate = DateTime.Now,
|
||||
IsDeleted = false,
|
||||
Size = sysFileInfo.Length,
|
||||
};
|
||||
|
||||
var entry = db.Files.Add(fileInfo);
|
||||
await db.SaveChangesAsync(token).ConfigureAwait(false);
|
||||
var fileId = entry.Entity.Id;
|
||||
string filePath = MakeFilePath(idWell, idCategory, destinationFileName, fileId);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
|
||||
File.Move(srcFilePath, filePath);
|
||||
|
||||
var dto = entry.Entity.Adapt<FileInfoDto>();
|
||||
return dto;
|
||||
}
|
||||
|
||||
public async Task<FileInfoDto> SaveAsync(int idWell, int? idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default)
|
||||
{
|
||||
//save info to db
|
||||
var fileInfo = new AsbCloudDb.Model.FileInfo()
|
||||
@ -46,23 +76,27 @@ namespace AsbCloudInfrastructure.Services
|
||||
};
|
||||
|
||||
var entry = db.Files.Add(fileInfo);
|
||||
db.SaveChanges();
|
||||
await db.SaveChangesAsync(token).ConfigureAwait(false);
|
||||
var fileId = entry.Entity.Id;
|
||||
//save stream to disk
|
||||
if(fileStream is not null)
|
||||
{
|
||||
var relativePath = Path.Combine(RootPath, $"{idWell}",
|
||||
$"{idCategory}", $"{fileId}" + $"{Path.GetExtension(fileFullName)}");
|
||||
string filePath = MakeFilePath(idWell, idCategory, fileFullName, fileId);
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(relativePath));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
|
||||
|
||||
using var newfileStream = new FileStream(relativePath, FileMode.Create);
|
||||
await fileStream.CopyToAsync(newfileStream, token).ConfigureAwait(false);
|
||||
using var newfileStream = new FileStream(filePath, FileMode.Create);
|
||||
await fileStream.CopyToAsync(newfileStream, token).ConfigureAwait(false);
|
||||
await fileStream.CopyToAsync(newfileStream);
|
||||
|
||||
var dto = entry.Entity.Adapt<FileInfoDto>();
|
||||
return dto;
|
||||
}
|
||||
|
||||
private string MakeFilePath(int idWell, int idCategory, string fileFullName, int fileId)
|
||||
{
|
||||
return Path.Combine(RootPath, $"{idWell}",
|
||||
$"{idCategory}", $"{fileId}" + $"{Path.GetExtension(fileFullName)}");
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<FileInfoDto>> GetInfosByCategoryAsync(int idWell,
|
||||
int idCategory, CancellationToken token = default)
|
||||
{
|
||||
|
@ -60,10 +60,8 @@ namespace AsbCloudInfrastructure.Services
|
||||
generator.Make(reportFileName);
|
||||
|
||||
var fileService = new FileService(context);
|
||||
using var filestream = File.OpenRead(reportFileName);
|
||||
var fileInfo = fileService.SaveAsync(idWell, idUser, ReportCategoryId, reportFileName, filestream).Result;
|
||||
filestream.Close();
|
||||
|
||||
var fileInfo = fileService.MoveAsync(idWell, idUser, ReportCategoryId, reportFileName, reportFileName).Result;
|
||||
|
||||
progressHandler.Invoke(new
|
||||
{
|
||||
Operation = "done",
|
||||
|
Loading…
Reference in New Issue
Block a user