mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-27 07:58:31 -06:00
refactor was really not needed
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
|
||||
// using System.Diagnostics.CodeAnalysis;
|
||||
// using LocalModels;
|
||||
|
||||
// public class FileStorageManagerCached : IFileStorageManager
|
||||
// {
|
||||
// private readonly FileStorageManager manager;
|
||||
|
||||
// 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 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()
|
||||
// {
|
||||
|
||||
// var secondsFromLastLoad = (DateTime.Now - cacheTime)?.Seconds;
|
||||
|
||||
// if (cachedCourses != null && secondsFromLastLoad < cacheSeconds)
|
||||
// {
|
||||
// logger.LogInformation("returning cached courses from file");
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
@@ -1,19 +1,19 @@
|
||||
using LocalModels;
|
||||
using Management.Services;
|
||||
|
||||
public class FileStorageManager
|
||||
public class FileStorageService
|
||||
{
|
||||
private readonly MyLogger<FileStorageManager> logger;
|
||||
private readonly MyLogger<FileStorageService> logger;
|
||||
private readonly CourseMarkdownLoader _courseMarkdownLoader;
|
||||
private readonly MarkdownCourseSaver _saveMarkdownCourse;
|
||||
private readonly ILogger<FileStorageManager> _otherLogger;
|
||||
private readonly ILogger<FileStorageService> _otherLogger;
|
||||
private readonly string _basePath;
|
||||
|
||||
public FileStorageManager(
|
||||
MyLogger<FileStorageManager> logger,
|
||||
public FileStorageService(
|
||||
MyLogger<FileStorageService> logger,
|
||||
CourseMarkdownLoader courseMarkdownLoader,
|
||||
MarkdownCourseSaver saveMarkdownCourse,
|
||||
ILogger<FileStorageManager> otherLogger,
|
||||
ILogger<FileStorageService> otherLogger,
|
||||
FileConfiguration fileConfig
|
||||
)
|
||||
{
|
||||
@@ -36,6 +36,8 @@ public class FileStorageManager
|
||||
|
||||
public async Task<IEnumerable<LocalCourse>> LoadSavedCourses()
|
||||
{
|
||||
|
||||
Console.WriteLine("loading pages from file system");
|
||||
return await _courseMarkdownLoader.LoadSavedCourses();
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ public class CourseMarkdownLoader
|
||||
return File.Exists(settingsPath);
|
||||
})
|
||||
.Select(async d => await LoadCourseByPath(d))
|
||||
.ToArray()
|
||||
);
|
||||
return courses.OrderBy(c => c.Settings.Name);
|
||||
}
|
||||
@@ -70,6 +71,7 @@ public class CourseMarkdownLoader
|
||||
var modules = await Task.WhenAll(
|
||||
modulePaths
|
||||
.Select(loadModuleFromPath)
|
||||
.ToArray()
|
||||
);
|
||||
return modules.OrderBy(m => m.Name);
|
||||
}
|
||||
@@ -79,7 +81,7 @@ public class CourseMarkdownLoader
|
||||
var moduleName = Path.GetFileName(modulePath);
|
||||
var assignments = await loadAssignmentsFromPath(modulePath);
|
||||
var quizzes = await loadQuizzesFromPath(modulePath);
|
||||
var pages = await loadPagesFromPath(modulePath);
|
||||
var pages = await loadModulePagesFromPath(modulePath);
|
||||
|
||||
return new LocalModule()
|
||||
{
|
||||
@@ -125,13 +127,13 @@ public class CourseMarkdownLoader
|
||||
{
|
||||
var rawQuiz = (await File.ReadAllTextAsync(path)).Replace("\r\n", "\n");
|
||||
return LocalQuiz.ParseMarkdown(rawQuiz);
|
||||
});
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
return await Task.WhenAll(quizPromises);
|
||||
}
|
||||
private async Task<IEnumerable<LocalCoursePage>> loadPagesFromPath(string modulePath)
|
||||
private async Task<IEnumerable<LocalCoursePage>> loadModulePagesFromPath(string modulePath)
|
||||
{
|
||||
using var activity = DiagnosticsConfig.Source?.StartActivity("loading Pages from path");
|
||||
var pagesPath = $"{modulePath}/pages";
|
||||
if (!Directory.Exists(pagesPath))
|
||||
{
|
||||
@@ -145,7 +147,8 @@ public class CourseMarkdownLoader
|
||||
{
|
||||
var rawPage = (await File.ReadAllTextAsync(path)).Replace("\r\n", "\n");
|
||||
return LocalCoursePage.ParseMarkdown(rawPage);
|
||||
});
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
return await Task.WhenAll(pagePromises);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user