diff --git a/Epsilon.Canvas.Abstractions/ICanvasModuleCollectionFetcher.cs b/Epsilon.Canvas.Abstractions/ICanvasModuleCollectionFetcher.cs index 6b8b97f5..f06dcf3c 100644 --- a/Epsilon.Canvas.Abstractions/ICanvasModuleCollectionFetcher.cs +++ b/Epsilon.Canvas.Abstractions/ICanvasModuleCollectionFetcher.cs @@ -4,5 +4,5 @@ namespace Epsilon.Canvas.Abstractions; public interface ICanvasModuleCollectionFetcher { - public IAsyncEnumerable GetAll(int courseId); + public IAsyncEnumerable GetAll(int courseId, String[] allowedModules); } \ No newline at end of file diff --git a/Epsilon.Canvas/CanvasModuleCollectionFetcher.cs b/Epsilon.Canvas/CanvasModuleCollectionFetcher.cs index 82aa0491..8d2b76dc 100644 --- a/Epsilon.Canvas/CanvasModuleCollectionFetcher.cs +++ b/Epsilon.Canvas/CanvasModuleCollectionFetcher.cs @@ -21,26 +21,29 @@ IOutcomeHttpService outcomeService _outcomeService = outcomeService; } - public async IAsyncEnumerable GetAll(int courseId) + public async IAsyncEnumerable GetAll(int courseId, string[] allowedModules) { var response = await _outcomeService.GetResults(courseId, new[] { "outcomes", "alignments" }); var modules = await _moduleService.GetAll(courseId, new[] { "items" }); Debug.Assert(response != null, nameof(response) + " != null"); Debug.Assert(modules != null, nameof(modules) + " != null"); - + foreach (var module in modules.ToArray()) { - Debug.Assert(module.Items != null, "module.Items != null"); + if (allowedModules.Length == 0 || allowedModules.Contains(module.Name)) + { + Debug.Assert(module.Items != null, "module.Items != null"); - var ids = module.Items.Select(static i => $"assignment_{i.ContentId}"); + var ids = module.Items.Select(static i => $"assignment_{i.ContentId}"); - Debug.Assert(response.Links?.Alignments != null, "response.Links?.Alignments != null"); + Debug.Assert(response.Links?.Alignments != null, "response.Links?.Alignments != null"); - yield return new ModuleOutcomeResultCollection(module, new OutcomeResultCollection( - response.OutcomeResults.Where(r => ids.Contains(r.Link.Alignment)), - response.Links with { Alignments = response.Links.Alignments.Where(a => ids.Contains(a.Id)) } - )); + yield return new ModuleOutcomeResultCollection(module, new OutcomeResultCollection( + response.OutcomeResults.Where(r => ids.Contains(r.Link.Alignment)), + response.Links with { Alignments = response.Links.Alignments.Where(a => ids.Contains(a.Id)) } + )); + } } } } \ No newline at end of file diff --git a/Epsilon.Cli/Startup.cs b/Epsilon.Cli/Startup.cs index d8e488ae..10a6dc24 100644 --- a/Epsilon.Cli/Startup.cs +++ b/Epsilon.Cli/Startup.cs @@ -62,15 +62,17 @@ private async Task ExecuteAsync() return; } - _logger.LogInformation("Targeting Canvas course: {CourseId}, at {Url}", _canvasSettings.CourseId, _canvasSettings.ApiUrl); + var modules = _exportOptions.Modules.Split(","); + _logger.LogInformation("Targeting Canvas course: {CourseId}, at {Url}", _canvasSettings.CourseId, + _canvasSettings.ApiUrl); _logger.LogInformation("Downloading results, this may take a few seconds..."); - var items = _collectionFetcher.GetAll(_canvasSettings.CourseId); + var items = _collectionFetcher.GetAll(_canvasSettings.CourseId, modules); var formats = _exportOptions.Formats.Split(","); var exporters = _exporterCollection.DetermineExporters(formats).ToArray(); _logger.LogInformation("Attempting to use following formats: {Formats}", string.Join(", ", formats)); - + foreach (var (format, exporter) in exporters) { _logger.LogInformation("Exporting to {Format} using {Exporter}...", format, exporter.GetType().Name); diff --git a/Epsilon/Export/ExportOptions.cs b/Epsilon/Export/ExportOptions.cs index c8a329fb..2e71d572 100644 --- a/Epsilon/Export/ExportOptions.cs +++ b/Epsilon/Export/ExportOptions.cs @@ -5,6 +5,8 @@ public class ExportOptions public string OutputName { get; set; } = $"{Constants.ProjectName}-Export-{{DateTime}}"; public string Formats { get; set; } = "console"; + + public string Modules { get; set; } = ""; public string FormattedOutputName => OutputName .Replace("{DateTime}", DateTime.Now.ToString("ddMMyyyyHHmmss"));