mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
hooks
This commit is contained in:
@@ -63,10 +63,12 @@ public class CanvasModuleService
|
||||
if (items == null)
|
||||
throw new Exception($"Error getting canvas module items for {url}");
|
||||
return items.Select(i =>
|
||||
i with {
|
||||
i with
|
||||
{
|
||||
ContentDetails = i.ContentDetails == null
|
||||
? null
|
||||
: i.ContentDetails with {
|
||||
: i.ContentDetails with
|
||||
{
|
||||
DueAt = i.ContentDetails.DueAt?.ToLocalTime(),
|
||||
LockAt = i.ContentDetails.LockAt?.ToLocalTime(),
|
||||
}
|
||||
|
||||
@@ -117,14 +117,16 @@ public class CanvasQuizService(
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
private async Task hackFixQuestionOrdering(ulong canvasCourseId, ulong canvasQuizId, IEnumerable<(CanvasQuizQuestion question, int position)> questionAndPositions )
|
||||
private async Task hackFixQuestionOrdering(ulong canvasCourseId, ulong canvasQuizId, IEnumerable<(CanvasQuizQuestion question, int position)> questionAndPositions)
|
||||
{
|
||||
using var activity = DiagnosticsConfig.Source.StartActivity("hack fixing question ordering with reorder");
|
||||
activity?.SetCustomProperty("canvasQuizId", canvasQuizId);
|
||||
activity?.SetTag("canvas syncronization", true);
|
||||
|
||||
var order = questionAndPositions.OrderBy(t => t.position).Select(tuple => {
|
||||
return new {
|
||||
var order = questionAndPositions.OrderBy(t => t.position).Select(tuple =>
|
||||
{
|
||||
return new
|
||||
{
|
||||
type = "question",
|
||||
id = tuple.question.Id.ToString(),
|
||||
};
|
||||
@@ -182,9 +184,10 @@ public class CanvasQuizService(
|
||||
|
||||
private static object[] getAnswers(LocalQuizQuestion q)
|
||||
{
|
||||
if(q.QuestionType == QuestionType.MATCHING)
|
||||
if (q.QuestionType == QuestionType.MATCHING)
|
||||
return q.Answers
|
||||
.Select(a => new {
|
||||
.Select(a => new
|
||||
{
|
||||
answer_match_left = a.Text,
|
||||
answer_match_right = a.MatchedText
|
||||
})
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using CanvasModel;
|
||||
using CanvasModel.Assignments;
|
||||
using CanvasModel.Courses;
|
||||
using CanvasModel.EnrollmentTerms;
|
||||
using CanvasModel.Modules;
|
||||
using RestSharp;
|
||||
using CanvasModel.Pages;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using RestSharp;
|
||||
|
||||
namespace Management.Services.Canvas;
|
||||
|
||||
|
||||
@@ -14,4 +14,4 @@ public class FileConfiguration(IConfiguration config)
|
||||
return basePath;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class FileStorageManager
|
||||
|
||||
public IEnumerable<string> GetEmptyDirectories()
|
||||
{
|
||||
if(!Directory.Exists(_basePath))
|
||||
if (!Directory.Exists(_basePath))
|
||||
throw new DirectoryNotFoundException($"Cannot get empty directories, {_basePath} does not exist");
|
||||
|
||||
return Directory
|
||||
|
||||
@@ -25,7 +25,7 @@ public class CourseMarkdownLoader
|
||||
})
|
||||
.Select(async d => await LoadCourseByPath(d))
|
||||
);
|
||||
return courses.OrderBy(c=>c.Settings.Name);
|
||||
return courses.OrderBy(c => c.Settings.Name);
|
||||
}
|
||||
|
||||
public async Task<LocalCourse> LoadCourseByPath(string courseDirectory)
|
||||
|
||||
@@ -45,12 +45,15 @@ public class WebRequestor : IWebRequestor
|
||||
|
||||
var response = await client.ExecutePostAsync(request);
|
||||
|
||||
if (isRateLimited(response)) {
|
||||
if(retryCount < rateLimitRetryCount){
|
||||
if (isRateLimited(response))
|
||||
{
|
||||
if (retryCount < rateLimitRetryCount)
|
||||
{
|
||||
logger.LogInformation($"hit rate limit on post, retry count is {retryCount} / {rateLimitRetryCount}, retrying");
|
||||
Console.WriteLine($"hit rate limit on post, retry count is {retryCount} / {rateLimitRetryCount}, retrying");
|
||||
Thread.Sleep(rateLimitSleepInterval);
|
||||
return await rateLimitAwarePostAsync(request, retryCount + 1);}
|
||||
return await rateLimitAwarePostAsync(request, retryCount + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!response.IsSuccessful)
|
||||
@@ -63,7 +66,7 @@ public class WebRequestor : IWebRequestor
|
||||
|
||||
private static bool isRateLimited(RestResponse response)
|
||||
{
|
||||
if(response.Content == null)
|
||||
if (response.Content == null)
|
||||
return false;
|
||||
return response.StatusCode == HttpStatusCode.Forbidden
|
||||
&& response.Content.Contains("403 Forbidden (Rate Limit Exceeded)");
|
||||
@@ -110,7 +113,7 @@ public class WebRequestor : IWebRequestor
|
||||
{
|
||||
if (e.StatusCode == HttpStatusCode.Forbidden) // && response.Content == "403 Forbidden (Rate Limit Exceeded)"
|
||||
{
|
||||
if(retryCount < rateLimitRetryCount)
|
||||
if (retryCount < rateLimitRetryCount)
|
||||
{
|
||||
logger.LogInformation($"hit rate limit in delete, retry count is {retryCount} / {rateLimitRetryCount}, retrying");
|
||||
Console.WriteLine($"hit rate limit in delete, retry count is {retryCount} / {rateLimitRetryCount}, retrying");
|
||||
|
||||
Reference in New Issue
Block a user