Attempted to Test CacheService, but can't figure it out.
This commit is contained in:
parent
1d61d1057e
commit
f430595d11
9 changed files with 96 additions and 22 deletions
|
|
@ -13,23 +13,23 @@ namespace API.Services
|
|||
{
|
||||
public class CacheService : ICacheService
|
||||
{
|
||||
private readonly IDirectoryService _directoryService;
|
||||
private readonly ILogger<CacheService> _logger;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IArchiveService _archiveService;
|
||||
private readonly IDirectoryService _directoryService;
|
||||
private readonly NumericComparer _numericComparer;
|
||||
public static readonly string CacheDirectory = Path.GetFullPath(Path.Join(Directory.GetCurrentDirectory(), "../cache/"));
|
||||
|
||||
public CacheService(IDirectoryService directoryService, ILogger<CacheService> logger, IUnitOfWork unitOfWork, IArchiveService archiveService)
|
||||
public CacheService(ILogger<CacheService> logger, IUnitOfWork unitOfWork, IArchiveService archiveService, IDirectoryService directoryService)
|
||||
{
|
||||
_directoryService = directoryService;
|
||||
_logger = logger;
|
||||
_unitOfWork = unitOfWork;
|
||||
_archiveService = archiveService;
|
||||
_directoryService = directoryService;
|
||||
_numericComparer = new NumericComparer();
|
||||
}
|
||||
|
||||
private bool CacheDirectoryIsAccessible()
|
||||
public bool CacheDirectoryIsAccessible()
|
||||
{
|
||||
_logger.LogDebug($"Checking if valid Cache directory: {CacheDirectory}");
|
||||
var di = new DirectoryInfo(CacheDirectory);
|
||||
|
|
@ -96,7 +96,7 @@ namespace API.Services
|
|||
|
||||
|
||||
|
||||
private string GetVolumeCachePath(int volumeId, MangaFile file)
|
||||
public string GetVolumeCachePath(int volumeId, MangaFile file)
|
||||
{
|
||||
var extractPath = Path.GetFullPath(Path.Join(Directory.GetCurrentDirectory(), $"../cache/{volumeId}/"));
|
||||
if (file.Chapter > 0)
|
||||
|
|
@ -106,9 +106,9 @@ namespace API.Services
|
|||
return extractPath;
|
||||
}
|
||||
|
||||
private IEnumerable<MangaFile> GetOrderedChapters(ICollection<MangaFile> files)
|
||||
public IEnumerable<MangaFile> GetOrderedChapters(ICollection<MangaFile> files)
|
||||
{
|
||||
return files.OrderBy(f => f.Chapter).Where(f => f.Chapter != 0);
|
||||
return files.OrderBy(f => f.Chapter).Where(f => f.Chapter > 0 || f.Volume.Number != 0);
|
||||
}
|
||||
|
||||
public string GetCachedPagePath(Volume volume, int page)
|
||||
|
|
@ -122,7 +122,7 @@ namespace API.Services
|
|||
if (page + 1 < (mangaFile.NumberOfPages + pagesSoFar))
|
||||
{
|
||||
var path = GetVolumeCachePath(volume.Id, mangaFile);
|
||||
var files = DirectoryService.GetFiles(path);
|
||||
var files = _directoryService.GetFiles(path);
|
||||
Array.Sort(files, _numericComparer);
|
||||
|
||||
return files.ElementAt(page - pagesSoFar);
|
||||
|
|
|
|||
|
|
@ -33,10 +33,9 @@ namespace API.Services
|
|||
reSearchPattern.IsMatch(Path.GetExtension(file)));
|
||||
}
|
||||
|
||||
public static string[] GetFiles(string path)
|
||||
public string[] GetFiles(string path)
|
||||
{
|
||||
if (!Directory.Exists(path)) return Array.Empty<string>();
|
||||
return Directory.GetFiles(path);
|
||||
return !Directory.Exists(path) ? Array.Empty<string>() : Directory.GetFiles(path);
|
||||
}
|
||||
|
||||
public IEnumerable<string> ListDirectory(string rootPath)
|
||||
|
|
@ -48,7 +47,6 @@ namespace API.Services
|
|||
.Where(dir => !(dir.Attributes.HasFlag(FileAttributes.Hidden) || dir.Attributes.HasFlag(FileAttributes.System)))
|
||||
.Select(d => d.Name).ToImmutableList();
|
||||
|
||||
|
||||
return dirs;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -224,11 +224,7 @@ namespace API.Services
|
|||
};
|
||||
}
|
||||
|
||||
private int MinimumNumberFromRange(string range)
|
||||
{
|
||||
var tokens = range.Split("-");
|
||||
return Int32.Parse(tokens.Length >= 1 ? tokens[0] : range);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates or Updates volumes for a given series
|
||||
|
|
@ -250,7 +246,7 @@ namespace API.Services
|
|||
var existingFile = existingVolume.Files.SingleOrDefault(f => f.FilePath == info.FullFilePath);
|
||||
if (existingFile != null)
|
||||
{
|
||||
existingFile.Chapter = MinimumNumberFromRange(info.Chapters);
|
||||
existingFile.Chapter = Parser.Parser.MinimumNumberFromRange(info.Chapters);
|
||||
existingFile.Format = info.Format;
|
||||
existingFile.NumberOfPages = _archiveService.GetNumberOfPagesFromArchive(info.FullFilePath);
|
||||
}
|
||||
|
|
@ -282,7 +278,7 @@ namespace API.Services
|
|||
var vol = new Volume()
|
||||
{
|
||||
Name = info.Volumes,
|
||||
Number = MinimumNumberFromRange(info.Volumes),
|
||||
Number = Parser.Parser.MinimumNumberFromRange(info.Volumes),
|
||||
Files = new List<MangaFile>()
|
||||
{
|
||||
CreateMangaFile(info)
|
||||
|
|
@ -316,9 +312,6 @@ namespace API.Services
|
|||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue