mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
switched to xunit
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using LocalModels;
|
||||
using Management.Services;
|
||||
|
||||
public class FileStorageManager : IFileStorageManager
|
||||
public class FileStorageManager
|
||||
{
|
||||
private readonly MyLogger<FileStorageManager> logger;
|
||||
private readonly CourseMarkdownLoader _courseMarkdownLoader;
|
||||
@@ -39,7 +39,7 @@ public class FileStorageManager : IFileStorageManager
|
||||
return await _courseMarkdownLoader.LoadSavedCourses();
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetEmptyDirectories()
|
||||
public async Task<IEnumerable<string>> GetEmptyDirectories()
|
||||
{
|
||||
if (!Directory.Exists(_basePath))
|
||||
throw new DirectoryNotFoundException($"Cannot get empty directories, {_basePath} does not exist");
|
||||
|
||||
@@ -1,50 +1,50 @@
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using LocalModels;
|
||||
// using System.Diagnostics.CodeAnalysis;
|
||||
// using LocalModels;
|
||||
|
||||
public class FileStorageManagerCached : IFileStorageManager
|
||||
{
|
||||
private readonly FileStorageManager manager;
|
||||
// public class FileStorageManagerCached : IFileStorageManager
|
||||
// {
|
||||
// private readonly FileStorageManager manager;
|
||||
|
||||
private readonly object cacheLock = new object(); // Lock object for synchronization
|
||||
// private readonly object cacheLock = new object(); // Lock object for synchronization
|
||||
|
||||
|
||||
private DateTime? cacheTime { get; set; } = null;
|
||||
private IEnumerable<LocalCourse>? cachedCourses { get; set; } = null;
|
||||
private ILogger<FileStorageManagerCached> logger { get; }
|
||||
// private DateTime? cacheTime { get; set; } = null;
|
||||
// private IEnumerable<LocalCourse>? cachedCourses { get; set; } = null;
|
||||
// private ILogger<FileStorageManagerCached> logger { get; }
|
||||
|
||||
private readonly int cacheSeconds = 2;
|
||||
public FileStorageManagerCached(FileStorageManager manager, ILogger<FileStorageManagerCached> logger)
|
||||
{
|
||||
this.manager = manager;
|
||||
this.logger = logger;
|
||||
}
|
||||
public IEnumerable<string> GetEmptyDirectories()
|
||||
{
|
||||
return manager.GetEmptyDirectories();
|
||||
}
|
||||
// private readonly int cacheSeconds = 2;
|
||||
// public FileStorageManagerCached(FileStorageManager manager, ILogger<FileStorageManagerCached> logger)
|
||||
// {
|
||||
// this.manager = manager;
|
||||
// this.logger = logger;
|
||||
// }
|
||||
// public Task<IEnumerable<string>> GetEmptyDirectories()
|
||||
// {
|
||||
// return manager.GetEmptyDirectories();
|
||||
// }
|
||||
|
||||
public async Task<IEnumerable<LocalCourse>> LoadSavedCourses()
|
||||
{
|
||||
// public async Task<IEnumerable<LocalCourse>> LoadSavedCourses()
|
||||
// {
|
||||
|
||||
var secondsFromLastLoad = (DateTime.Now - cacheTime)?.Seconds;
|
||||
// var secondsFromLastLoad = (DateTime.Now - cacheTime)?.Seconds;
|
||||
|
||||
if (cachedCourses != null && secondsFromLastLoad < cacheSeconds)
|
||||
{
|
||||
logger.LogInformation("returning cached courses from file");
|
||||
return cachedCourses;
|
||||
}
|
||||
// if (cachedCourses != null && secondsFromLastLoad < cacheSeconds)
|
||||
// {
|
||||
// logger.LogInformation("returning cached courses from file");
|
||||
// return cachedCourses;
|
||||
// }
|
||||
|
||||
cachedCourses = await manager.LoadSavedCourses();
|
||||
cacheTime = DateTime.Now;
|
||||
return cachedCourses;
|
||||
}
|
||||
// cachedCourses = await manager.LoadSavedCourses();
|
||||
// cacheTime = DateTime.Now;
|
||||
// return cachedCourses;
|
||||
// }
|
||||
|
||||
public async Task SaveCourseAsync(LocalCourse course, LocalCourse? previouslyStoredCourse)
|
||||
{
|
||||
// race condition...
|
||||
cacheTime = null;
|
||||
cachedCourses = null;
|
||||
await manager.SaveCourseAsync(course, previouslyStoredCourse);
|
||||
}
|
||||
}
|
||||
// public async Task SaveCourseAsync(LocalCourse course, LocalCourse? previouslyStoredCourse)
|
||||
// {
|
||||
// // race condition...
|
||||
// cacheTime = null;
|
||||
// cachedCourses = null;
|
||||
// await manager.SaveCourseAsync(course, previouslyStoredCourse);
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -4,5 +4,5 @@ public interface IFileStorageManager
|
||||
{
|
||||
Task SaveCourseAsync(LocalCourse course, LocalCourse? previouslyStoredCourse);
|
||||
Task<IEnumerable<LocalCourse>> LoadSavedCourses();
|
||||
IEnumerable<string> GetEmptyDirectories();
|
||||
Task<IEnumerable<string>> GetEmptyDirectories();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user