mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
refactor was really not needed
This commit is contained in:
@@ -2,14 +2,16 @@ using Akka.Actor;
|
||||
|
||||
using LocalModels;
|
||||
|
||||
using Management.Services;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
public class LocalStorageActor : ReceiveActor
|
||||
{
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private readonly IServiceScope scope;
|
||||
private readonly ILogger<CanvasQueueActor> logger;
|
||||
private readonly FileStorageManager storage;
|
||||
private readonly MyLogger<CanvasQueueActor> logger;
|
||||
private readonly FileStorageService storage;
|
||||
|
||||
private DateTime? cacheTime { get; set; } = null;
|
||||
private IEnumerable<LocalCourse>? cachedCourses { get; set; } = null;
|
||||
@@ -19,8 +21,8 @@ public class LocalStorageActor : ReceiveActor
|
||||
{
|
||||
serviceProvider = serviceProviderArg;
|
||||
scope = serviceProvider.CreateScope();
|
||||
logger = scope.ServiceProvider.GetRequiredService<ILogger<CanvasQueueActor>>();
|
||||
storage = scope.ServiceProvider.GetRequiredService<FileStorageManager>();
|
||||
logger = scope.ServiceProvider.GetRequiredService<MyLogger<CanvasQueueActor>>();
|
||||
storage = scope.ServiceProvider.GetRequiredService<FileStorageService>();
|
||||
|
||||
Receive<EmptyDirectoryAsk>(m =>
|
||||
{
|
||||
@@ -31,15 +33,14 @@ public class LocalStorageActor : ReceiveActor
|
||||
|
||||
ReceiveAsync<SavedCoursesAsk>(async m =>
|
||||
{
|
||||
var secondsFromLastLoad = (DateTime.Now - cacheTime)?.Seconds;
|
||||
var secondsFromLastLoad = (DateTime.Now - cacheTime)?.TotalSeconds;
|
||||
|
||||
if (cachedCourses != null && secondsFromLastLoad < cacheSeconds)
|
||||
{
|
||||
logger.LogInformation("returning cached courses from file");
|
||||
logger.Log("returning cached courses from file");
|
||||
Sender.Tell(cachedCourses);
|
||||
return;
|
||||
}
|
||||
|
||||
cachedCourses = await storage.LoadSavedCourses();
|
||||
cacheTime = DateTime.Now;
|
||||
Sender.Tell(cachedCourses);
|
||||
|
||||
@@ -2,7 +2,7 @@ using Akka.Actor;
|
||||
|
||||
using LocalModels;
|
||||
|
||||
public class LocalStorageCache(IActorRef storageActor) : IFileStorageManager
|
||||
public class LocalStorageActorWrapper(IActorRef storageActor) : IFileStorageManager
|
||||
{
|
||||
private readonly IActorRef storageActor = storageActor;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class MyLogger<T>
|
||||
var finalMessage = $"[{typeof(T)}.{memberName}] {message}";
|
||||
|
||||
_baseLogger.Log(logLevel, finalMessage);
|
||||
Console.WriteLine(finalMessage);
|
||||
// Console.WriteLine(finalMessage);
|
||||
}
|
||||
public void Error(
|
||||
string message,
|
||||
|
||||
Reference in New Issue
Block a user