forked from ddrilling/AsbCloudServer
Мелкие фиксы репозитория хранения файлов.
This commit is contained in:
parent
6f05877ac9
commit
2769271583
@ -11,6 +11,7 @@ namespace AsbCloudApp.Repositories
|
||||
/// </summary>
|
||||
public interface IFileStorageRepository
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Получение длинны фала и проверка его наличия, если отсутствует падает исключение
|
||||
/// </summary>
|
||||
@ -35,10 +36,16 @@ namespace AsbCloudApp.Repositories
|
||||
Task SaveFileAsync(string filePathRec, Stream fileStreamSrc, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление файла
|
||||
/// Удаление пачки файлов
|
||||
/// </summary>
|
||||
/// <param name="filesName"></param>
|
||||
void DeleteFile(IEnumerable<string> filesName);
|
||||
void DeleteFiles(IEnumerable<string> filesName);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление одного файла
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
void DeleteFile(string fileName);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление всех файлов с диска о которых нет информации в базе
|
||||
@ -55,7 +62,7 @@ namespace AsbCloudApp.Repositories
|
||||
IEnumerable<FileInfoDto> GetListFilesNotDisc(IEnumerable<FileInfoDto> files);
|
||||
|
||||
/// <summary>
|
||||
/// Получение пути к файлу
|
||||
/// Создание пути для сохранения файла связанного со скважиной
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="idCategory"></param>
|
||||
@ -65,13 +72,32 @@ namespace AsbCloudApp.Repositories
|
||||
string MakeFilePath(int idWell, int idCategory, string fileFullName, int fileId);
|
||||
|
||||
/// <summary>
|
||||
/// Получить путь для скачивания
|
||||
/// Создание пути для сохранения файла
|
||||
/// </summary>
|
||||
/// <param name="path1"></param>
|
||||
/// <param name="path2"></param>
|
||||
/// <param name="path3"></param>
|
||||
/// <returns></returns>
|
||||
string MakeFilePath(string path1, string path2, string path3);
|
||||
|
||||
/// <summary>
|
||||
/// Получение пути к файлу связанного со скважиной
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="idCategory"></param>
|
||||
/// <param name="idFile"></param>
|
||||
/// <param name="dotExtention"></param>
|
||||
/// <param name="dotExtenstion"></param>
|
||||
/// <returns></returns>
|
||||
string GetUrl(int idWell, int idCategory, int idFile, string dotExtention);
|
||||
string GetFilePath(int idWell, int idCategory, int idFile, string dotExtenstion);
|
||||
|
||||
/// <summary>
|
||||
/// Получение пути файла лежащего на диске
|
||||
/// </summary>
|
||||
/// <param name="path1"></param>
|
||||
/// <param name="path2"></param>
|
||||
/// <param name="idFile"></param>
|
||||
/// <param name="dotExtenstion"></param>
|
||||
/// <returns></returns>
|
||||
string GetFilePath(string path1, string path2, int idFile, string dotExtenstion);
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ namespace AsbCloudApp.Services
|
||||
return 0;
|
||||
|
||||
var filesName = files.Select(x => GetUrl(x.IdWell, x.IdCategory, x.Id, Path.GetExtension(x.Name)));
|
||||
fileStorageRepository.DeleteFile(filesName);
|
||||
fileStorageRepository.DeleteFiles(filesName);
|
||||
|
||||
return files.Any() ? 1 : 0;
|
||||
}
|
||||
@ -143,7 +143,7 @@ namespace AsbCloudApp.Services
|
||||
/// <param name="dotExtention"></param>
|
||||
/// <returns></returns>
|
||||
public string GetUrl(int idWell, int idCategory, int idFile, string dotExtention) =>
|
||||
fileStorageRepository.GetUrl(idWell, idCategory, idFile, dotExtention);
|
||||
fileStorageRepository.GetFilePath(idWell, idCategory, idFile, dotExtention);
|
||||
|
||||
/// <summary>
|
||||
/// пометить метку файла как удаленную
|
||||
|
@ -6,8 +6,7 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Repository
|
||||
{
|
||||
namespace AsbCloudInfrastructure.Repository;
|
||||
|
||||
public class FileStorageRepository : IFileStorageRepository
|
||||
{
|
||||
@ -27,14 +26,19 @@ namespace AsbCloudInfrastructure.Repository
|
||||
await fileStreamSrc.CopyToAsync(newfileStream, token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public void DeleteFile(IEnumerable<string> filesName)
|
||||
public void DeleteFiles(IEnumerable<string> filesName)
|
||||
{
|
||||
foreach (var fileName in filesName)
|
||||
{
|
||||
DeleteFile(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteFile(string fileName)
|
||||
{
|
||||
if (File.Exists(fileName))
|
||||
File.Delete(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
public long GetFileLength(string srcFilePath)
|
||||
{
|
||||
@ -48,11 +52,16 @@ namespace AsbCloudInfrastructure.Repository
|
||||
File.Move(srcFilePath, filePath);
|
||||
}
|
||||
|
||||
public string MakeFilePath(int idWell, int idCategory, string fileFullName, int fileId)
|
||||
{
|
||||
return Path.Combine(RootPath, $"{idWell}",
|
||||
$"{idCategory}", $"{fileId}" + $"{Path.GetExtension(fileFullName)}");
|
||||
}
|
||||
public string MakeFilePath(int idWell, int idCategory, string fileFullName, int fileId) =>
|
||||
MakeFilePath($"{idWell}",
|
||||
$"{idCategory}",
|
||||
$"{fileId}" + $"{Path.GetExtension(fileFullName)}");
|
||||
|
||||
public string MakeFilePath(string path1, string path2, string path3) =>
|
||||
Path.Combine(RootPath,
|
||||
path1,
|
||||
path2,
|
||||
path3);
|
||||
|
||||
public int DeleteFilesNotInList(int idWell, IEnumerable<int> idsFilesList)
|
||||
{
|
||||
@ -90,8 +99,11 @@ namespace AsbCloudInfrastructure.Repository
|
||||
return resutl;
|
||||
}
|
||||
|
||||
public string GetUrl(int idWell, int idCategory, int idFile, string dotExtention) =>
|
||||
Path.Combine(RootPath, idWell.ToString(), idCategory.ToString(), $"{idFile}{dotExtention}");
|
||||
public string GetFilePath(int idWell, int idCategory, int idFile, string dotExtenstion) =>
|
||||
GetFilePath(idWell.ToString(), idCategory.ToString(), idFile, dotExtenstion);
|
||||
|
||||
public string GetFilePath(string path1, string path2, int idFile, string dotExtenstion) =>
|
||||
Path.Combine(RootPath, path1, path2, $"{idFile}{dotExtenstion}");
|
||||
|
||||
private IEnumerable<int> GetIdsFiles(int idWell)
|
||||
{
|
||||
@ -117,5 +129,3 @@ namespace AsbCloudInfrastructure.Repository
|
||||
Directory.CreateDirectory(directoryName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
});
|
||||
|
||||
var storageRepositoryMock = new Mock<IFileStorageRepository>();
|
||||
storageRepositoryMock.Setup(x => x.GetUrl(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<string>()))
|
||||
storageRepositoryMock.Setup(x => x.GetFilePath(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<string>()))
|
||||
.Returns((int idWell, int idCategory, int idFile, string dotExtention) => {
|
||||
return Path.Combine("files", idWell.ToString(), idCategory.ToString(), $"{idFile}{dotExtention}");
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user